MantisBT - Zandronum
View Issue Details
0003620Zandronum[All Projects] Bugpublic2019-03-10 22:182019-06-04 20:18
voidpointer 
 
normalmajoralways
newopen 
Ubuntu 18.10Ubuntu 18.10
 
 
0003620: Unnecessarily high CPU usage when zandronum-server is idle
When there are zero connected clients for an instance of zandronum-server, I am seeing around 8-10% CPU usage. This is not scalable. There should be as close to 0% CPU usage as possible when there are no connected clients for a server instance of Zandronum.

After looking at the Zandronum code base a bit, I see this in sv_main.cpp:

    lPreviousTics = static_cast<LONG> ( g_lGameTime / (( 1.0 / TICRATE ) * 1000.0 ) );

    lNowTime = I_MSTime( );
    lNewTics = static_cast<LONG> ( lNowTime / (( 1.0 / TICRATE ) * 1000.0 ) );

    lCurTics = lNewTics - lPreviousTics;
    while ( lCurTics <= 0 )
    {
        // [BB] Recieve packets whenever possible (not only once each tic) to allow
        // for an accurate ping measurement.
        SERVER_GetPackets( );

        I_Sleep( 1 );
        lNowTime = I_MSTime( );
        lNewTics = static_cast<LONG> ( lNowTime / (( 1.0 / TICRATE ) * 1000.0 ) );
        lCurTics = lNewTics - lPreviousTics;
    }

The delta calculations are strange and confusing, but the `I_Sleep(1)` is very inefficient for the CPU. The sleep needs to be longer so the OS can schedule other work for the CPU.

Could we make this an `I_Sleep(500)` (2 FPS) when there are 0 connected clients, and bump it back up to 35 FPS when 1 or more clients are connected?
No tags attached.
Issue History
2019-03-10 22:18voidpointerNew Issue
2019-06-04 20:18DuskNote Added: 0020722

Notes
(0020722)
Dusk   
2019-06-04 20:18   
Perhaps we could make Zandronum call select() when there are no clients connected?