I am trying to understand the difference between asyncBoundary
and mapAsync
. From the glance, I guess they should be same. However, when I run the code, it looks like that the performance of asyncBoundary
is quicker than mapAsync
Here is the code
implicit val system = ActorSystem("sourceDemo")
implicit val materializer = ActorMaterializer()
Source(1 to 100).mapAsync(100)(t => Future {t + 1}).mapAsync(100)(t => Future {t * 2}).map(println).to(Sink.ignore).run()
Source(1 to 100).map(_ + 1).withAttributes(Attributes.asyncBoundary).map(_ * 2).map(t => println("async boundary", t)).to(Sink.ignore).run()
The output: async boundary is always finished quicker than mayAsync.
From the document described about asyncBoundary (https://doc.akka.io/docs/akka-stream-and-http-experimental/current/scala/stream-flows-and-basics.html), I can see it is running on different CPU, but mapAsync is multi-threaded by using Future. Future is also asynchronous.
May I ask more clarification about this two APIs ?