Skip to content

Thread Model

boyism80 edited this page Jul 14, 2026 · 2 revisions

Thread Model

Thread Architecture

Within each Game process:

  • I/O threads handle socket read/write (boost::asio).
  • Logic threads run game handlers, map updates, and Lua.
  • Received packets are dispatched from I/O to the logic thread that owns the session's map; responses go back through I/O.

Map-to-thread assignment

Maps are bound to logic threads by runtime map ID (map.id):

logic_thread = map.id % N   // N = number of logic threads

For static source maps, map.id equals model.id. Runtime instance maps receive a distinct map.id, so they may run on a different logic thread from their source even though clients still use the same model.id for map assets.

All objects on the same map run on the same logic thread, avoiding locks between nearby objects.

Trade-offs

Uneven map distribution can overload a single logic thread. Communication between maps on different threads is more complex than within a single map. I/O and logic thread counts are configurable in the server config file.

An additional AMQP thread handles RabbitMQ consume/publish (not shown in the diagram).

Related pages

Clone this wiki locally