Threading the server
Plans/Ideas
Per-map threads and per-player threads
Mutex locks in players, and in 'map queues'.
One map thread when wanting to do something such as teleport an object to another map, get a lock on the map's queue and put it in a queue of things for the other map thread to do in it's next tick.
In order to avoid all chance of deadlock, do this when processing the queue of things other threads told the thread to do:
Lock it's queue
Copy it's queue and clear the original
Unlock it's queue
Process the copy of the queue.
Otherwise, there is a small chance that two processing queues at the same time might want to lock eachother to add to the list.
Alternatively one could do per-query-entry locking, however that wouldn't work with a linked list, plus that much locking and unlocking may become expensive on cpu
-
Issues to watch out for
I consider this to be a very low priority thing, however made the wiki page here to make sure some ideas about implementing it are not lost —
Alex Schultz 2006/10/09 11:15
put information from the logs of IRC discussion here
Nicolas's ideas
Things to solve:
Things that should definitely be threaded:
Things that would be nice to thread:
one thread per map
issue: how will the “Object.Teleport” Python function work, since it couldn't cross thread boundaries? simply remove it, and force script makers to use other means?
same issue with ready_map() through scripts - what happens if the map is already loaded and has its thread running?
thread for socket processing, one per player maybe
ideally, one could thread potentially long operations like massive item selling, or massive item drop
thread socket sending to players, to make the previous operations faster?
split eg item selling and player notification, with that latter moved to a separate thread