Search code examples
akka-stream

Akka-Stream using Partition stage


I am trying to find an example that shows how to use, Akka Stream Partition capability. I am trying to optimize writing a Store. For that i would like to group item in a batch of my choosing and write them at once, however to make use of parallelism i would like to do it in parallel. Hence the batch and then the writing in the database would happen let say on 8 simultaneous threads.

I would be able to write 30 records as one update on 8 parallel threads.

Grouped or GroupedWithin are well documented and i have tried them with success. However, the only thing i see to do what i want to in parallel is actually a partitioning. I'd to partition randomly, i don't care about how it is partition. If there is facilities to like round-robin partitioner, i'd like to know as well.

But first and foremost how do I use partition. Do i have to build a GraphBuilder ?

Please help


Solution

  • Usage example of Partition can be found here.

    If you're looking for random partitioning, the Balance stage is what you need. The docs provide an example here.

    In both cases you need to make use of the GraphDSL, documented here.