posted 5 years ago
Google trailing average, or moving average. One of those should do the trick.
The question is what happens when you exceed the limit. Do you drop the token, or make a queue of tokens waiting? If the queue fills up what then?
You might want to read up on networking also. The hardware can send at a certain max rate, packets get queued up to handle bursts. Make the queue too large and you get something called buffer bloat, which is bad.
Thou shalt not try me. Mom 24:7