1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Change how max_lag is calculated and reported (#14378)

-Change how max_lag is calculated and reported

- Cap singleplayer step at 60Hz

- Clarify dedicated_server_step
This commit is contained in:
sfan5 2024-02-26 20:46:57 +01:00 committed by GitHub
parent 63a9853811
commit 5d8a22066c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 40 additions and 25 deletions

View file

@ -646,15 +646,29 @@ void Server::AsyncRunStep(float dtime, bool initial_step)
{
MutexAutoLock lock(m_env_mutex);
// Figure out and report maximum lag to environment
float max_lag = m_env->getMaxLagEstimate();
max_lag *= 0.9998; // Decrease slowly (about half per 5 minutes)
if(dtime > max_lag){
if(dtime > 0.1 && dtime > max_lag * 2.0)
infostream<<"Server: Maximum lag peaked to "<<dtime
<<" s"<<std::endl;
max_lag = dtime;
constexpr float lag_warn_threshold = 2.0f;
// Decrease value gradually, halve it every minute.
if (m_max_lag_decrease.step(dtime, 0.5f)) {
// To reproduce this number enter "solve (x)**(60/0.5) = 0.5"
// into Wolfram Alpha.
max_lag *= 0.99425f;
}
// Report a 20% change to the log but only if we're >10% off target
// also report if we crossed into the warning boundary
if (dtime >= max_lag * 1.2f ||
(max_lag < lag_warn_threshold && dtime >= lag_warn_threshold)) {
const float steplen = getStepSettings().steplen;
if (dtime > steplen * 1.1f) {
auto &to = dtime >= lag_warn_threshold ? warningstream : infostream;
to << "Server: Maximum lag peaked at " << dtime
<< " (steplen=" << steplen << ")" << std::endl;
}
}
max_lag = std::max(max_lag, dtime),
m_env->reportMaxLagEstimate(max_lag);
// Step environment