aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/HttpServer
diff options
context:
space:
mode:
authorUbitUmarov2015-08-18 21:03:34 +0100
committerUbitUmarov2015-08-18 21:03:34 +0100
commit2cac56340a079fad8a16736778b6ebef78fb6d56 (patch)
tree90cb9963be59cf802d97961abff1dfddaea2a3bd /OpenSim/Framework/Servers/HttpServer
parentTrack selected objects per client (diff)
downloadopensim-SC-2cac56340a079fad8a16736778b6ebef78fb6d56.zip
opensim-SC-2cac56340a079fad8a16736778b6ebef78fb6d56.tar.gz
opensim-SC-2cac56340a079fad8a16736778b6ebef78fb6d56.tar.bz2
opensim-SC-2cac56340a079fad8a16736778b6ebef78fb6d56.tar.xz
try to serialize http requests from same connection, so they are processed
in order. ( next commits will be about necessary keepAlive changes needed)
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs38
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs46
2 files changed, 84 insertions, 0 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs
index 6aa9479..e636c38 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic;
30using System.Reflection; 31using System.Reflection;
31using System.Text; 32using System.Text;
32using HttpServer; 33using HttpServer;
@@ -44,6 +45,24 @@ namespace OpenSim.Framework.Servers.HttpServer
44 public readonly IHttpRequest Request; 45 public readonly IHttpRequest Request;
45 public readonly int RequestTime; 46 public readonly int RequestTime;
46 public readonly UUID RequestID; 47 public readonly UUID RequestID;
48 public int contextHash;
49
50 private void GenContextHash()
51 {
52 Random rnd = new Random();
53 contextHash = 0;
54 if (Request.Headers["remote_addr"] != null)
55 contextHash = (Request.Headers["remote_addr"]).GetHashCode() << 16;
56 else
57 contextHash = rnd.Next() << 16;
58 if (Request.Headers["remote_port"] != null)
59 {
60 string[] strPorts = Request.Headers["remote_port"].Split(new char[] { ',' });
61 contextHash += Int32.Parse(strPorts[0]);
62 }
63 else
64 contextHash += rnd.Next() & 0xffff;
65 }
47 66
48 public PollServiceHttpRequest( 67 public PollServiceHttpRequest(
49 PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest) 68 PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest)
@@ -53,6 +72,7 @@ namespace OpenSim.Framework.Servers.HttpServer
53 Request = pRequest; 72 Request = pRequest;
54 RequestTime = System.Environment.TickCount; 73 RequestTime = System.Environment.TickCount;
55 RequestID = UUID.Random(); 74 RequestID = UUID.Random();
75 GenContextHash();
56 } 76 }
57 77
58 internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata) 78 internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata)
@@ -65,6 +85,7 @@ namespace OpenSim.Framework.Servers.HttpServer
65 response.SendChunked = false; 85 response.SendChunked = false;
66 response.ContentLength64 = buffer.Length; 86 response.ContentLength64 = buffer.Length;
67 response.ContentEncoding = Encoding.UTF8; 87 response.ContentEncoding = Encoding.UTF8;
88 response.ReuseContext = false;
68 89
69 try 90 try
70 { 91 {
@@ -93,5 +114,22 @@ namespace OpenSim.Framework.Servers.HttpServer
93 PollServiceArgs.RequestsHandled++; 114 PollServiceArgs.RequestsHandled++;
94 } 115 }
95 } 116 }
117
118 }
119
120 class PollServiceHttpRequestComparer : IEqualityComparer<PollServiceHttpRequest>
121 {
122 public bool Equals(PollServiceHttpRequest b1, PollServiceHttpRequest b2)
123 {
124 if (b1.contextHash != b2.contextHash)
125 return false;
126 bool b = Object.ReferenceEquals(b1.HttpContext, b2.HttpContext);
127 return b;
128 }
129
130 public int GetHashCode(PollServiceHttpRequest b2)
131 {
132 return (int)b2.contextHash;
133 }
96 } 134 }
97} \ No newline at end of file 135} \ No newline at end of file
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
index e75b705..2c5c41d 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
@@ -46,6 +46,7 @@ namespace OpenSim.Framework.Servers.HttpServer
46 46
47 private readonly BaseHttpServer m_server; 47 private readonly BaseHttpServer m_server;
48 48
49 private Dictionary<PollServiceHttpRequest, Queue<PollServiceHttpRequest>> m_bycontext;
49 private BlockingQueue<PollServiceHttpRequest> m_requests = new BlockingQueue<PollServiceHttpRequest>(); 50 private BlockingQueue<PollServiceHttpRequest> m_requests = new BlockingQueue<PollServiceHttpRequest>();
50 private static Queue<PollServiceHttpRequest> m_slowRequests = new Queue<PollServiceHttpRequest>(); 51 private static Queue<PollServiceHttpRequest> m_slowRequests = new Queue<PollServiceHttpRequest>();
51 private static Queue<PollServiceHttpRequest> m_retryRequests = new Queue<PollServiceHttpRequest>(); 52 private static Queue<PollServiceHttpRequest> m_retryRequests = new Queue<PollServiceHttpRequest>();
@@ -65,6 +66,9 @@ namespace OpenSim.Framework.Servers.HttpServer
65 m_WorkerThreadCount = pWorkerThreadCount; 66 m_WorkerThreadCount = pWorkerThreadCount;
66 m_workerThreads = new Thread[m_WorkerThreadCount]; 67 m_workerThreads = new Thread[m_WorkerThreadCount];
67 68
69 PollServiceHttpRequestComparer preqCp = new PollServiceHttpRequestComparer();
70 m_bycontext = new Dictionary<PollServiceHttpRequest, Queue<PollServiceHttpRequest>>(preqCp);
71
68 STPStartInfo startInfo = new STPStartInfo(); 72 STPStartInfo startInfo = new STPStartInfo();
69 startInfo.IdleTimeout = 30000; 73 startInfo.IdleTimeout = 30000;
70 startInfo.MaxWorkerThreads = 15; 74 startInfo.MaxWorkerThreads = 15;
@@ -114,6 +118,45 @@ namespace OpenSim.Framework.Servers.HttpServer
114 118
115 public void Enqueue(PollServiceHttpRequest req) 119 public void Enqueue(PollServiceHttpRequest req)
116 { 120 {
121 lock (m_bycontext)
122 {
123 Queue<PollServiceHttpRequest> ctxQeueue;
124 if (m_bycontext.TryGetValue(req, out ctxQeueue))
125 {
126 ctxQeueue.Enqueue(req);
127 }
128 else
129 {
130 ctxQeueue = new Queue<PollServiceHttpRequest>();
131 m_bycontext[req] = ctxQeueue;
132 EnqueueInt(req);
133 }
134 }
135 }
136
137 public void byContextDequeue(PollServiceHttpRequest req)
138 {
139 Queue<PollServiceHttpRequest> ctxQeueue;
140 lock (m_bycontext)
141 {
142 if (m_bycontext.TryGetValue(req, out ctxQeueue))
143 {
144 if (ctxQeueue.Count > 0)
145 {
146 PollServiceHttpRequest newreq = ctxQeueue.Dequeue();
147 EnqueueInt(newreq);
148 }
149 else
150 {
151 m_bycontext.Remove(req);
152 }
153 }
154 }
155 }
156
157
158 public void EnqueueInt(PollServiceHttpRequest req)
159 {
117 if (m_running) 160 if (m_running)
118 { 161 {
119 if (req.PollServiceArgs.Type != PollServiceEventArgs.EventType.LongPoll) 162 if (req.PollServiceArgs.Type != PollServiceEventArgs.EventType.LongPoll)
@@ -220,6 +263,7 @@ namespace OpenSim.Framework.Servers.HttpServer
220 try 263 try
221 { 264 {
222 req.DoHTTPGruntWork(m_server, responsedata); 265 req.DoHTTPGruntWork(m_server, responsedata);
266 byContextDequeue(req);
223 } 267 }
224 catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream 268 catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream
225 { 269 {
@@ -233,6 +277,7 @@ namespace OpenSim.Framework.Servers.HttpServer
233 try 277 try
234 { 278 {
235 req.DoHTTPGruntWork(m_server, responsedata); 279 req.DoHTTPGruntWork(m_server, responsedata);
280 byContextDequeue(req);
236 } 281 }
237 catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream 282 catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream
238 { 283 {
@@ -249,6 +294,7 @@ namespace OpenSim.Framework.Servers.HttpServer
249 { 294 {
250 req.DoHTTPGruntWork(m_server, 295 req.DoHTTPGruntWork(m_server,
251 req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); 296 req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id));
297 byContextDequeue(req);
252 } 298 }
253 else 299 else
254 { 300 {