Multiple Tokio Runtimes lead to heavy cpu usage

101 points Lower_Calligrapher_6 24 comments

Making a discord bot to allow servers to run custom made luau scripts (using mlua). Unfortunately, I'm running into an issue surrounding heavy CPU usage when spawning just 24 threads, each with their own tokio LocalRuntime incurs nearly 30% extra CPU usage.

Not sure why multiple tokio LocalRuntimes (LocalSet+Runtime is even worse) incurs such a heavy CPU penalty. Tried using tokio console but just enabling it shot up cpu usage to 150%.

Source code (if anyone is interested in helping debug it): https://github.com/anti-raid/template-worker