#Sharding in a prod bot
1 messages · Page 1 of 1 (latest)
The example is not up to date ?
https://github.com/twilight-rs/twilight/blob/main/examples/gateway-reshard.rs#L29
Create a range of shards from Discord’s recommendation.
that example is for something else, there is no difference how you should do sharding between 0.16 and 0.17
Yeah, I was just asking in general, not spesifically 0.17 since I rolled my own manager when using 0.16 but I’m asking what’s the idiomatic way to do sharding just in twilight in general
I just run each shard seperately with a small bit of shared state, I have not really had a need for a manager.
What about shard crashes/disconnects?
Disconnects are handled internally in the shard, and generally crashes should be avoided
You can observe tokio task panics with JoinSet and track tasks through task::Id
Each shard should be in their own task for optimal performance fyi. How was your shardmanager setup? Channels?
No, I spawned tasks without tracking them in joinset when doing 0.16, I'm doing a small rewrite of my shard manager for a new bot with 0.17 now though
But a JoinSet is probably better in this case (and in all cases)
Have you run into shard crashes? The shard task should be very small, essentially just a next-spawn loop. I mean there's not much that can panic there
Otherwise I'd use mpsc channels for state management. It fits in really nice since the shard is cancellation safe
yeah I did once surprisingly, and it for some reason could not recover with next_event, I don't have the logs but this was a stress test of over 100 shards so maybe not unexpected