akka/akka-core

Source.actorRefWithAck for batch sending to stream

Aberta

#26.818 aberto em 26 de abr. de 2019

 (0 comentário) (0 reação) (0 responsável)Scala (3.547 forks)batch import
1 - triagedhelp wantedt:stream

Métricas do repositório

Stars
 (13.277 estrelas)
Métricas de merge de PR
 (Mesclagem média 8d 19h) (10 fundiu PRs em 30d)

Description

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

Guia do colaborador