gen_stage v0.6.0 Experimental.GenStage.PartitionDispatcher
A dispatcher that sends events according to partitions.
Keep in mind that, if partitions are not evenly distributed, a backed-up partition will slow all other ones.
Options
The partition dispatcher accepts the following options on initialization:
:partitions
- the number of partitions to dispatch to. It may be an integer with a total number of partitions, where each partition is named from 0 up tointeger - 1
. For example,partitions: 4
will contains 4 partitions named 0, 1, 2 and 3.It may also be an enumerable that specifies the name of every partition. For instance,
partitions: [:odd, :even]
will build two partitions, named:odd
and:even
.:hash
- the hashing algorithm, which receives the event and returns a tuple with two elements, containing the event and the partition. The partition must be one of the partitions specified in:partitions
above. The default uses&:erlang.phash2(&1, Enum.count(partitions))
on the event to select the partition.
Subscribe options
When subscribing to a GenStage
with a partition dispatcher the following
option is required:
:partition
- the name of the partition. The partition must be one of the partitions specified in:partitions
above.