Skip to content

Commit 3e1ae5d

Browse files
committed
Improve pulse sleep on busy servers (#4853)
HandlePulseSleep now returns as soon as the sync thread queues work, instead of sleeping busy_sleep_time at the start of every pulse. Mitigates #4853 (high player count chat lag / packet loss with low CPU): with threadnet, the unconditional sleep could cap DoPulse while m_InResultQueue still grew. Replaced with a short 1ms polling loop that exits on PendingWorkToDo. Idle path unchanged (full idle_sleep_time). server_logic_fps_limit remains the hard cap. busy_sleep_time is no longer used on this path (option still parses). Test plan: code review only; needs 600+ player confirmation.
1 parent 2239a7b commit 3e1ae5d

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

Server/core/CServerImpl.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -544,21 +544,20 @@ void CServerImpl::HandlePulseSleep()
544544
return;
545545
}
546546

547-
CTickCount sleepLimit = CTickCount::Now() + CTickCount((long long)iSleepIdleMs);
548-
549-
// Initial sleep period
550-
int iInitialMs = std::min(iSleepIdleMs, iSleepBusyMs);
551-
Sleep(Clamp(1, iInitialMs, 50));
552-
553-
// Remaining idle sleep period
554-
int iFinalMs = Clamp(1, iSleepIdleMs - iInitialMs, 50);
555-
for (int i = 0; i < iFinalMs; i++)
547+
// Sleep up to idle_sleep_time in 1ms ticks, exiting the moment the sync
548+
// thread queues a packet. The previous code did a blind Sleep for
549+
// busy_sleep_time at the top of every pulse before checking the inbound
550+
// queue, which capped logic FPS near 1000/busy_sleep_time on busy servers
551+
// regardless of how full the queue already was (#4853). busy_sleep_time
552+
// is no longer consulted on this path; server_logic_fps_limit is the
553+
// existing knob for a hard cap.
554+
const int iSleepMs = Clamp(0, iSleepIdleMs, 50);
555+
const CTickCount deadline = CTickCount::Now() + CTickCount((long long)iSleepMs);
556+
while (CTickCount::Now() < deadline)
556557
{
557558
if (m_pModManager->PendingWorkToDo())
558-
break;
559+
return;
559560
Sleep(1);
560-
if (CTickCount::Now() >= sleepLimit)
561-
break;
562561
}
563562
}
564563

0 commit comments

Comments
 (0)