try to serialize http requests from same connection, so they are processed
in order. ( next commits will be about necessary keepAlive changes needed)avinationmerge
parent
1fb2f0296f
commit
2cac56340a
|
@ -27,6 +27,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using HttpServer;
|
||||
|
@ -44,6 +45,24 @@ namespace OpenSim.Framework.Servers.HttpServer
|
|||
public readonly IHttpRequest Request;
|
||||
public readonly int RequestTime;
|
||||
public readonly UUID RequestID;
|
||||
public int contextHash;
|
||||
|
||||
private void GenContextHash()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
contextHash = 0;
|
||||
if (Request.Headers["remote_addr"] != null)
|
||||
contextHash = (Request.Headers["remote_addr"]).GetHashCode() << 16;
|
||||
else
|
||||
contextHash = rnd.Next() << 16;
|
||||
if (Request.Headers["remote_port"] != null)
|
||||
{
|
||||
string[] strPorts = Request.Headers["remote_port"].Split(new char[] { ',' });
|
||||
contextHash += Int32.Parse(strPorts[0]);
|
||||
}
|
||||
else
|
||||
contextHash += rnd.Next() & 0xffff;
|
||||
}
|
||||
|
||||
public PollServiceHttpRequest(
|
||||
PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest)
|
||||
|
@ -53,6 +72,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
|||
Request = pRequest;
|
||||
RequestTime = System.Environment.TickCount;
|
||||
RequestID = UUID.Random();
|
||||
GenContextHash();
|
||||
}
|
||||
|
||||
internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata)
|
||||
|
@ -65,6 +85,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
|||
response.SendChunked = false;
|
||||
response.ContentLength64 = buffer.Length;
|
||||
response.ContentEncoding = Encoding.UTF8;
|
||||
response.ReuseContext = false;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -93,5 +114,22 @@ namespace OpenSim.Framework.Servers.HttpServer
|
|||
PollServiceArgs.RequestsHandled++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public int GetHashCode(PollServiceHttpRequest b2)
|
||||
{
|
||||
return (int)b2.contextHash;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -46,6 +46,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
|||
|
||||
private readonly BaseHttpServer m_server;
|
||||
|
||||
private Dictionary<PollServiceHttpRequest, Queue<PollServiceHttpRequest>> m_bycontext;
|
||||
private BlockingQueue<PollServiceHttpRequest> m_requests = new BlockingQueue<PollServiceHttpRequest>();
|
||||
private static Queue<PollServiceHttpRequest> m_slowRequests = new Queue<PollServiceHttpRequest>();
|
||||
private static Queue<PollServiceHttpRequest> m_retryRequests = new Queue<PollServiceHttpRequest>();
|
||||
|
@ -65,6 +66,9 @@ namespace OpenSim.Framework.Servers.HttpServer
|
|||
m_WorkerThreadCount = pWorkerThreadCount;
|
||||
m_workerThreads = new Thread[m_WorkerThreadCount];
|
||||
|
||||
PollServiceHttpRequestComparer preqCp = new PollServiceHttpRequestComparer();
|
||||
m_bycontext = new Dictionary<PollServiceHttpRequest, Queue<PollServiceHttpRequest>>(preqCp);
|
||||
|
||||
STPStartInfo startInfo = new STPStartInfo();
|
||||
startInfo.IdleTimeout = 30000;
|
||||
startInfo.MaxWorkerThreads = 15;
|
||||
|
@ -113,6 +117,45 @@ namespace OpenSim.Framework.Servers.HttpServer
|
|||
}
|
||||
|
||||
public void Enqueue(PollServiceHttpRequest req)
|
||||
{
|
||||
lock (m_bycontext)
|
||||
{
|
||||
Queue<PollServiceHttpRequest> ctxQeueue;
|
||||
if (m_bycontext.TryGetValue(req, out ctxQeueue))
|
||||
{
|
||||
ctxQeueue.Enqueue(req);
|
||||
}
|
||||
else
|
||||
{
|
||||
ctxQeueue = new Queue<PollServiceHttpRequest>();
|
||||
m_bycontext[req] = ctxQeueue;
|
||||
EnqueueInt(req);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void byContextDequeue(PollServiceHttpRequest req)
|
||||
{
|
||||
Queue<PollServiceHttpRequest> ctxQeueue;
|
||||
lock (m_bycontext)
|
||||
{
|
||||
if (m_bycontext.TryGetValue(req, out ctxQeueue))
|
||||
{
|
||||
if (ctxQeueue.Count > 0)
|
||||
{
|
||||
PollServiceHttpRequest newreq = ctxQeueue.Dequeue();
|
||||
EnqueueInt(newreq);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bycontext.Remove(req);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void EnqueueInt(PollServiceHttpRequest req)
|
||||
{
|
||||
if (m_running)
|
||||
{
|
||||
|
@ -220,6 +263,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
|||
try
|
||||
{
|
||||
req.DoHTTPGruntWork(m_server, responsedata);
|
||||
byContextDequeue(req);
|
||||
}
|
||||
catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream
|
||||
{
|
||||
|
@ -233,6 +277,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
|||
try
|
||||
{
|
||||
req.DoHTTPGruntWork(m_server, responsedata);
|
||||
byContextDequeue(req);
|
||||
}
|
||||
catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream
|
||||
{
|
||||
|
@ -249,6 +294,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
|||
{
|
||||
req.DoHTTPGruntWork(m_server,
|
||||
req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id));
|
||||
byContextDequeue(req);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue