Skip to content

SwarmBuilder: support for multi-threaded execution #319

@bystepii

Description

@bystepii

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-rust processes (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::spawn and 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

  1. Could per-bot isolation reduce this concern? If each bot's handler runs on its own dedicated thread (via tokio::spawn_blocking or similar), would the state consistency guarantee hold for that individual bot?

  2. Partial multi-threading? Could the ECS tick schedule remain single-threaded while handler async tasks run on the multi-threaded pool?

  3. Is this a known limitation? Are there plans to address swarm scaling beyond the single-threaded pattern?

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions