diff options
author | you <ovvv@web.de> | 2018-06-23 09:16:01 +0200 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2018-06-23 09:16:01 +0200 |
commit | 968ce9af598024ec71e9ffb2d15c3997a13ad754 (patch) | |
tree | 0ad28040f1deb3ca1885d5147b23931d237a76f5 /src/network/connection.cpp | |
parent | 07b1743d3db086f0f984968252d9e3ac71336a7e (diff) | |
download | dragonfireclient-968ce9af598024ec71e9ffb2d15c3997a13ad754.tar.xz |
RTT fixes (#7428)
* Few code updates
* Do not show average RTT before timing out
* Fix unwanted integer division in RTTStatistics
* Fix float format, prettier jitter calculation
* Use +=, 0.1f -> 100.0f for stronger average updates
Diffstat (limited to 'src/network/connection.cpp')
-rw-r--r-- | src/network/connection.cpp | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/src/network/connection.cpp b/src/network/connection.cpp index 69dc0cdff..a9f8ee082 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -825,8 +825,9 @@ void Peer::DecUseCount() delete this; } -void Peer::RTTStatistics(float rtt, const std::string &profiler_id, - unsigned int num_samples) { +void Peer::RTTStatistics(float rtt, const std::string &profiler_id) +{ + static const float avg_factor = 100.0f / MAX_RELIABLE_WINDOW_SIZE; if (m_last_rtt > 0) { /* set min max values */ @@ -837,21 +838,14 @@ void Peer::RTTStatistics(float rtt, const std::string &profiler_id, /* do average calculation */ if (m_rtt.avg_rtt < 0.0) - m_rtt.avg_rtt = rtt; + m_rtt.avg_rtt = rtt; else - m_rtt.avg_rtt = m_rtt.avg_rtt * (num_samples/(num_samples-1)) + - rtt * (1/num_samples); + m_rtt.avg_rtt += (rtt - m_rtt.avg_rtt) * avg_factor; /* do jitter calculation */ //just use some neutral value at beginning - float jitter = m_rtt.jitter_min; - - if (rtt > m_last_rtt) - jitter = rtt-m_last_rtt; - - if (rtt <= m_last_rtt) - jitter = m_last_rtt - rtt; + float jitter = std::fabs(rtt - m_last_rtt); if (jitter < m_rtt.jitter_min) m_rtt.jitter_min = jitter; @@ -859,10 +853,9 @@ void Peer::RTTStatistics(float rtt, const std::string &profiler_id, m_rtt.jitter_max = jitter; if (m_rtt.jitter_avg < 0.0) - m_rtt.jitter_avg = jitter; + m_rtt.jitter_avg = jitter; else - m_rtt.jitter_avg = m_rtt.jitter_avg * (num_samples/(num_samples-1)) + - jitter * (1/num_samples); + m_rtt.jitter_avg += (jitter - m_rtt.jitter_avg) * avg_factor; if (!profiler_id.empty()) { g_profiler->graphAdd(profiler_id + "_rtt", rtt); @@ -934,16 +927,12 @@ void UDPPeer::setNonLegacyPeer() void UDPPeer::reportRTT(float rtt) { - if (rtt < 0.0) { - return; - } - RTTStatistics(rtt,"rudp",MAX_RELIABLE_WINDOW_SIZE*10); + assert(rtt >= 0.0f); + + RTTStatistics(rtt, "rudp"); float timeout = getStat(AVG_RTT) * RESEND_TIMEOUT_FACTOR; - if (timeout < RESEND_TIMEOUT_MIN) - timeout = RESEND_TIMEOUT_MIN; - if (timeout > RESEND_TIMEOUT_MAX) - timeout = RESEND_TIMEOUT_MAX; + timeout = rangelim(timeout, RESEND_TIMEOUT_MIN, RESEND_TIMEOUT_MAX); MutexAutoLock usage_lock(m_exclusive_access_mutex); resend_timeout = timeout; |