Skip to content

Commit

Permalink
Thread names and hopefully reduce tokio overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
amsam0 committed Aug 25, 2024
1 parent 3d4418b commit 80e159c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/dev/amsam0/voicechatdiscord/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void enable() {
}
initializeNatives();

new Thread(UpdateChecker::checkForUpdate).start();
new Thread(UpdateChecker::checkForUpdate, "voicechat-discord: Update Checker").start();
loadConfig();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() -> {
Expand All @@ -188,7 +188,7 @@ private void start() {
}
}
platform.debug("sender thread " + startConnectionNumber + " ending");
});
}, "voicechat-discord: Sender Thread #" + connectionNumber);
senderThread.start();

connection.setConnected(true);
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/dev/amsam0/voicechatdiscord/SubCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -120,7 +120,7 @@ private static void start(CommandContext<?> sender) {

platform.sendMessage(player, "<yellow>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) {
Expand All @@ -143,7 +143,7 @@ private static void stop(CommandContext<?> sender) {
bot.stop();

platform.sendMessage(sender, "<green>Successfully stopped the bot!");
}).start();
}, "voicechat-discord: Bot Stop for " + player.getUuid()).start();
}

private static void reloadConfig(CommandContext<?> sender) {
Expand Down Expand Up @@ -178,7 +178,7 @@ private static void reloadConfig(CommandContext<?> sender) {
sender,
"<green>Successfully reloaded config! Using " + bots.size() + " bot" + (bots.size() != 1 ? "s" : "") + "."
);
}).start();
}, "voicechat-discord: Reload Config").start();
}

private static void checkForUpdate(CommandContext<?> sender) {
Expand All @@ -197,7 +197,7 @@ private static void checkForUpdate(CommandContext<?> sender) {
platform.sendMessage(sender, Objects.requireNonNullElse(UpdateChecker.updateMessage, "<red>No update found."));
else
platform.sendMessage(sender, "<red>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) {
Expand Down
9 changes: 8 additions & 1 deletion core/src/main/rust/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
Expand Down

0 comments on commit 80e159c

Please sign in to comment.