Reputation: 1532
I have a pipeline with Akka flow that is using a custom dispatcher.
Akka Flow code:
// Pulls in data via network requests
source
// Downstream will be sent to a different actor.
// Also, a "buffer" of 16 elements will be created between those actors.
.async
.via(writeToDatabase())
.toMat(Sink.ignore)(Keep.right)
.withAttributes(ActorAttributes.dispatcher("customer-dispatcher"))
.run()
Dispatcher configuration:
custom-dispatcher {
type = Dispatcher
executor = "thread-pool-executor"
thread-pool-executor {
fixed-pool-size = 16
}
throughput = 1
}
My understanding is that .async
will insert a buffer of 16 elements by default
When an asynchronous boundary is introduced, the Akka Streams API inserts a buffer between every asynchronous processing stage
Source: https://blog.colinbreck.com/maximizing-throughput-for-akka-streams/
Question: Will setting the throughput=1
cause the buffer to always have only 1 document?
Upvotes: 1
Views: 882
Reputation: 20551
No.
An Akka dispatcher is responsible for (among other things) scheduling an actor in a threadpool. The throughput
configuration sets the maximum number of messages an actor will process from its mailbox before another actor would be able to be scheduled on the thread. Lower values for throughput mean more context switches and thus lower performance: the benefit in exchange is that an actor which takes a long time to process messages is less able to hog the thread.
The buffer introduced at an async boundary in Akka Streams is different and basically part of the backpressure protocol. You can set the default size of these buffers with the akka.stream.materializer.max-input-buffer-size
configuration option, or programmatically per async boundary by adding the Attributes.inputBuffer
attribute to the boundary.
Akka Streams could be affected by dispatcher throughput, though the effect would be pronounced in situations where there are more stream actors than dispatcher threads. Since the internal messages for signalling demand as well as those moving stream elements from actor to actor would be affected, it's rather unpredictable what the effect would be.
Upvotes: 2