-
Notifications
You must be signed in to change notification settings - Fork 792
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
[Question ]Do we implement the auto guild sharding ? #265
Comments
Having a small sharded wrapper might be the way to go. I don't want to put On Sep 30, 2016 4:09 AM, "robbix1206" notifications@github.com wrote:
|
Maybe one thing is to add something like "function (*Session) setShard(ShardID,ShardCount)" |
Session.ShardID = 0 Isn't too difficult :) As for number of shards, I'm hoping Discord will provide an API as there's On Fri, Sep 30, 2016 at 9:32 AM, robbix1206 notifications@github.com
|
Think we have answer to all that questions ^^ |
Any word on this? I'm considering using discordgo for my bot that's approaching 3000 guilds and already requires sharding. It's currently written in Java and uses JDA, but I know Go and want to rewrite it to be more memory efficient and faster. |
What do you need to know? DiscordGo supports sharding and it's quite simple to wrap together multiple Sessions. |
Could you provide a small example of sharding using DiscordGo please? |
I reopen it because of the
I think we need to change Session.Open() as it calls the Proposals:
BTW Maybe is that better to make Gateway and GatewayBot independent from a Session. |
This is from over a year ago. Is it resolved so that it correctly calls the |
I'm not sure if the above is still relevant anymore. The documentation now states
I don't see in the documentation (at the moment) where it states it should only be called once even with multiple shards. Right now DiscordGo calls the /gateway/ endpoint to get the gateway. That value is cached so reconnects do not have to call it again, but separate shards would each still call the endpoint. This issue should probably be closed, actually. Are you running into any specific issue with this or just following up (which I do appreciate)? |
Yes the documentation was modified in this commit discord/discord-api-docs@77af69f |
@bwmarrin I was just following up because I am developing a bot which might need sharding, and I'd rather design it with that feature from the beginning. But I couldn't find any examples using sharding, and this issue was one of the first results on Google for |
Ah, well I unfortunately?.. do not have a bot that's popular enough to need sharding :( If you join the Discord Gophers chat server there are a few people there that have made bots doing sharding that might be able to give you some advice. The basis though, is you need to set Session.ShardID and Session.ShardCount before calling Session.Open(). ShardID should be unique number for each shard, 0 for your first, then 1, and so on. Then ShardCount should be the total number of shards you are running. You can create multiple DiscordGo.Session instances in the same program or you could launch each shard as a separate program on the same or even different servers. The Discord documentation has some details here as well that might be worth reading though. Hopefully that helps some :) |
The actual process of sharding is really easy, just set ShardID and ShardCount and your session will be sharded. The trick comes if you want to use your bot like it was in one big Session, in that case you need to kinda strap a bunch of Sessions together, like I did! https://github.com/iopred/bruxism/blob/master/discord.go#L190 This actually works really well, I'm running this with 50 shards on a single (rather big) GCE instance. If you want to do this properly-properly, you would just have each instance of your application talk to the same backend/database, but nothing in DiscordGo helps you write that, it's your responsibility. |
So, I've migrated my bot over to DiscordGo from JDA and was kind of taken when autosharding didn't happen... My bot is in about 35 shards and auto sharding would be super helpful |
Understandable - there's always some differences between libraries. "Auto Sharding" wouldn't be within the design goals of this library though. And really, I'd say it shouldn't exist also because there's a number of ways a bot developer might want to do it for their bot. Maybe they want it all in one program, maybe they want to split up the load 50/50 between two separate programs on different AWS/GCE/whatever hosts, maybe they want to do something else entirely. This library main design goal (for better or worse) is a low level fairly direct mapping of the api itself, with a little "magic" in the middle. |
For future reference, I implemented a simple sharding manager here for anyone who needs it: https://github.com/servusDei2018/shards It has an example mirroring discordgo's pingpong: https://github.com/servusDei2018/shards/tree/master/examples/pingpong I documented it well and, unlike some other discordgo sharding managers on GitHub, is documented, well-structured, and concurrency safe by default. Moreover, it supports downtime-free restarting/rescaling out of the box. |
This library is so popular and you should not adhere whatever you wanted earlier. When it comes to discord.js it has all features whatever people wanted. At least you need to let people make improvements about it. This is what open source is. You let people whatever they want to build. |
Disgo has implemented a prioritized shard manager. This comment is made for future reference. |
discord/discord-api-docs#17
Do we let user deal with that or do we automatically do that ?
(I personally it's better that the users deal with that because they can put the programs on multiple computers for big bots like airhorn)
The text was updated successfully, but these errors were encountered: