KeyedExecutor

constructor(workers: Int = DEFAULT_WORKERS, maxInFlight: Int = DEFAULT_MAX_IN_FLIGHT, name: String = DEFAULT_NAME, throughput: Int = DEFAULT_THROUGHPUT, spin: Duration = DEFAULT_SPIN)

Parameters

workers

the number of worker threads; defaults to the available processors.

maxInFlight

the most messages one receiver, i.e. one (dispatcher, bounded context), holds unfinished (running or queued in a mailbox).

name

the worker thread name prefix.

throughput

the most messages of one aggregate a worker runs in one turn (while they complete synchronously) before it moves on to other aggregates, so one hot aggregate cannot starve the others.

spin

the longest a worker that ran out of messages spins before it parks, at most MAX_SPIN; the default, Duration.ZERO, parks at once (no spin). Worth setting only for in-memory, high-rate dispatch whose messages keep arriving within microseconds of each other; with a real store the gain is within noise. A worker spins only when its last wait was shorter than this; after a longer wait it parks at once. A spinning worker takes the next message without the wake-up a park costs (an OS call by the sender and the scheduling delay of the woken thread). CPU cost: while messages keep arriving at intervals shorter than the spin, a worker can stay busy on one core the whole time; after each short interval, the next wait can cost up to the spin in CPU even when no message follows. The worst case is workers cores. In a container with a CPU quota (cgroup limit), set it to Duration.ZERO.