From 8e5fe0257c59f13631c1e2676c838a0d4009bbb1 Mon Sep 17 00:00:00 2001
From: Melanie Thielker
Date: Wed, 17 Dec 2008 17:05:12 +0000
Subject: Mantis #2850 Applying the patch to reduce the load caused by the
 throttle loop even more

---
 OpenSim/Region/ClientStack/LindenUDP/LLPacketQueue.cs | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

(limited to 'OpenSim')

diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLPacketQueue.cs b/OpenSim/Region/ClientStack/LindenUDP/LLPacketQueue.cs
index 81f3922..a8785a6 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLPacketQueue.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLPacketQueue.cs
@@ -327,11 +327,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP
             // we've hit the throttle limit or there's no more packets to send
             lock (this)
             {
+                // this variable will be true if there was work done in the last execution of the
+                // loop, since each pass through the loop checks the queue length, we no longer 
+                // need the check on entering the loop
+                bool qchanged = true;
                 ResetCounters();
                 // m_log.Info("[THROTTLE]: Entering Throttle");
-                while (TotalThrottle.UnderLimit() && PacketsWaiting() &&
+                while (TotalThrottle.UnderLimit() && qchanged &&
                        (throttleLoops <= MaxThrottleLoops))
                 {
+                    qchanged = false; // We will break out of the loop if no work was accomplished
+
                     throttleLoops++;
                     //Now comes the fun part..   we dump all our elements into m_packetQueue that we've saved up.
                     if ((ResendOutgoingPacketQueue.Count > 0) && ResendThrottle.UnderLimit())
@@ -341,6 +347,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
                         SendQueue.Enqueue(qpack);
                         TotalThrottle.AddBytes(qpack.Packet.ToBytes().Length);
                         ResendThrottle.AddBytes(qpack.Packet.ToBytes().Length);
+                        qchanged = true;
                     }
                     
                     if ((LandOutgoingPacketQueue.Count > 0) && LandThrottle.UnderLimit())
@@ -350,6 +357,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
                         SendQueue.Enqueue(qpack);
                         TotalThrottle.AddBytes(qpack.Packet.ToBytes().Length);
                         LandThrottle.AddBytes(qpack.Packet.ToBytes().Length);
+                        qchanged = true;
                     }
                     
                     if ((WindOutgoingPacketQueue.Count > 0) && WindThrottle.UnderLimit())
@@ -359,6 +367,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
                         SendQueue.Enqueue(qpack);
                         TotalThrottle.AddBytes(qpack.Packet.ToBytes().Length);
                         WindThrottle.AddBytes(qpack.Packet.ToBytes().Length);
+                        qchanged = true;
                     }
                     
                     if ((CloudOutgoingPacketQueue.Count > 0) && CloudThrottle.UnderLimit())
@@ -368,6 +377,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
                         SendQueue.Enqueue(qpack);
                         TotalThrottle.AddBytes(qpack.Packet.ToBytes().Length);
                         CloudThrottle.AddBytes(qpack.Packet.ToBytes().Length);
+                        qchanged = true;
                     }
                     
                     if ((TaskOutgoingPacketQueue.Count > 0 || TaskLowpriorityPacketQueue.Count > 0) && TaskThrottle.UnderLimit())
@@ -385,6 +395,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
                         }
                         TotalThrottle.AddBytes(qpack.Packet.ToBytes().Length);
                         TaskThrottle.AddBytes(qpack.Packet.ToBytes().Length);
+                        qchanged = true;
                     }
                     
                     if ((TextureOutgoingPacketQueue.Count > 0) && TextureThrottle.UnderLimit())
@@ -394,6 +405,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
                         SendQueue.Enqueue(qpack);
                         TotalThrottle.AddBytes(qpack.Packet.ToBytes().Length);
                         TextureThrottle.AddBytes(qpack.Packet.ToBytes().Length);
+                        qchanged = true;
                     }
                     
                     if ((AssetOutgoingPacketQueue.Count > 0) && AssetThrottle.UnderLimit())
@@ -403,6 +415,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
                         SendQueue.Enqueue(qpack);
                         TotalThrottle.AddBytes(qpack.Packet.ToBytes().Length);
                         AssetThrottle.AddBytes(qpack.Packet.ToBytes().Length);
+                        qchanged = true;
                     }
                 }
                 // m_log.Info("[THROTTLE]: Processed " + throttleLoops + " packets");
-- 
cgit v1.1