From c87585ad96e11397841b8c49b968e11f7c276e21 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 24 Jan 2018 03:12:56 +0000 Subject: simplify http bycontext key --- .../Servers/HttpServer/PollServiceHttpRequest.cs | 18 --------------- .../HttpServer/PollServiceRequestManager.cs | 27 ++++++++++++---------- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs index 8ab5808..d5c25b9 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs @@ -130,27 +130,9 @@ namespace OpenSim.Framework.Servers.HttpServer response.OutputStream.Flush(); response.Send(); } -// catch (Exception e) catch { } } } - - class PollServiceHttpRequestComparer : IEqualityComparer - { - public bool Equals(PollServiceHttpRequest b1, PollServiceHttpRequest b2) - { - if (b1.contextHash != b2.contextHash) - return false; -// bool b = Object.ReferenceEquals(b1.HttpContext, b2.HttpContext); -// return b; - return true; - } - - public int GetHashCode(PollServiceHttpRequest b2) - { - return (int)b2.contextHash; - } - } } \ No newline at end of file diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index db445fa..a2f6a11 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -43,7 +43,7 @@ namespace OpenSim.Framework.Servers.HttpServer private readonly BaseHttpServer m_server; - private Dictionary> m_bycontext; + private Dictionary> m_bycontext; private BlockingCollection m_requests = new BlockingCollection(); private static ConcurrentQueue m_retryRequests = new ConcurrentQueue(); @@ -62,8 +62,7 @@ namespace OpenSim.Framework.Servers.HttpServer m_WorkerThreadCount = pWorkerThreadCount; m_workerThreads = new Thread[m_WorkerThreadCount]; - PollServiceHttpRequestComparer preqCp = new PollServiceHttpRequestComparer(); - m_bycontext = new Dictionary>(preqCp); + m_bycontext = new Dictionary>(256); STPStartInfo startInfo = new STPStartInfo(); startInfo.IdleTimeout = 30000; @@ -102,8 +101,6 @@ namespace OpenSim.Framework.Servers.HttpServer true, null, 1000 * 60 * 10); - - } private void ReQueueEvent(PollServiceHttpRequest req) @@ -114,17 +111,18 @@ namespace OpenSim.Framework.Servers.HttpServer public void Enqueue(PollServiceHttpRequest req) { + Queue ctxQeueue; + int rhash = req.contextHash; lock (m_bycontext) { - Queue ctxQeueue; - if (m_bycontext.TryGetValue(req, out ctxQeueue)) + if (m_bycontext.TryGetValue(rhash, out ctxQeueue)) { ctxQeueue.Enqueue(req); } else { ctxQeueue = new Queue(); - m_bycontext[req] = ctxQeueue; + m_bycontext[rhash] = ctxQeueue; EnqueueInt(req); } } @@ -133,9 +131,10 @@ namespace OpenSim.Framework.Servers.HttpServer public void byContextDequeue(PollServiceHttpRequest req) { Queue ctxQeueue; + int rhash = req.contextHash; lock (m_bycontext) { - if (m_bycontext.TryGetValue(req, out ctxQeueue)) + if (m_bycontext.TryGetValue(rhash, out ctxQeueue)) { if (ctxQeueue.Count > 0) { @@ -144,7 +143,7 @@ namespace OpenSim.Framework.Servers.HttpServer } else { - m_bycontext.Remove(req); + m_bycontext.Remove(rhash); } } } @@ -153,12 +152,13 @@ namespace OpenSim.Framework.Servers.HttpServer public void DropByContext(PollServiceHttpRequest req) { Queue ctxQeueue; + int rhash = req.contextHash; lock (m_bycontext) { - if (m_bycontext.TryGetValue(req, out ctxQeueue)) + if (m_bycontext.TryGetValue(rhash, out ctxQeueue)) { ctxQeueue.Clear(); - m_bycontext.Remove(req); + m_bycontext.Remove(rhash); } } } @@ -228,6 +228,7 @@ namespace OpenSim.Framework.Servers.HttpServer PollServiceHttpRequest req; while (m_running) { + req = null; if(!m_requests.TryTake(out req, 4500) || req == null) { Watchdog.UpdateThread(); @@ -271,6 +272,7 @@ namespace OpenSim.Framework.Servers.HttpServer finally { byContextDequeue(nreq); + nreq = null; } return null; }, null); @@ -291,6 +293,7 @@ namespace OpenSim.Framework.Servers.HttpServer finally { byContextDequeue(nreq); + nreq = null; } return null; }, null); -- cgit v1.1