| |
- FloodProtector
class FloodProtector |
|
Here's how this algorithm works:
It limits the time between "events". What constitutes and event is
determined by "messages", which is a regex. Every message passed
in to self.check that matches messages is a throttled event.
The instance keeps a running timer. Each time an event occurs, the
following happens:
1) if the timer is less than the current time, it is set to the
current time
2) if the timer is more than N seconds ahead of the current time,
where (N, D) appear in "delays", then self.check sleeps for
D seconds.
3) "step" seconds are added to the timer.
In the simplest case, we could say
step = 2
delays = ((9, 3), )
Then, every time a message came in, the timer would be advanced by 2,
and if the timer got 9 or more seconds ahead of the wall clock,
self.check would sleep for 3 seconds. This would have the effect of
limiting events to roughly one every two seconds with a "burst capacity"
of about 5 events. |
|
Methods defined here:
- __init__(self, step=2, delays=((9, 3), (6, 2), (3, 1)), messages=None, debug=0)
- check(self, message)
| |