-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(gateway-queue)!: rewrite crate
- Loading branch information
Showing
10 changed files
with
372 additions
and
445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,21 @@ | ||
# twilight-gateway-queue | ||
|
||
Ratelimiting functionality for queueing new gateway sessions. | ||
|
||
The gateway ratelimits how often clients can initialize new sessions. | ||
Instances of a queue are given to shards so that they can request to | ||
initialize a session. | ||
|
||
Queue implementations must point to the same broker so that all shards | ||
across all shard groups, processes, and other forms of multi-serviced | ||
applications, can work together and use the same ratelimiting source. That is, | ||
if two shard groups are in two different processes, then the the two processes | ||
must use some unified form of ratelimiting: this can either mean using IPC to | ||
communicate ratelimiting or a broker. | ||
|
||
## Provided queues | ||
|
||
Most users only need the [`LocalQueue`]: it's a single-process queue for | ||
smaller bots. Larger bots need the [`LargeBotQueue`], which supports | ||
single-process [Sharding for Large Bots] through the use of bucket | ||
releasing. | ||
|
||
By default, the gateway's `stream` module and `Shard`s use the [`LocalQueue`]. | ||
This can be overridden via the `ShardBuilder::queue` configuration method. | ||
|
||
## Advanced use cases | ||
|
||
Large bots, and smaller bots out of design, may need to implement their own | ||
queue. The most common reason to need this is if you have shard groups in | ||
multiple processes. A broker to manage ratelimiting across shard groups is | ||
required, so a [`Queue`] trait is provided that shards can use to make requests | ||
to create sessions. | ||
|
||
## Features | ||
|
||
### Twilight-HTTP | ||
|
||
The `twilight-http` feature brings in support for [`LargeBotQueue`]. | ||
|
||
This is enabled by default. | ||
|
||
[Sharding for Large Bots]: https://discord.com/developers/docs/topics/gateway#sharding-for-large-bots | ||
Rate limiting functionality for gateway `IDENTIFY` commands. | ||
|
||
Discord allows bot's shards to send a limited amount of `IDENTIFY` commands | ||
every 5 seconds, with a daily limit from 1000 to 2000 commands, and invalidates | ||
*all* shard sessions upon exceeding it. Each identify window is called a bucket | ||
and is filled by shards' IDs modulo `max_concurrency`. Buckets must furthermore | ||
be started in order. See [Discord Docs/Sharding]. | ||
|
||
To coordinate this, a [`Queue`] should process each identify request and shards | ||
should wait for its signal to proceed before continuing and otherwise retry. The | ||
provided [`InMemoryQueue`] never fails or cancels requests and is therefore a | ||
good starting point for custom implementations. For most cases, simply wrapping | ||
[`InMemoryQueue`] is be enough to add new capabilities such as multi-process | ||
support, see [`gateway-queue`] and [`gateway-queue-http`]. Integration tests can | ||
be found [here](https://github.com/twilight-rs/twilight/blob/main/twilight-gateway-queue/src/lib.rs). | ||
|
||
[Discord Docs/Sharding]: https://discord.com/developers/docs/topics/gateway#sharding | ||
[`gateway-queue`]: https://github.com/twilight-rs/gateway-queue | ||
[`gateway-queue-http`]: https://github.com/twilight-rs/twilight/blob/main/examples/gateway-queue-http.rs |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.