From e0f0b88dece110ca10208a2f826f9e360a9d7826 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Tue, 16 Jul 2013 13:01:39 -0700 Subject: In the pursuit of using less CPU: now trying to avoid blocking queues altogether. Instead, this uses a timer. No sure if it's better or worse, but worth the try. --- .../GridServiceThrottleModule.cs | 71 +++++++++++++++++++--- .../UserManagement/UserManagementModule.cs | 64 ++++++++++++++++--- 2 files changed, 120 insertions(+), 15 deletions(-) diff --git a/OpenSim/Region/CoreModules/Framework/GridServiceThrottle/GridServiceThrottleModule.cs b/OpenSim/Region/CoreModules/Framework/GridServiceThrottle/GridServiceThrottleModule.cs index a069317..83be644 100644 --- a/OpenSim/Region/CoreModules/Framework/GridServiceThrottle/GridServiceThrottleModule.cs +++ b/OpenSim/Region/CoreModules/Framework/GridServiceThrottle/GridServiceThrottleModule.cs @@ -48,18 +48,26 @@ namespace OpenSim.Region.CoreModules.Framework MethodBase.GetCurrentMethod().DeclaringType); private readonly List m_scenes = new List(); + private System.Timers.Timer m_timer = new System.Timers.Timer(); //private OpenSim.Framework.BlockingQueue m_RequestQueue = new OpenSim.Framework.BlockingQueue(); - private OpenSim.Framework.DoubleQueue m_RequestQueue = new OpenSim.Framework.DoubleQueue(); + // private OpenSim.Framework.DoubleQueue m_RequestQueue = new OpenSim.Framework.DoubleQueue(); + private Queue m_RequestQueue = new Queue(); public void Initialise(IConfigSource config) { - Watchdog.StartThread( - ProcessQueue, - "GridServiceRequestThread", - ThreadPriority.BelowNormal, - true, - false); + m_timer = new System.Timers.Timer(); + m_timer.AutoReset = false; + m_timer.Interval = 15000; // 15 secs at first + m_timer.Elapsed += ProcessQueue; + m_timer.Start(); + + //Watchdog.StartThread( + // ProcessQueue, + // "GridServiceRequestThread", + // ThreadPriority.BelowNormal, + // true, + // false); } public void AddRegion(Scene scene) @@ -89,6 +97,16 @@ namespace OpenSim.Region.CoreModules.Framework client.OnRegionHandleRequest += OnRegionHandleRequest; } + //void OnMakeRootAgent(ScenePresence obj) + //{ + // lock (m_timer) + // { + // m_timer.Stop(); + // m_timer.Interval = 1000; + // m_timer.Start(); + // } + //} + public void PostInitialise() { } @@ -118,7 +136,8 @@ namespace OpenSim.Region.CoreModules.Framework } GridRegionRequest request = new GridRegionRequest(client, regionID); - m_RequestQueue.Enqueue(request); + lock (m_RequestQueue) + m_RequestQueue.Enqueue(request); } @@ -134,6 +153,41 @@ namespace OpenSim.Region.CoreModules.Framework return false; } + private bool AreThereRootAgents() + { + foreach (Scene s in m_scenes) + { + if (s.GetRootAgentCount() > 0) + return true; + } + + return false; + } + + private void ProcessQueue(object sender, System.Timers.ElapsedEventArgs e) + { + while (m_RequestQueue.Count > 0) + { + GridRegionRequest request = null; + lock (m_RequestQueue) + request = m_RequestQueue.Dequeue(); + if (request != null) + { + GridRegion r = m_scenes[0].GridService.GetRegionByUUID(UUID.Zero, request.regionID); + + if (r != null && r.RegionHandle != 0) + request.client.SendRegionHandle(request.regionID, r.RegionHandle); + } + } + + if (AreThereRootAgents()) + m_timer.Interval = 1000; // 1 sec + else + m_timer.Interval = 10000; // 10 secs + + m_timer.Start(); + } + private void ProcessQueue() { while (true) @@ -150,6 +204,7 @@ namespace OpenSim.Region.CoreModules.Framework } } } + } class GridRegionRequest diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs index 9f5e4ae..61c1e70 100644 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs @@ -61,8 +61,10 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement // Throttle the name requests //private OpenSim.Framework.BlockingQueue m_RequestQueue = new OpenSim.Framework.BlockingQueue(); - private OpenSim.Framework.DoubleQueue m_RequestQueue = new OpenSim.Framework.DoubleQueue(); + //private OpenSim.Framework.DoubleQueue m_RequestQueue = new OpenSim.Framework.DoubleQueue(); + private Queue m_RequestQueue = new Queue(); + private System.Timers.Timer m_timer; #region ISharedRegionModule @@ -599,12 +601,18 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement protected void Init() { RegisterConsoleCmds(); - Watchdog.StartThread( - ProcessQueue, - "NameRequestThread", - ThreadPriority.BelowNormal, - true, - false); + //Watchdog.StartThread( + // ProcessQueue, + // "NameRequestThread", + // ThreadPriority.BelowNormal, + // true, + // false); + + m_timer = new System.Timers.Timer(); + m_timer.AutoReset = false; + m_timer.Interval = 15000; // 15 secs at first + m_timer.Elapsed += ProcessQueue; + m_timer.Start(); } @@ -698,6 +706,48 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement } } + private bool AreThereRootAgents() + { + foreach (Scene s in m_Scenes) + { + if (s.GetRootAgentCount() > 0) + return true; + } + + return false; + } + + private void ProcessQueue(object sender, System.Timers.ElapsedEventArgs e) + { + while (m_RequestQueue.Count > 0) + { + NameRequest request = null; + lock (m_RequestQueue) + request = m_RequestQueue.Dequeue(); + + if (request != null) + { + string[] names; + bool foundRealName = TryGetUserNames(request.uuid, out names); + + if (names.Length == 2) + { + if (!foundRealName) + m_log.DebugFormat("[USER MANAGEMENT MODULE]: Sending {0} {1} for {2} to {3} since no bound name found", names[0], names[1], request.uuid, request.client.Name); + + request.client.SendNameReply(request.uuid, names[0], names[1]); + } + } + } + + if (AreThereRootAgents()) + m_timer.Interval = 1000; // 1 sec + else + m_timer.Interval = 10000; // 10 secs + + m_timer.Start(); + + } } class NameRequest -- cgit v1.1