Akka-Stream implementation slower than single threaded implementation

前端 未结 2 392
迷失自我
迷失自我 2020-12-03 12:09

UPDATE FROM 2015-10-30


based on Roland Kuhn Awnser:

Akka Streams is using asynchronous message passing between Actors

2条回答
  •  不思量自难忘°
    2020-12-03 12:41

    Akka Streams is using asynchronous message passing between Actors to implement stream processing stages. Passing data across an asynchronous boundary has an overhead that you are seeing here: your computation seems to take only about 160ns (derived from the single-threaded measurement) while the streaming solution takes roughly 1µs per element, which is dominated by the message passing.

    Another misconception is that saying “stream” implies parallelism: in your code all computation runs sequentially in a single Actor (the map stage), so no benefit can be expected over the primitive single-threaded solution.

    In order to benefit from the parallelism afforded by Akka Streams you need to have multiple processing stages that each perform tasks of >1µs per element, see also the docs.

提交回复
热议问题