-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat: added @discordjs/sharder
package
#7204
Conversation
🎉 |
Is there a reason, why @discordjs/sharder module is using the cluster module instead of child-processes. The Cluster module has some layers built on top of child_processes, which can make it slower. |
I fail to see where you see cluster being the only/forced option to use, @meister03, it's simply a strategy. If somebody wants to use cluster over child processes, they're free to do so. |
This looks promising as a replacement for old d.js sharder. One thing though, can we implement our op system in this sharder by tapping on ipc messages, and do the same send() reply() fashion like how the old veza does? eg: if we want to send messages our selves from main process to sub process? One reason why I would like a system like this, is because I don't want to use broadcastEval on getting data across my sub process. |
You can reply to messages, thats been done with the |
I think there are a few features from Discordeno that we could learn from and would be a big improvement for discord.js and big bots that use it. Actually, updates are painful for bots that handle a large amount of shards. |
A lot of those would go in the @discordjs/ws package, not in sharder, and are actually planned to a degree (for instance you can host the ws in a different process or machine, and in the future, you can make d.js pull from that process using NATS or whatever floats your boat)! |
I would love to take inspiration of discordeno, if it were any good that is. Most of that text is just random fluff with no actual improvement or impact, or a complete lack and misunderstanding of how sharding works to make it look more appealing. |
Sure @iCrawl, I agree with you. |
594a812
to
7ab2ebf
Compare
Actually it is close to zero downtime as you only lose a few events, you have the new shard and the old shards stays connected until the new one is ready |
633c74b
to
6863309
Compare
6863309
to
1b812de
Compare
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
1b812de
to
feb0981
Compare
any updates on this? |
Superseded by #8859, the new PR is up-to-date and implements the RFC. Also has a much simpler API. |
Please describe the changes this PR makes and why it should be merged:
I heard you wanted a nice and complete sharder. 👀
This sharder draws inspiration from the strategy and plug-in system Sapphire has largely adopted over the months, the way Kurasuta handles messages and shards separately, and the structure of Discord.js's built-in sharding manager to make the update easy, alongside a few sprinkles of my own based on my experience when building a cross-process intercommunication system.
Let's talk about this sharder's structure! It is divided in three components:
WorkerShardHandler
) and forks (ForkProcessShardHandler
) to cross-server clusters going thru local clusters (ClusterProcessShardHandler
). Yes, you heard that. Although we'll most likely ship only the 3 local ones. You can make your own custom shard strategies.RawMessageHandler
(data as-is, without converting to a Buffer or a string),JsonMessageHandler
(JSON), andBinaryMessageHandler
(V8 serder)... You can plug in your own ones, such as the Erlang External Term Format (ETF), YAML, TOML, etc.This clear separation between responsibilities allow for greater customization of the core functionality of the library, reducing the need to use external libraries.
And coming in the future, we'll probably release The Message Mappers, which give a final touch-up to a message, such as appending a header/footer or even, using OpenSSL to encrypt messages over the network.
Issues to handle:
respawn: boolean
torespawn: number
, accepting-1
andInfinity
for unlimited respawns, but a number that is decreased by one on each shard until it's ready, in which case it'll reset the counter./gateway/bot
in the sharder, only once, and pass the data to the shards during spawn. We could also implement a query system so we can get that data from the ShardingManager without querying Discord more than once a day by caching and updating the result accordingly.Todo:
ProcessShardHandler
abstract, for the two classes below.ForkProcessShardHandler
.CusterProcessShardHandler
.WorkerShardHandler
.RawMessageHandler
.BinaryMessageHandler
.fetchRecommendedShards
.ShardTunnel
?ShardClient
?Note: This is a port of discordjs/discord.js-modules#87
Status and versioning classification: