From edafea6ae6dd3617520d989fb2fe748e3f0de1b3 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 19 Jul 2013 13:17:15 -0700 Subject: PollServiceRequestManager: changed the long poll from a Queue to a List. No need to dequeue and enqueue items every 1sec. --- .../HttpServer/PollServiceRequestManager.cs | 30 ++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'OpenSim/Framework/Servers') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 727dbe5..309b71f 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -47,7 +47,7 @@ namespace OpenSim.Framework.Servers.HttpServer private readonly BaseHttpServer m_server; private BlockingQueue m_requests = new BlockingQueue(); - private static Queue m_longPollRequests = new Queue(); + private static List m_longPollRequests = new List(); private uint m_WorkerThreadCount = 0; private Thread[] m_workerThreads; @@ -116,7 +116,7 @@ namespace OpenSim.Framework.Servers.HttpServer if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LongPoll) { lock (m_longPollRequests) - m_longPollRequests.Enqueue(req); + m_longPollRequests.Add(req); } else m_requests.Enqueue(req); @@ -139,18 +139,21 @@ namespace OpenSim.Framework.Servers.HttpServer List not_ready = new List(); lock (m_longPollRequests) { - while (m_longPollRequests.Count > 0 && m_running) + if (m_longPollRequests.Count > 0 && m_running) { - PollServiceHttpRequest req = m_longPollRequests.Dequeue(); - if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id) || // there are events in this EQ + List ready = m_longPollRequests.FindAll(req => + (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id) || // there are events in this EQ (Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) // no events, but timeout - m_requests.Enqueue(req); - else - not_ready.Add(req); - } + ); - foreach (PollServiceHttpRequest req in not_ready) - m_longPollRequests.Enqueue(req); + ready.ForEach(req => + { + m_log.DebugFormat("[YYY]: --> Enqueuing"); + m_requests.Enqueue(req); + m_longPollRequests.Remove(req); + }); + + } } } @@ -169,8 +172,8 @@ namespace OpenSim.Framework.Servers.HttpServer lock (m_longPollRequests) { - while (m_longPollRequests.Count > 0 && m_running) - m_requests.Enqueue(m_longPollRequests.Dequeue()); + if (m_longPollRequests.Count > 0 && m_running) + m_longPollRequests.ForEach(req => m_requests.Enqueue(req)); } while (m_requests.Count() > 0) @@ -186,6 +189,7 @@ namespace OpenSim.Framework.Servers.HttpServer } } + m_longPollRequests.Clear(); m_requests.Clear(); } -- cgit v1.1