Skip to content

blackbull.server.rate_window

blackbull.server.rate_window

Rolling-window count meter.

Do not replace this with a token bucket: burst allowance would change the meaning of caller limits. Use a separately named primitive for smoothing.

ByteRateFloor

Enforce a rolling byte-rate floor after a grace period; rate=0 disables.

waited includes every transport wait, even reads without countable payload. nbytes counts wanted payload, excluding padding or framing the peer can inflate. Satisfied windows roll so prior progress cannot cover later stalls.

observed property

Bytes per second in the window currently open (diagnostics only).

record(nbytes, waited)

Add one delivery. Returns True when the window came up short.

reset()

Forget the current window. For reuse, not for callers that dislike the answer.

RateWindow

Count events per fixed window; report when the budget is spent.

limit events are permitted per window seconds. A limit of 0 disables the meter entirely — hit then never reports an overrun, which is how every cap knob in this server spells "off".

One instance per thing being counted, per connection: separate meters for PING and SETTINGS mean a peer may legitimately send its budget of each, and a shared meter would have made the two compete for one allowance for no reason a peer could predict.

count property

Events counted in the window currently open (diagnostics only).

hit(now=None)

Count one event. Returns True when the budget is exceeded.

now accepts an injected clock so a test can drive window rollover deterministically instead of sleeping through it.

reset()

Forget the current window. For connection reuse, not for callers that dislike the answer.