diff --git a/core/src/main/java/dev/amsam0/voicechatdiscord/Core.java b/core/src/main/java/dev/amsam0/voicechatdiscord/Core.java index f392634..1090387 100644 --- a/core/src/main/java/dev/amsam0/voicechatdiscord/Core.java +++ b/core/src/main/java/dev/amsam0/voicechatdiscord/Core.java @@ -45,7 +45,7 @@ public static void enable() { } initializeNatives(); - new Thread(UpdateChecker::checkForUpdate).start(); + new Thread(UpdateChecker::checkForUpdate, "voicechat-discord: Update Checker").start(); loadConfig(); } diff --git a/core/src/main/java/dev/amsam0/voicechatdiscord/DiscordBot.java b/core/src/main/java/dev/amsam0/voicechatdiscord/DiscordBot.java index bff20f8..ee8363a 100644 --- a/core/src/main/java/dev/amsam0/voicechatdiscord/DiscordBot.java +++ b/core/src/main/java/dev/amsam0/voicechatdiscord/DiscordBot.java @@ -169,7 +169,7 @@ private void start() { _resetSenders(ptr); } platform.debug("reset thread " + startConnectionNumber + " ending"); - }); + }, "voicechat-discord: Reset Thread #" + connectionNumber); resetThread.start(); senderThread = new Thread(() -> { @@ -188,7 +188,7 @@ private void start() { } } platform.debug("sender thread " + startConnectionNumber + " ending"); - }); + }, "voicechat-discord: Sender Thread #" + connectionNumber); senderThread.start(); connection.setConnected(true); diff --git a/core/src/main/java/dev/amsam0/voicechatdiscord/SubCommands.java b/core/src/main/java/dev/amsam0/voicechatdiscord/SubCommands.java index fcd394f..6c6a204 100644 --- a/core/src/main/java/dev/amsam0/voicechatdiscord/SubCommands.java +++ b/core/src/main/java/dev/amsam0/voicechatdiscord/SubCommands.java @@ -105,7 +105,7 @@ private static void start(CommandContext sender) { } catch (InterruptedException ignored) { } botForPlayer.logInAndStart(player); - }).start(); + }, "voicechat-discord: Bot Restart for " + player.getUuid()).start(); } return; } @@ -120,7 +120,7 @@ private static void start(CommandContext sender) { platform.sendMessage(player, "Starting a voice chat..."); - new Thread(() -> bot.logInAndStart(player)).start(); + new Thread(() -> bot.logInAndStart(player), "voicechat-discord: Bot Start for " + player.getUuid()).start(); } private static void stop(CommandContext sender) { @@ -143,7 +143,7 @@ private static void stop(CommandContext sender) { bot.stop(); platform.sendMessage(sender, "Successfully stopped the bot!"); - }).start(); + }, "voicechat-discord: Bot Stop for " + player.getUuid()).start(); } private static void reloadConfig(CommandContext sender) { @@ -178,7 +178,7 @@ private static void reloadConfig(CommandContext sender) { sender, "Successfully reloaded config! Using " + bots.size() + " bot" + (bots.size() != 1 ? "s" : "") + "." ); - }).start(); + }, "voicechat-discord: Reload Config").start(); } private static void checkForUpdate(CommandContext sender) { @@ -197,7 +197,7 @@ private static void checkForUpdate(CommandContext sender) { platform.sendMessage(sender, Objects.requireNonNullElse(UpdateChecker.updateMessage, "No update found.")); else platform.sendMessage(sender, "An error occurred when checking for updates. Check the console for the error message."); - }).start(); + }, "voicechat-discord: Check for Update").start(); } private static void toggleWhisper(CommandContext sender) { diff --git a/core/src/main/rust/runtime.rs b/core/src/main/rust/runtime.rs index 536128d..9d7a1bf 100644 --- a/core/src/main/rust/runtime.rs +++ b/core/src/main/rust/runtime.rs @@ -18,11 +18,18 @@ pub struct RuntimeHolder { impl RuntimeHolder { #[inline] fn new() -> RuntimeHolder { - info!("Initializing runtime"); + let cpus = std::thread::available_parallelism().map_or(1, NonZeroUsize::get); + let worker_threads = cpus / 2; + info!(%worker_threads, "Initializing runtime"); RuntimeHolder { runtime: MaybeUninit::new( Builder::new_multi_thread() .enable_all() + .thread_name("voicechat-discord: Runtime") + .worker_threads(worker_threads) + .max_blocking_threads(4) + .event_interval(120) + .max_io_events_per_tick(512) .build() .expect("Unable to create tokio runtime"), ),