diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index 65a341e274..f472dba9c6 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs @@ -9614,61 +9614,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP #region Parcel related packets - // acumulate several HandleRegionHandleRequest consecutive overlaping requests - // to be done with minimal resources as possible - // variables temporary here while in test - - Queue RegionHandleRequests = new Queue(); - bool RegionHandleRequestsInService = false; - private bool HandleRegionHandleRequest(IClientAPI sender, Packet Pack) { - UUID currentUUID; - RegionHandleRequest handlerRegionHandleRequest = OnRegionHandleRequest; - if (handlerRegionHandleRequest == null) - return true; - - RegionHandleRequestPacket rhrPack = (RegionHandleRequestPacket)Pack; - - lock (RegionHandleRequests) + if (handlerRegionHandleRequest != null) { - if (RegionHandleRequestsInService) - { - // we are already busy doing a previus request - // so enqueue it - RegionHandleRequests.Enqueue(rhrPack.RequestBlock.RegionID); - return true; - } - - // else do it - currentUUID = rhrPack.RequestBlock.RegionID; - RegionHandleRequestsInService = true; + RegionHandleRequestPacket rhrPack = (RegionHandleRequestPacket)Pack; + handlerRegionHandleRequest(this, rhrPack.RequestBlock.RegionID); } - while (true) - { - handlerRegionHandleRequest(this, currentUUID); - - lock (RegionHandleRequests) - { - // exit condition, nothing to do or closed - // current code seems to assume we may loose the handler at anytime, - // so keep checking it - handlerRegionHandleRequest = OnRegionHandleRequest; - - if (RegionHandleRequests.Count == 0 || !IsActive || handlerRegionHandleRequest == null) - { - RegionHandleRequests.Clear(); - RegionHandleRequestsInService = false; - return true; - } - currentUUID = RegionHandleRequests.Dequeue(); - } - } - - return true; // actually unreached + return true; } private bool HandleParcelInfoRequest(IClientAPI sender, Packet Pack) diff --git a/OpenSim/Region/CoreModules/Framework/ServiceThrottle/ServiceThrottleModule.cs b/OpenSim/Region/CoreModules/Framework/ServiceThrottle/ServiceThrottleModule.cs index 3abacbd3cf..36fb57a18d 100644 --- a/OpenSim/Region/CoreModules/Framework/ServiceThrottle/ServiceThrottleModule.cs +++ b/OpenSim/Region/CoreModules/Framework/ServiceThrottle/ServiceThrottleModule.cs @@ -48,31 +48,16 @@ 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 Queue m_RequestQueue = new Queue(); - private Dictionary> m_Pending = new Dictionary>(); - private int m_Interval; - + private JobEngine m_processorJobEngine; + #region ISharedRegionModule public void Initialise(IConfigSource config) { - m_Interval = Util.GetConfigVarFromSections(config, "Interval", new string[] { "ServiceThrottle" }, 5000); - - m_timer = new System.Timers.Timer(); - m_timer.AutoReset = false; - m_timer.Enabled = true; - m_timer.Interval = 15000; // 15 secs at first - m_timer.Elapsed += ProcessQueue; - m_timer.Start(); - - //WorkManager.StartThread( - // ProcessQueue, - // "GridServiceRequestThread", - // ThreadPriority.BelowNormal, - // true, - // false); + m_processorJobEngine = new JobEngine( + "ServiceThrottle","ServiceThrottle"); + m_processorJobEngine.RequestProcessTimeoutOnStop = 31000; // many webrequests have 30s expire + m_processorJobEngine.Start(); } public void AddRegion(Scene scene) @@ -82,7 +67,6 @@ namespace OpenSim.Region.CoreModules.Framework m_scenes.Add(scene); scene.RegisterModuleInterface(this); scene.EventManager.OnNewClient += OnNewClient; - scene.EventManager.OnMakeRootAgent += OnMakeRootAgent; } } @@ -105,6 +89,7 @@ namespace OpenSim.Region.CoreModules.Framework public void Close() { + m_processorJobEngine.Stop(); } public string Name @@ -126,38 +111,24 @@ namespace OpenSim.Region.CoreModules.Framework client.OnRegionHandleRequest += OnRegionHandleRequest; } - void OnMakeRootAgent(ScenePresence obj) - { - lock (m_timer) - { - if (!m_timer.Enabled) - { - m_timer.Interval = m_Interval; - m_timer.Enabled = true; - m_timer.Start(); - } - } - } - public void OnRegionHandleRequest(IClientAPI client, UUID regionID) { //m_log.DebugFormat("[SERVICE THROTTLE]: RegionHandleRequest {0}", regionID); - ulong handle = 0; - if (IsLocalRegionHandle(regionID, out handle)) - { - client.SendRegionHandle(regionID, handle); - return; - } - Action action = delegate { + if(!client.IsActive) + return; + GridRegion r = m_scenes[0].GridService.GetRegionByUUID(UUID.Zero, regionID); + if(!client.IsActive) + return; + if (r != null && r.RegionHandle != 0) client.SendRegionHandle(regionID, r.RegionHandle); }; - Enqueue("region", regionID.ToString(), action); + m_processorJobEngine.QueueJob("regionHandle", action, regionID.ToString()); } #endregion Events @@ -166,91 +137,10 @@ namespace OpenSim.Region.CoreModules.Framework public void Enqueue(string category, string itemid, Action continuation) { - lock (m_RequestQueue) - { - if (m_Pending.ContainsKey(category)) - { - if (m_Pending[category].Contains(itemid)) - // Don't enqueue, it's already pending - return; - } - else - m_Pending.Add(category, new List()); - - m_Pending[category].Add(itemid); - - m_RequestQueue.Enqueue(delegate - { - lock (m_RequestQueue) - m_Pending[category].Remove(itemid); - - continuation(); - }); - } + m_processorJobEngine.QueueJob(category, continuation, itemid); } #endregion IServiceThrottleModule - - #region Process Continuation Queue - - private void ProcessQueue(object sender, System.Timers.ElapsedEventArgs e) - { - //m_log.DebugFormat("[YYY]: Process queue with {0} continuations", m_RequestQueue.Count); - - while (m_RequestQueue.Count > 0) - { - Action continuation = null; - lock (m_RequestQueue) - continuation = m_RequestQueue.Dequeue(); - - if (continuation != null) - continuation(); - } - - if (AreThereRootAgents()) - { - lock (m_timer) - { - m_timer.Interval = 1000; // 1 sec - m_timer.Enabled = true; - m_timer.Start(); - } - } - else - lock (m_timer) - m_timer.Enabled = false; - - } - - #endregion Process Continuation Queue - - #region Misc - - private bool IsLocalRegionHandle(UUID regionID, out ulong regionHandle) - { - regionHandle = 0; - foreach (Scene s in m_scenes) - if (s.RegionInfo.RegionID == regionID) - { - regionHandle = s.RegionInfo.RegionHandle; - return true; - } - return false; - } - - private bool AreThereRootAgents() - { - foreach (Scene s in m_scenes) - { - foreach (ScenePresence sp in s.GetScenePresences()) - if (!sp.IsChildAgent) - return true; - } - - return false; - } - - #endregion Misc } } diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs index 72fff2290f..5507526310 100644 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs @@ -206,7 +206,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement } // Not found in cache, queue continuation - m_ServiceThrottle.Enqueue("name", uuid.ToString(), delegate + m_ServiceThrottle.Enqueue("uuidname", uuid.ToString(), delegate { //m_log.DebugFormat("[YYY]: Name request {0}", uuid); @@ -216,9 +216,12 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement // So to avoid clients // (particularly Hypergrid clients) permanently binding "Unknown User" to a given UUID, we will // instead drop the request entirely. + if(!client.IsActive) + return; if (GetUser(uuid, out user)) { - client.SendNameReply(uuid, user.FirstName, user.LastName); + if(client.IsActive) + client.SendNameReply(uuid, user.FirstName, user.LastName); } // else // m_log.DebugFormat(