From b051b3a81dbb3bb0e7358e257b1cf82f5daee4ce Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 9 Apr 2019 21:30:06 +0100 Subject: [PATCH] change to ping based RTO --- .../ClientStack/Linden/UDP/LLUDPClient.cs | 68 ++++--------------- .../ClientStack/Linden/UDP/LLUDPServer.cs | 14 ++-- .../Linden/UDP/UnackedPacketCollection.cs | 8 --- 3 files changed, 18 insertions(+), 72 deletions(-) diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs index fc1e8462d6..f812ce13a2 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPClient.cs @@ -148,7 +148,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP /// milliseconds or longer will be resent /// Calculated from and using the /// guidelines in RFC 2988 - public int RTO; + public int m_RTO; /// Number of bytes received since the last acknowledgement was sent out. This is used /// to loosely follow the TCP delayed ACK algorithm in RFC 1122 (4.2.3.2) public int BytesSinceLastACK; @@ -190,7 +190,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP private byte[] m_packedThrottles; private int m_defaultRTO = 1000; // 1sec is the recommendation in the RFC - private int m_maxRTO = 60000; + private int m_maxRTO = 10000; public bool m_deliverPackets = true; private float m_burstTime; @@ -264,7 +264,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP } // Default the retransmission timeout to one second - RTO = m_defaultRTO; + m_RTO = m_defaultRTO; // Initialize this to a sane value to prevent early disconnects TickLastPacketReceived = Environment.TickCount & Int32.MaxValue; @@ -719,63 +719,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP } /// - /// Called when an ACK packet is received and a round-trip time for a - /// packet is calculated. This is used to calculate the smoothed - /// round-trip time, round trip time variance, and finally the - /// retransmission timeout + /// Called when we get a ping update /// - /// Round-trip time of a single packet and its + /// ping time in ms /// acknowledgement - public void UpdateRoundTrip(float r) + public void UpdateRoundTrip(int p) { - return; - /* - const float ALPHA = 0.125f; - const float BETA = 0.25f; - const float K = 4.0f; + p *= 5; + if( p> m_maxRTO) + p = m_maxRTO; + else if(p < m_defaultRTO) + p = m_defaultRTO; - if (RTTVAR == 0.0f) - { - // First RTT measurement - SRTT = r; - RTTVAR = r * 0.5f; - } - else - { - // Subsequence RTT measurement - RTTVAR = (1.0f - BETA) * RTTVAR + BETA * Math.Abs(SRTT - r); - SRTT = (1.0f - ALPHA) * SRTT + ALPHA * r; - } - - int rto = (int)(SRTT + Math.Max(m_udpServer.TickCountResolution, K * RTTVAR)); - - // Clamp the retransmission timeout to manageable values - rto = Utils.Clamp(rto, m_defaultRTO, m_maxRTO); - - RTO = rto; - - //if (RTO != rto) - // m_log.Debug("[LLUDPCLIENT]: Setting RTO to " + RTO + "ms from " + rto + "ms with an RTTVAR of " + - //RTTVAR + " based on new RTT of " + r + "ms"); - */ - } - - /// - /// Exponential backoff of the retransmission timeout, per section 5.5 - /// of RFC 2988 - /// - public void BackoffRTO() - { - return; - // Reset SRTT and RTTVAR, we assume they are bogus since things - // didn't work out and we're backing off the timeout - /* - SRTT = 0.0f; - RTTVAR = 0.0f; - - // Double the retransmission timeout - RTO = Math.Min(RTO * 2, m_maxRTO); - */ + m_RTO = p; } const double MIN_CALLBACK_MS = 20.0; diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs index 285751da1e..e3139345fd 100755 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs @@ -1120,13 +1120,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP } // Get a list of all of the packets that have been sitting unacked longer than udpClient.RTO - List expiredPackets = udpClient.NeedAcks.GetExpiredPackets(udpClient.RTO); + List expiredPackets = udpClient.NeedAcks.GetExpiredPackets(udpClient.m_RTO); if (expiredPackets != null) { - //m_log.Debug("[LLUDPSERVER]: Handling " + expiredPackets.Count + " packets to " + udpClient.AgentID + ", RTO=" + udpClient.RTO); - // Exponential backoff of the retransmission timeout - udpClient.BackoffRTO(); for (int i = 0; i < expiredPackets.Count; ++i) expiredPackets[i].UnackedMethod(expiredPackets[i]); } @@ -1515,10 +1512,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP else if (packet.Type == PacketType.CompletePingCheck) { double t = Util.GetTimeStampMS() - udpClient.m_lastStartpingTimeMS; - double c = udpClient.m_pingMS; - c = 800 * c + 200 * t; - c /= 1000; - udpClient.m_pingMS = (int)c; + double c = 0.8 * udpClient.m_pingMS; + c += 0.2 * t; + int p = (int)c; + udpClient.m_pingMS = p; + udpClient.UpdateRoundTrip(p); return; } diff --git a/OpenSim/Region/ClientStack/Linden/UDP/UnackedPacketCollection.cs b/OpenSim/Region/ClientStack/Linden/UDP/UnackedPacketCollection.cs index 1f978e13c3..32a6c404d6 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/UnackedPacketCollection.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/UnackedPacketCollection.cs @@ -215,14 +215,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP // As with other network applications, assume that an acknowledged packet is an // indication that the network can handle a little more load, speed up the transmission ackedPacket.Client.FlowThrottle.AcknowledgePackets(1); - - if (!pendingAcknowledgement.FromResend) - { - // Calculate the round-trip time for this packet and its ACK - int rtt = pendingAcknowledgement.RemoveTime - ackedPacket.TickCount; - if (rtt > 0) - ackedPacket.Client.UpdateRoundTrip(rtt); - } } else {