-
-
Notifications
You must be signed in to change notification settings - Fork 81
Description
Question
Currently, SwarmBuilder uses tokio::task::LocalSet to ensure state consistency across bot handlers. However, this prevents the swarm from utilizing multiple CPU cores, causing single-threaded bottlenecks at ~100 bots.
Is there a possibility to support multi-threaded swarms while maintaining the correctness guarantees?
Context
When running 200+ bots with the current architecture:
- All handlers run in a single
LocalSet(single thread) - CPU usage caps at 100% on one core, even with
tokio::runtime::Builder::new_multi_thread() - Only solution is spawning multiple
bot-rustprocesses (not ideal for unified management)
I understand from the docs that spawn_local is used to guarantee state consistency:
"If you spawn a task with
tokio::spawnand move your bot into it, it's possible for Tokio to run the handler function or schedule a Minecraft tick at an unexpected moment."
Questions
-
Could per-bot isolation reduce this concern? If each bot's handler runs on its own dedicated thread (via
tokio::spawn_blockingor similar), would the state consistency guarantee hold for that individual bot? -
Partial multi-threading? Could the ECS tick schedule remain single-threaded while handler async tasks run on the multi-threaded pool?
-
Is this a known limitation? Are there plans to address swarm scaling beyond the single-threaded pattern?