Measures if there is backpressure on an Akka Stream at the given stage.
When an Akka Stream doesn't perform as intended, it is difficult to tell where the bottleneck is, since all stages operate at the same rate (see e.g. here ).
So when things are not fast as expected, this pressure gauge can help you to narrow down on the slow stage. Imagine your bottleneck is a narrow passage in a water pipe. What you'll observe is that:
- pressure before the bottleneck will be high (no matter how far before you measure)
- pressure after the bottleneck will be low (no matter how far after you measure).
PressureGauge gives you a tool that follows this intuition.
PressureGauge is implemented to give some information while producing low overhead. Therefore, it collects a boolean indicating if the stage is under pressure. Although this is only binary information, most of the time the measurement will be consistent and therefore sufficient. Unless the rates of the gauges' up- and downstreams are within 1 % of each other, chances to get different measurements every time the gauge is queried are very low.
If you need a more detailed picture, one option would be to sample the pressure boolean at a given frequency (e.g. every 50 milliseconds), retain a constant number of samples (e.g. 40), and build an average over these samples. A simple way how this could be done is shown in the example below. Expect to get 0% or 100% backpressure most of the time, and only very rarely values in between.