10.Understanding server main loop

Detailed information on server main loop is guided in Reception and Event Callback from Server and

16. Managing Timer loop, RMI, Event from server.

10.1Reception and Event Callback from Server

Game server utilizes the entire CPU and Thread poolingto handle reception of other clients when accessing the database. ProudNet also works in thread pooling method which has following features.

The below picture shows a case where client A,B, and C are included in server, and how they are queued for each RMIs or events that just occurred inside of Proud.CNetServer. A1, A2, and A3 are events or RMIs for client A. In the same manner, B1, B2, and B3 are for client B. There are 2 threads in pool. In the case like this, the operation runs as followed.

그림 10-1Thread Pool Operation

10.2Timer callback from server

Just like game client, game server also can operate something at a fixed time. In the case like this, there is a way to have a very simple loop as followed.

while(1)
{
do_something(); // The world 1000 starts operation
Sleep(1); // Wait for a specific time
}

There is also a way to handle the loop from a separated thread using Proud.CTimerThread or Proud.CTimerQueue.

However, it is recommended for the thread pool of server directly calls the user-defined timer function. For instance, if server has only 1 thread, you can reduce the number of access to the critical section since the timer function and event callback can be performed in a single thread.