Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accuracy of reservoir refresh interval? #88

Closed
swayam18 opened this issue Oct 14, 2018 · 3 comments
Closed

Accuracy of reservoir refresh interval? #88

swayam18 opened this issue Oct 14, 2018 · 3 comments

Comments

@swayam18
Copy link

In the docs it says that the accuracy of reservoirRefreshInterval is +-5 seconds.

This is a problem because many APIs have limits with 1 second granularity, i.e. they allow x requests every second. So, we may be off their rate limit by nearly 5x.

Is there something I can do to make sure the reservoir is refreshed accurately every second? Should I be using a custom timeout + incrementReservoir function?

@SGrondin
Copy link
Owner

SGrondin commented Oct 14, 2018

It's an oversight in the docs, it's actually only 5s (5000ms) when using Clustering and 250ms otherwise.

It's set to 5000 for Clustering for performance reasons and it can be altered by passing the (currently undocumented) heartbeatInterval option. I'll fix the docs. It could only really affects performance with a very high number of limiters.

@swayam18
Copy link
Author

Ah, makes sense. I will add the heartbeatInterval option to my cluster and set it to 250ms. Cheers

@SGrondin
Copy link
Owner

SGrondin commented Oct 15, 2018

Glad that helps! Here's a few more details you might be interested in.

The inaccuracy is only "below", not "above". What I mean is that the actual Reservoir Refresh Interval might be slower than your reservoirRefreshInterval setting by up to heartbeatInterval, but it will never be too fast. It's designed this way to ensure you never blow up your rate limits.

Also, assuming all of your servers have an accurate and consistent (across the cluster) internal clock, then the more limiters you have sharing the same id in the Cluster, the more accurate it will be, even with a high heartbeatInterval.

Finally, the more traffic limiters get, the more accurate your refresh interval is. Again, it will never be "faster than reservoirRefreshInterval", it can only be "a bit slower than reservoirRefreshInterval".

As usual, make sure to benchmark and adjust it for your own use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants