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

Add ratelimiter to allow custom hard-coded global ratelimits #475

Merged
merged 1 commit into from
Nov 22, 2019

Conversation

Bastian
Copy link
Member

@Bastian Bastian commented May 29, 2019

On larger bots, it is possible to hit the global ratelimit of 50/1. Preventing to hit this global ratelimit is not possible with just the ratelimit HTTP-headers that we receive from Discord, but only with hard-coded limits. As the limits could change over-time (and there might even some increased limits for large bots?) it's no option to hard-code them directly into the Javacord code.

This PR allows users to set their own ratelimits in the DiscordApiBuilder. A default implementation is available for local ratelimits that allows users to set a hard-coded limit. It is possible to write custom implementations that allow more complex ratelimiters that can for example share their state across multiple machines.

The code can be used like this:

DiscordApi api = new DiscordApiBuilder()
        .setGlobalRatelimiter(new LocalRatelimiter(50, 1)) // 50/1 ratelimit
        .setToken("<token>")
        .login()
        .join();

@Bastian Bastian added the low priority An issue or pull request with a low priority label May 29, 2019
@Bastian Bastian added this to the Next Version milestone May 29, 2019
@Bastian Bastian force-pushed the improve-global-ratelimits branch 4 times, most recently from 6bf83ab to 6bad5fc Compare May 29, 2019 19:47
This can be usedful for some very large bots that regularly hit the
global ratelimits. It allows them to set a hard-coded limit that fits
their needs and can be shared by multiple shards.

A bot that runs on multiple machines can either use its own
implementation of the Ratelimits that communicates across the network
to ensure that no ratelimits are hit, or just adjust the values and
grant every machine only a part of the available global limit.
@Bastian Bastian modified the milestones: Next Version, Version 3.0.5 Nov 22, 2019
@Bastian Bastian merged commit 917e4b3 into Javacord:development Nov 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low priority An issue or pull request with a low priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant