From b06f258319f088bcf6658880ed371ef313bac3b6 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Wed, 21 Oct 2009 16:21:08 -0700 Subject: [PATCH] * FireQueueEmpty now checks if a measurable amount of time has passed, and if not it sleeps for a small amount of time. This throttles OnQueueEmpty calls where there is no callback or the callback is doing very little work * Changed HandleQueueEmpty()'s Monitor.TryEnter() calls to locks. We want to take our time in this function and do all the work necessary, since returning too fast will induce a sleep anyways --- .../ClientStack/LindenUDP/LLClientView.cs | 42 +++++-------------- .../ClientStack/LindenUDP/LLUDPClient.cs | 8 +++- .../LindenUDP/UnackedPacketCollection.cs | 4 -- 3 files changed, 16 insertions(+), 38 deletions(-) diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 91afa4d2e7..0bb7a712c6 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -3558,45 +3558,23 @@ namespace OpenSim.Region.ClientStack.LindenUDP ProcessTextureRequests(); break; case ThrottleOutPacketType.Task: - if (Monitor.TryEnter(m_avatarTerseUpdates.SyncRoot)) + lock (m_avatarTerseUpdates.SyncRoot) { - try - { - if (m_avatarTerseUpdates.Count > 0) - { - - ProcessAvatarTerseUpdates(); - return; - } - } - finally { Monitor.Exit(m_avatarTerseUpdates.SyncRoot); } + if (m_avatarTerseUpdates.Count > 0) + ProcessAvatarTerseUpdates(); } break; case ThrottleOutPacketType.State: - if (Monitor.TryEnter(m_primFullUpdates.SyncRoot)) + lock (m_primFullUpdates.SyncRoot) { - try - { - if (m_primFullUpdates.Count > 0) - { - ProcessPrimFullUpdates(); - return; - } - } - finally { Monitor.Exit(m_primFullUpdates.SyncRoot); } + if (m_primFullUpdates.Count > 0) + ProcessPrimFullUpdates(); } - if (Monitor.TryEnter(m_primTerseUpdates.SyncRoot)) + lock (m_primTerseUpdates.SyncRoot) { - try - { - if (m_primTerseUpdates.Count > 0) - { - ProcessPrimTerseUpdates(); - return; - } - } - finally { Monitor.Exit(m_primTerseUpdates.SyncRoot); } + if (m_primTerseUpdates.Count > 0) + ProcessPrimTerseUpdates(); } break; } @@ -10344,7 +10322,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP { if (lookup.Heap.ContainsHandle(lookup.Handle)) lookup.Heap[lookup.Handle] = - new MinHeapItem(priority, item.Value, item.LocalID); + new MinHeapItem(priority, item.Value, item.LocalID, this.m_comparison); } else { diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClient.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClient.cs index 0a090b4452..71f4c47967 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClient.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClient.cs @@ -535,14 +535,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP ThrottleOutPacketType type = (ThrottleOutPacketType)i; QueueEmpty callback = OnQueueEmpty; + int start = Environment.TickCount; + if (callback != null) { try { callback(type); } catch (Exception e) { m_log.Error("[LLUDPCLIENT]: OnQueueEmpty(" + type + ") threw an exception: " + e.Message, e); } } - // HACK: Try spending some extra time here to slow down OnQueueEmpty calls - //System.Threading.Thread.Sleep(100); + // Make sure all queue empty calls take at least a measurable amount of time, + // otherwise we'll peg a CPU trying to fire these too fast + if (Environment.TickCount == start) + System.Threading.Thread.Sleep((int)m_udpServer.TickCountResolution); m_onQueueEmptyRunning[i] = false; } diff --git a/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs b/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs index bd5fe1cab4..016712f8ae 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs @@ -125,10 +125,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP expiredPackets = new List(); expiredPackets.Add(packet); } - /*else - { - break; - }*/ } }