music-bot icon indicating copy to clipboard operation
music-bot copied to clipboard

Question: how to implement sharding while keeping the API functionality

Open ig4e opened this issue 2 years ago • 6 comments

how to implement sharding while keeping the API functionality, I tried getting the queue using useQueue from discord-player while sharding and sadly there's no data

ig4e avatar Feb 15 '24 00:02 ig4e

useQueue does work, @mariusbegby did it with cadence bot. Correct shard with correct guild id should work just fine when invoked from discord.

However the website may not work with shards using current setup, as any of the shard may receive the request. The overall design of this project does not involve sharding in mind but I will be happy to include this feature in the future.

twlite avatar Feb 15 '24 01:02 twlite

@ig4e there should be no special considerations when using useQueue() and sharding. For example, look at this pause command and how useQueue() is implemented: https://github.com/mariusbegby/cadence-discord-bot/blob/main/src/interactions/slashcommands/pause.ts

It just takes guild id as normal.

mariusbegby avatar Feb 20 '24 07:02 mariusbegby

@mariusbegby There are no special considerations on the bot side, but it currently doesn't manage/detect shards on the API side.

How will communication between different shards/processes with discord-player bindings be implemented?

ig4e avatar Mar 02 '24 19:03 ig4e

useQueue does work, @mariusbegby did it with cadence bot. Correct shard with correct guild id should work just fine when invoked from discord.

However the website may not work with shards using current setup, as any of the shard may receive the request. The overall design of this project does not involve sharding in mind but I will be happy to include this feature in the future.

Thanks! I would love to see how it's done, I appreciate it if you could give me a hint ^^

ig4e avatar Mar 02 '24 19:03 ig4e

@ig4e I am not sure what problem you are running into. I am sharding using discord.js, nothing fancy and it works out of the box. I don't need a different setup of discord-player to get it to work with sharding. It works exactly the same as if no sharding would be used.

Hopefully you get something working, but I honestly cannot see what the problem is here.

mariusbegby avatar Mar 02 '24 22:03 mariusbegby

as far as I understand, @ig4e is talking about the website part, which I've already responded to saying

However the website may not work with shards using current setup, as any of the shard may receive the request. The overall design of this project does not involve sharding in mind but I will be happy to include this feature in the future.

The website part may not receive correct shard because there would also be multiple clusters of web servers working simultaneously meaning any of those would receive the request we send. This was not considered while implementing the api, due to which it is not possible to use the website with shards at the moment. We'll need to update the code to include data from all shards in the rest api part.

twlite avatar Mar 03 '24 01:03 twlite