reduce httppipeline depth
parent
3989dbac31
commit
29f59fe407
|
@ -79,8 +79,11 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
{
|
{
|
||||||
RequestCookies cookies = _request.Cookies;
|
RequestCookies cookies = _request.Cookies;
|
||||||
HttpCookieCollection httpCookies = new HttpCookieCollection();
|
HttpCookieCollection httpCookies = new HttpCookieCollection();
|
||||||
foreach (RequestCookie cookie in cookies)
|
if(cookies != null)
|
||||||
httpCookies.Add(new HttpCookie(cookie.Name, cookie.Value));
|
{
|
||||||
|
foreach (RequestCookie cookie in cookies)
|
||||||
|
httpCookies.Add(new HttpCookie(cookie.Name, cookie.Value));
|
||||||
|
}
|
||||||
return httpCookies;
|
return httpCookies;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace OSHttpServer
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class HttpClientContext : IHttpClientContext, IDisposable
|
public class HttpClientContext : IHttpClientContext, IDisposable
|
||||||
{
|
{
|
||||||
const int MAXREQUESTS = 20;
|
const int MAXPIPEREQUESTS = 5;
|
||||||
const int MAXKEEPALIVE = 60000;
|
const int MAXKEEPALIVE = 60000;
|
||||||
|
|
||||||
static private int basecontextID;
|
static private int basecontextID;
|
||||||
|
@ -47,7 +47,7 @@ namespace OSHttpServer
|
||||||
public int m_TimeoutKeepAlive = MAXKEEPALIVE; // 400 seconds before keepalive timeout
|
public int m_TimeoutKeepAlive = MAXKEEPALIVE; // 400 seconds before keepalive timeout
|
||||||
// public int TimeoutKeepAlive = 120000; // 400 seconds before keepalive timeout
|
// public int TimeoutKeepAlive = 120000; // 400 seconds before keepalive timeout
|
||||||
|
|
||||||
public int m_maxRequests = MAXREQUESTS;
|
public int m_maxPipeRequests = MAXPIPEREQUESTS;
|
||||||
|
|
||||||
public bool FirstRequestLineReceived;
|
public bool FirstRequestLineReceived;
|
||||||
public bool FullRequestReceived;
|
public bool FullRequestReceived;
|
||||||
|
@ -68,12 +68,15 @@ namespace OSHttpServer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int MAXRequests
|
public int MaxPipeRequests
|
||||||
{
|
{
|
||||||
get { return m_maxRequests; }
|
get { return m_maxPipeRequests; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
m_maxRequests = value > MAXREQUESTS ? MAXREQUESTS : value;
|
if(value <= 1)
|
||||||
|
m_maxPipeRequests = 1;
|
||||||
|
else
|
||||||
|
m_maxPipeRequests = value > MAXPIPEREQUESTS ? MAXPIPEREQUESTS : value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,6 +357,9 @@ namespace OSHttpServer
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(m_maxPipeRequests <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
m_ReceiveBytesLeft += bytesRead;
|
m_ReceiveBytesLeft += bytesRead;
|
||||||
if (m_ReceiveBytesLeft > m_ReceiveBuffer.Length)
|
if (m_ReceiveBytesLeft > m_ReceiveBuffer.Length)
|
||||||
{
|
{
|
||||||
|
@ -531,28 +537,29 @@ namespace OSHttpServer
|
||||||
{
|
{
|
||||||
TriggerKeepalive = false;
|
TriggerKeepalive = false;
|
||||||
MonitorKeepaliveMS = 0;
|
MonitorKeepaliveMS = 0;
|
||||||
|
FullRequestReceived = true;
|
||||||
|
|
||||||
|
if (m_maxPipeRequests == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(--m_maxPipeRequests == 0)
|
||||||
|
m_currentRequest.Connection = ConnectionType.Close;
|
||||||
|
|
||||||
// load cookies if they exist
|
// load cookies if they exist
|
||||||
|
if(m_currentRequest.Headers["cookie"] != null)
|
||||||
RequestCookies cookies = m_currentRequest.Headers["cookie"] != null
|
m_currentRequest.SetCookies(new RequestCookies(m_currentRequest.Headers["cookie"]));
|
||||||
? new RequestCookies(m_currentRequest.Headers["cookie"]) : new RequestCookies(String.Empty);
|
|
||||||
m_currentRequest.SetCookies(cookies);
|
|
||||||
|
|
||||||
m_currentRequest.Body.Seek(0, SeekOrigin.Begin);
|
m_currentRequest.Body.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
FullRequestReceived = true;
|
|
||||||
|
|
||||||
int nreqs;
|
int nreqs;
|
||||||
lock (requestsInServiceIDs)
|
lock (requestsInServiceIDs)
|
||||||
{
|
{
|
||||||
nreqs = requestsInServiceIDs.Count;
|
nreqs = requestsInServiceIDs.Count;
|
||||||
requestsInServiceIDs.Add(m_currentRequest.ID);
|
requestsInServiceIDs.Add(m_currentRequest.ID);
|
||||||
if (m_maxRequests > 0)
|
|
||||||
m_maxRequests--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for now pipeline requests need to be serialized by opensim
|
// for now pipeline requests need to be serialized by opensim
|
||||||
RequestReceived(this, new RequestEventArgs(m_currentRequest));
|
RequestReceived?.Invoke(this, new RequestEventArgs(m_currentRequest));
|
||||||
|
|
||||||
m_currentRequest = new HttpRequest(this);
|
m_currentRequest = new HttpRequest(this);
|
||||||
|
|
||||||
|
@ -610,10 +617,8 @@ namespace OSHttpServer
|
||||||
lock (requestsInServiceIDs)
|
lock (requestsInServiceIDs)
|
||||||
{
|
{
|
||||||
requestsInServiceIDs.Remove(requestID);
|
requestsInServiceIDs.Remove(requestID);
|
||||||
// doclose = doclose && requestsInServiceIDs.Count == 0;
|
|
||||||
if (requestsInServiceIDs.Count > 1)
|
if (requestsInServiceIDs.Count > 1)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -750,11 +755,11 @@ namespace OSHttpServer
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Event can be used to clean up a context, or to reuse it.
|
/// Event can be used to clean up a context, or to reuse it.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public event EventHandler<DisconnectedEventArgs> Disconnected = delegate { };
|
public event EventHandler<DisconnectedEventArgs> Disconnected;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A request have been received in the context.
|
/// A request have been received in the context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<RequestEventArgs> RequestReceived = delegate { };
|
public event EventHandler<RequestEventArgs> RequestReceived;
|
||||||
|
|
||||||
public HTTPNetworkContext GiveMeTheNetworkStreamIKnowWhatImDoing()
|
public HTTPNetworkContext GiveMeTheNetworkStreamIKnowWhatImDoing()
|
||||||
{
|
{
|
||||||
|
|
|
@ -245,9 +245,9 @@ namespace OSHttpServer
|
||||||
sb.Append("Server: OSWebServer\r\n");
|
sb.Append("Server: OSWebServer\r\n");
|
||||||
|
|
||||||
int keepaliveS = m_context.TimeoutKeepAlive / 1000;
|
int keepaliveS = m_context.TimeoutKeepAlive / 1000;
|
||||||
if (Connection == ConnectionType.KeepAlive && keepaliveS > 0 && m_context.MAXRequests > 0)
|
if (Connection == ConnectionType.KeepAlive && keepaliveS > 0 && m_context.MaxPipeRequests > 0)
|
||||||
{
|
{
|
||||||
sb.AppendFormat("Keep-Alive:timeout={0}, max={1}\r\n", keepaliveS, m_context.MAXRequests);
|
sb.AppendFormat("Keep-Alive:timeout={0}, max={1}\r\n", keepaliveS, m_context.MaxPipeRequests);
|
||||||
sb.Append("Connection: Keep-Alive\r\n");
|
sb.Append("Connection: Keep-Alive\r\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -282,7 +282,7 @@ namespace OSHttpServer
|
||||||
if (Sent)
|
if (Sent)
|
||||||
throw new InvalidOperationException("Everything have already been sent.");
|
throw new InvalidOperationException("Everything have already been sent.");
|
||||||
|
|
||||||
if (m_context.MAXRequests == 0 || m_keepAlive == 0)
|
if (m_context.MaxPipeRequests == 0 || m_keepAlive == 0)
|
||||||
{
|
{
|
||||||
Connection = ConnectionType.Close;
|
Connection = ConnectionType.Close;
|
||||||
m_context.TimeoutKeepAlive = 0;
|
m_context.TimeoutKeepAlive = 0;
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace OSHttpServer
|
||||||
|
|
||||||
int contextID {get;}
|
int contextID {get;}
|
||||||
int TimeoutKeepAlive {get; set; }
|
int TimeoutKeepAlive {get; set; }
|
||||||
int MAXRequests{get; set; }
|
int MaxPipeRequests{get; set; }
|
||||||
|
|
||||||
bool CanSend();
|
bool CanSend();
|
||||||
bool IsSending();
|
bool IsSending();
|
||||||
|
|
Loading…
Reference in New Issue