Skip to content

Instantly share code, notes, and snippets.

View andreas-schroeder's full-sized avatar

Andreas Schroeder andreas-schroeder

  • BMW Group
  • Munich
View GitHub Profile
@andreas-schroeder
andreas-schroeder / fetch-tokens.lua
Last active June 25, 2019 04:33
Redis-based bucket rate limiting
local bucket_key = KEYS[1]
local requested = tonumber(ARGV[1])
local time = redis.call('TIME')
local now = tonumber(time[1]) * 1000000 + tonumber(time[2]) -- time in microseconds
local bucket = redis.call('HMGET', bucket_key, 'tokens', 'next_refill')
local tokens, next_refill = bucket[1], bucket[2]
if (not tokens) then
@andreas-schroeder
andreas-schroeder / Akka_streams_backpressure_gauge.md
Last active July 8, 2020 23:03
Measuring Akka Streams Backpressure

Akka Streams Backpressure Gauge

Measures if there is backpressure on an Akka Stream at the given stage.

Motivation

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