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

Cannot use Nostrum.Api functions in a multi-host configuration due to the request Ratelimiter not running #620

Open
jonklein opened this issue Aug 9, 2024 · 2 comments

Comments

@jonklein
Copy link

jonklein commented Aug 9, 2024

SCENARIO:
Nostrum is running in a multi-node environment, with the Nostrum.Application & consumer processes running on just one node and serving bot requests, as described in the documentation. We'd like the other nodes in the cluster to be able to use Nostrum.Api functions needed to perform web requests, background jobs, etc. Currently, these calls fail because the Ratelimiter instance is not running on the other nodes.

I do have a workaround, but it's probably not the right long-term solution. I'm happy to submit a fix, but want to create this issue to figure out the correct approach.

SOLUTIONS TRIED:

  • Start just the Ratelimiter on the non-main nodes: this fails when a failover occurs – the Nostrum application fails to restart on the new host due to the Ratelimiter already running.

  • Run the Nostrum application on multiple nodes, but run the main consumer on only a single node: this almost works, but results in duplicate events, because every node's connection dispatches to the consumer, which is globally registered with :pg in ConsumerGroup.

CURRENT WORKAROUND:

I'm running the Nostrum application on multiple nodes as described above, but have forked the library and updated the ConsumerGroup to use :pg.get_local_members instead of :pg.get_members. Even though running the connection on multiple hosts is not the right approach in general, I do feel like get_local_members is more correct here - based on the current multi-node support, I'm not sure what the justification would be for dispatching to consumers on other nodes.

OTHER POSSIBLE SOLUTIONS:

  • Make it possible to run Nostrom.Api.Ratelimiter independent of Nostrum.Application: if Nostrum.Application allowed an option to not start the Ratelimiter, applications could optionally start it themselves separately on every node.

  • Register the Ratelimiter as a global process (some tradeoffs are discussed in the Ratelimiter docs)

Any thoughts on the preferred approach, especially taking into consideration possible future distributed multi-node consumer support?

@Th3-M4jor
Copy link
Contributor

For the 1.0.0 release, which should be the next non-patch release, we do have plans to make it so that users have to start Nostrum as part of their Supervision tree instead of leveraging the Application path. As part of that we could make it possible to configure how the ratelimiter module is named.

Also have you tried what's suggested in our multi-node guide?

@jchristgit
Copy link
Collaborator

jchristgit commented Aug 10, 2024 via email

jchristgit added a commit that referenced this issue Aug 10, 2024
As described in #620, currently the ratelimiter is not usable across
multiple nodes. Lay the groundwork for doing this by registering
ratelimiters in a process group and selecting the matching ratelimiter
based on the request route.

Note that some minor further adjustments need to be made to make the
ratelimiter fully functional over multiple nodes, primarily related to
process registration, but some further documentation is also missing and
will be amended once manual consumer startup is prepared.
jchristgit added a commit that referenced this issue Aug 10, 2024
As described in #620, currently the ratelimiter is not usable across
multiple nodes. Lay the groundwork for doing this by registering
ratelimiters in a process group and selecting the matching ratelimiter
based on the request route.

Note that some minor further adjustments need to be made to make the
ratelimiter fully functional over multiple nodes, primarily related to
process registration, but some further documentation is also missing and
will be amended once manual consumer startup is prepared.
jchristgit added a commit that referenced this issue Aug 16, 2024
As described in #620, currently the ratelimiter is not usable across
multiple nodes. Lay the groundwork for doing this by registering
ratelimiters in a process group and selecting the matching ratelimiter
based on the request route.

Note that some minor further adjustments need to be made to make the
ratelimiter fully functional over multiple nodes, primarily related to
process registration, but some further documentation is also missing and
will be amended once manual consumer startup is prepared.
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

3 participants