simplify http bycontext key

httptests
UbitUmarov 2018-01-24 03:12:56 +00:00
parent 3f7ffc12c4
commit c87585ad96
2 changed files with 15 additions and 30 deletions

View File

@ -130,27 +130,9 @@ namespace OpenSim.Framework.Servers.HttpServer
response.OutputStream.Flush(); response.OutputStream.Flush();
response.Send(); response.Send();
} }
// catch (Exception e)
catch catch
{ {
} }
} }
} }
class PollServiceHttpRequestComparer : IEqualityComparer<PollServiceHttpRequest>
{
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;
}
}
} }

View File

@ -43,7 +43,7 @@ namespace OpenSim.Framework.Servers.HttpServer
private readonly BaseHttpServer m_server; private readonly BaseHttpServer m_server;
private Dictionary<PollServiceHttpRequest, Queue<PollServiceHttpRequest>> m_bycontext; private Dictionary<int, Queue<PollServiceHttpRequest>> m_bycontext;
private BlockingCollection<PollServiceHttpRequest> m_requests = new BlockingCollection<PollServiceHttpRequest>(); private BlockingCollection<PollServiceHttpRequest> m_requests = new BlockingCollection<PollServiceHttpRequest>();
private static ConcurrentQueue<PollServiceHttpRequest> m_retryRequests = new ConcurrentQueue<PollServiceHttpRequest>(); private static ConcurrentQueue<PollServiceHttpRequest> m_retryRequests = new ConcurrentQueue<PollServiceHttpRequest>();
@ -62,8 +62,7 @@ namespace OpenSim.Framework.Servers.HttpServer
m_WorkerThreadCount = pWorkerThreadCount; m_WorkerThreadCount = pWorkerThreadCount;
m_workerThreads = new Thread[m_WorkerThreadCount]; m_workerThreads = new Thread[m_WorkerThreadCount];
PollServiceHttpRequestComparer preqCp = new PollServiceHttpRequestComparer(); m_bycontext = new Dictionary<int, Queue<PollServiceHttpRequest>>(256);
m_bycontext = new Dictionary<PollServiceHttpRequest, Queue<PollServiceHttpRequest>>(preqCp);
STPStartInfo startInfo = new STPStartInfo(); STPStartInfo startInfo = new STPStartInfo();
startInfo.IdleTimeout = 30000; startInfo.IdleTimeout = 30000;
@ -102,8 +101,6 @@ namespace OpenSim.Framework.Servers.HttpServer
true, true,
null, null,
1000 * 60 * 10); 1000 * 60 * 10);
} }
private void ReQueueEvent(PollServiceHttpRequest req) private void ReQueueEvent(PollServiceHttpRequest req)
@ -114,17 +111,18 @@ namespace OpenSim.Framework.Servers.HttpServer
public void Enqueue(PollServiceHttpRequest req) public void Enqueue(PollServiceHttpRequest req)
{ {
Queue<PollServiceHttpRequest> ctxQeueue;
int rhash = req.contextHash;
lock (m_bycontext) lock (m_bycontext)
{ {
Queue<PollServiceHttpRequest> ctxQeueue; if (m_bycontext.TryGetValue(rhash, out ctxQeueue))
if (m_bycontext.TryGetValue(req, out ctxQeueue))
{ {
ctxQeueue.Enqueue(req); ctxQeueue.Enqueue(req);
} }
else else
{ {
ctxQeueue = new Queue<PollServiceHttpRequest>(); ctxQeueue = new Queue<PollServiceHttpRequest>();
m_bycontext[req] = ctxQeueue; m_bycontext[rhash] = ctxQeueue;
EnqueueInt(req); EnqueueInt(req);
} }
} }
@ -133,9 +131,10 @@ namespace OpenSim.Framework.Servers.HttpServer
public void byContextDequeue(PollServiceHttpRequest req) public void byContextDequeue(PollServiceHttpRequest req)
{ {
Queue<PollServiceHttpRequest> ctxQeueue; Queue<PollServiceHttpRequest> ctxQeueue;
int rhash = req.contextHash;
lock (m_bycontext) lock (m_bycontext)
{ {
if (m_bycontext.TryGetValue(req, out ctxQeueue)) if (m_bycontext.TryGetValue(rhash, out ctxQeueue))
{ {
if (ctxQeueue.Count > 0) if (ctxQeueue.Count > 0)
{ {
@ -144,7 +143,7 @@ namespace OpenSim.Framework.Servers.HttpServer
} }
else else
{ {
m_bycontext.Remove(req); m_bycontext.Remove(rhash);
} }
} }
} }
@ -153,12 +152,13 @@ namespace OpenSim.Framework.Servers.HttpServer
public void DropByContext(PollServiceHttpRequest req) public void DropByContext(PollServiceHttpRequest req)
{ {
Queue<PollServiceHttpRequest> ctxQeueue; Queue<PollServiceHttpRequest> ctxQeueue;
int rhash = req.contextHash;
lock (m_bycontext) lock (m_bycontext)
{ {
if (m_bycontext.TryGetValue(req, out ctxQeueue)) if (m_bycontext.TryGetValue(rhash, out ctxQeueue))
{ {
ctxQeueue.Clear(); ctxQeueue.Clear();
m_bycontext.Remove(req); m_bycontext.Remove(rhash);
} }
} }
} }
@ -228,6 +228,7 @@ namespace OpenSim.Framework.Servers.HttpServer
PollServiceHttpRequest req; PollServiceHttpRequest req;
while (m_running) while (m_running)
{ {
req = null;
if(!m_requests.TryTake(out req, 4500) || req == null) if(!m_requests.TryTake(out req, 4500) || req == null)
{ {
Watchdog.UpdateThread(); Watchdog.UpdateThread();
@ -271,6 +272,7 @@ namespace OpenSim.Framework.Servers.HttpServer
finally finally
{ {
byContextDequeue(nreq); byContextDequeue(nreq);
nreq = null;
} }
return null; return null;
}, null); }, null);
@ -291,6 +293,7 @@ namespace OpenSim.Framework.Servers.HttpServer
finally finally
{ {
byContextDequeue(nreq); byContextDequeue(nreq);
nreq = null;
} }
return null; return null;
}, null); }, null);