[SDL] [Framework] Event-based Networking
cgloeckner at freenet.de
Wed Mar 20 01:20:16 PDT 2013
Nathaniel J Fries wrote:
> The thread-per-client model is a bad model for any highly-interactive program. Like I said, synchronization bottlenecks. The key is to do as little synchronizing as possible; which means using a specific thread for a specific task and minimizing thread interaction.
My current approach is:
- n clients are handled by 2*n worker threads (one for sending, one for receiving) on the server
- each worker-thread does access either the worker's outgoing queue (for popping events to send) or the server's incomming queue (to enqueue new events to a main queue)
- the later model will pop events from the server's incomming queue (that means events that arrived from different workers) and handle it
- the model also will push events (so-to-say "answers") to the worker's outgoing queue (for sending them).
The number of threads is definitly larger then the number of processors. Do you have an idea where mit bootlenecks might be? I'm not sure.
the worker's receiving loop got an event and tries to push it to the server's incomming queue.
another worker's receiving loop is doing the same and has to wait for an unlocked queue.
more receiving loops will also wait. but the sending loops are still able to send outgoing data.
but also the model has to wait for an unlocked queue to pop an event from it
I'm not sure whether this is already a bottleneck or just close-to-a-bottleneck... what's your opinion?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SDL