Azusfin / lavacoffee

A fast and rich-featured lavalink wrapper for node.js
https://Azusfin.github.io/lavacoffee/index.html
BSD 3-Clause "New" or "Revised" License
7 stars 2 forks source link

Load Balancing is not working #2

Closed maxall41 closed 2 years ago

maxall41 commented 2 years ago

Lavacoffee is working much better for me than the other clients which had much more issues. But I'm running into this issue where load balancing just refuses to work and always uses the first node even if the first node is down it will not use the second node if i only pass the second node to the config and not the first it uses the second node but when passing multiple it always uses the first even if the first is pinned at 100% CPU. Does anybody know why this is happening?

XzFirzal commented 2 years ago

Any sample code of how you create the lava instance and players?

maxall41 commented 2 years ago

Yeah they are created like this:

config example:

/**
   * Lavalink config
 */
  nodeConfig: [
    {
      url: "111.111.1.111:2333",
      password: process.env.LAVALINK_PASSWORD,
      name: "Node 1",
    },
    {
      url: "11.111.111.111:2333",
      password: process.env.LAVALINK_PASSWORD,
      name: "Node 2",
    },
  ],

init code:

// Configure discord client
const client = new Discord.Client({
messageCacheLifetime: 21600,
messageSweepInterval: 43200,
intents: [
  Discord.Intents.FLAGS.GUILDS,
  Discord.Intents.FLAGS.GUILD_MESSAGES,
  Discord.Intents.FLAGS.GUILD_VOICE_STATES,
],
});
client.login(config.discordToken);
//@ts-ignore
client.music = new CoffeeLava({
send: (guildID, p) => {
  const guild = client.guilds.cache.get(guildID);
  guild?.shard.send(p);
},
});
// Status updater
client.on("ready", () => {
setInterval(() => {
  client.user.setActivity(`${client.guilds.cache.size} Servers`, {
    type: "WATCHING",
  });
}, 60000); // Runs this every 60 seconds.
});

for (const node of config.nodeConfig) {
//@ts-ignore
client.music.add({
  ...node,
  retryAmount: Infinity,
});
}

//@ts-ignore
client.music.on("connect", () => {
console.log(`[music] now connected to lavalink`);
});
//@ts-ignore
client.on("raw", (p) => client.music.updateVoiceData(p));

client.on("ready", () => {
//@ts-ignore
client.music.init(client.user!.id);
console.log("[discord] ready!");
});
XzFirzal commented 2 years ago

LGTM, looks almost like the testing config. Noting that disconnecting player from voice channel won't destroy the player unless you're doing player.destroy(), therefore there will be no node change on the player

maxall41 commented 2 years ago

Can you give an example of the best practices for initializing lavacoffee?

Azusfin commented 2 years ago

By the way, the load balancing is counted by the node systemLoad, not the lavalinkLoad