akka/akka-core

Source.actorRefWithAck for batch sending to stream

Aperta

#26.818 aperta il 26 apr 2019

 (0 commenti) (0 reazioni) (0 assegnatari)Scala (3547 fork)batch import
1 - triagedhelp wantedt:stream

Metriche repository

Star
 (13.277 stelle)
Metriche merge PR
 (Merge medio 8g 19h) (10 PR mergiate in 30 g)

Descrizione

https://github.com/akka/akka/pull/26633 added actorRefWithAck with 1-1 acks and no buffering (single element buffer).

We could also have a variant with a buffer and OverflowStrategy similar to ActorRefSource and SourceQueue.

Then we could also support batch sending into the stream by having having a function that evaluates if an ack should be sent back for a given element and thereby 1-1 acks are not needed. Could be ackMessage: Any => Option[Any], where the first Any is the incoming message and the second is optionally the ack message.

Then one can define a Source.actorRefWithAck with buffer size 100 and use it like:

ackMessage = n => if (n % 50 == 0) Some(n) else None

ref ! 1
ref ! 2
ref ! 3
...
ref ! 99
// wait for ack 50 if not already received
ref ! 100
ref ! 101
...
ref ! 149
// wait for ack 100 if not already received
...

Inspiration for jmh benchmark can be found in https://github.com/akka/akka/blob/master/akka-bench-jmh/src/main/scala/akka/remote/artery/SendQueueBenchmark.scala#L79

Guida contributor