This is a question I’ve asked previously in Stack Overflow
Looking at the signature of throttle in Akka Streams I see that it can take a cost function of type
(Out) ⇒ Int to compute how the element passing through the stage affects the
cost/per speed limit of elements sent downstream.
Is it possible to implement throttling based on external input for the stream with a built-in stage? If not, would it be easier just to implement a custom stage?
I’m expecting something like:
def throttle(cost: Int, per: FiniteDuration, maximumBurst: Int, costCalculation: ⇒ Int, mode: ThrottleMode): Repr[Out]
So that we could do something like:
throttle(75 /** 75% CPU **/, 1.second, 80 /** 80% CPU **/, getSinkCPU, ThrottleMode.Shaping)