diff options
author | Dan Lake | 2013-07-17 15:06:25 -0700 |
---|---|---|
committer | Dan Lake | 2013-07-17 15:06:25 -0700 |
commit | 49b3b7ee832bfd71d736773e7499158b068c3cae (patch) | |
tree | 5ba499399e8a00e8aebfb136203821ce17eebe0e /OpenSim/Framework | |
parent | command line kick user now uses exact name match instead of substring search ... (diff) | |
parent | This is a completely unreasonable thing to do, effectively defying the purpos... (diff) | |
download | opensim-SC-49b3b7ee832bfd71d736773e7499158b068c3cae.zip opensim-SC-49b3b7ee832bfd71d736773e7499158b068c3cae.tar.gz opensim-SC-49b3b7ee832bfd71d736773e7499158b068c3cae.tar.bz2 opensim-SC-49b3b7ee832bfd71d736773e7499158b068c3cae.tar.xz |
Merge branch 'master' of git://opensimulator.org/git/opensim
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r-- | OpenSim/Framework/BlockingQueue.cs | 5 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs | 4 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | 167 |
3 files changed, 90 insertions, 86 deletions
diff --git a/OpenSim/Framework/BlockingQueue.cs b/OpenSim/Framework/BlockingQueue.cs index aef1192..3e90fac 100644 --- a/OpenSim/Framework/BlockingQueue.cs +++ b/OpenSim/Framework/BlockingQueue.cs | |||
@@ -76,9 +76,10 @@ namespace OpenSim.Framework | |||
76 | { | 76 | { |
77 | lock (m_queueSync) | 77 | lock (m_queueSync) |
78 | { | 78 | { |
79 | if (m_queue.Count < 1 && m_pqueue.Count < 1) | 79 | bool success = true; |
80 | while (m_queue.Count < 1 && m_pqueue.Count < 1 && success) | ||
80 | { | 81 | { |
81 | Monitor.Wait(m_queueSync, msTimeout); | 82 | success = Monitor.Wait(m_queueSync, msTimeout); |
82 | } | 83 | } |
83 | 84 | ||
84 | if (m_pqueue.Count > 0) | 85 | if (m_pqueue.Count > 0) |
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs index 020bfd5..9477100 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs | |||
@@ -50,7 +50,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
50 | 50 | ||
51 | public enum EventType : int | 51 | public enum EventType : int |
52 | { | 52 | { |
53 | Normal = 0, | 53 | LongPoll = 0, |
54 | LslHttp = 1, | 54 | LslHttp = 1, |
55 | Inventory = 2 | 55 | Inventory = 2 |
56 | } | 56 | } |
@@ -80,7 +80,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
80 | NoEvents = pNoEvents; | 80 | NoEvents = pNoEvents; |
81 | Id = pId; | 81 | Id = pId; |
82 | TimeOutms = pTimeOutms; | 82 | TimeOutms = pTimeOutms; |
83 | Type = EventType.Normal; | 83 | Type = EventType.LongPoll; |
84 | } | 84 | } |
85 | } | 85 | } |
86 | } | 86 | } |
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 1b9010a..b8f5743 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | |||
@@ -47,12 +47,11 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
47 | private readonly BaseHttpServer m_server; | 47 | private readonly BaseHttpServer m_server; |
48 | 48 | ||
49 | private BlockingQueue<PollServiceHttpRequest> m_requests = new BlockingQueue<PollServiceHttpRequest>(); | 49 | private BlockingQueue<PollServiceHttpRequest> m_requests = new BlockingQueue<PollServiceHttpRequest>(); |
50 | private static Queue<PollServiceHttpRequest> m_slowRequests = new Queue<PollServiceHttpRequest>(); | 50 | private static Queue<PollServiceHttpRequest> m_longPollRequests = new Queue<PollServiceHttpRequest>(); |
51 | private static Queue<PollServiceHttpRequest> m_retryRequests = new Queue<PollServiceHttpRequest>(); | ||
52 | 51 | ||
53 | private uint m_WorkerThreadCount = 0; | 52 | private uint m_WorkerThreadCount = 0; |
54 | private Thread[] m_workerThreads; | 53 | private Thread[] m_workerThreads; |
55 | private Thread m_retrysThread; | 54 | private Thread m_longPollThread; |
56 | 55 | ||
57 | private bool m_running = true; | 56 | private bool m_running = true; |
58 | private int slowCount = 0; | 57 | private int slowCount = 0; |
@@ -84,9 +83,9 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
84 | int.MaxValue); | 83 | int.MaxValue); |
85 | } | 84 | } |
86 | 85 | ||
87 | m_retrysThread = Watchdog.StartThread( | 86 | m_longPollThread = Watchdog.StartThread( |
88 | this.CheckRetries, | 87 | this.CheckLongPollThreads, |
89 | string.Format("PollServiceWatcherThread:{0}", m_server.Port), | 88 | string.Format("LongPollServiceWatcherThread:{0}", m_server.Port), |
90 | ThreadPriority.Normal, | 89 | ThreadPriority.Normal, |
91 | false, | 90 | false, |
92 | true, | 91 | true, |
@@ -97,49 +96,52 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
97 | private void ReQueueEvent(PollServiceHttpRequest req) | 96 | private void ReQueueEvent(PollServiceHttpRequest req) |
98 | { | 97 | { |
99 | if (m_running) | 98 | if (m_running) |
100 | { | 99 | m_requests.Enqueue(req); |
101 | lock (m_retryRequests) | ||
102 | m_retryRequests.Enqueue(req); | ||
103 | } | ||
104 | } | 100 | } |
105 | 101 | ||
106 | public void Enqueue(PollServiceHttpRequest req) | 102 | public void Enqueue(PollServiceHttpRequest req) |
107 | { | 103 | { |
108 | if (m_running) | 104 | if (m_running) |
109 | { | 105 | { |
110 | if (req.PollServiceArgs.Type != PollServiceEventArgs.EventType.Normal) | 106 | if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LongPoll) |
111 | { | 107 | { |
112 | m_requests.Enqueue(req); | 108 | lock (m_longPollRequests) |
109 | m_longPollRequests.Enqueue(req); | ||
113 | } | 110 | } |
114 | else | 111 | else |
115 | { | 112 | m_requests.Enqueue(req); |
116 | lock (m_slowRequests) | ||
117 | m_slowRequests.Enqueue(req); | ||
118 | } | ||
119 | } | 113 | } |
120 | } | 114 | } |
121 | 115 | ||
122 | private void CheckRetries() | 116 | private void CheckLongPollThreads() |
123 | { | 117 | { |
118 | // The only purpose of this thread is to check the EQs for events. | ||
119 | // If there are events, that thread will be placed in the "ready-to-serve" queue, m_requests. | ||
120 | // If there are no events, that thread will be back to its "waiting" queue, m_longPollRequests. | ||
121 | // All other types of tasks (Inventory handlers) don't have the long-poll nature, | ||
122 | // so if they aren't ready to be served by a worker thread (no events), they are placed | ||
123 | // directly back in the "ready-to-serve" queue by the worker thread. | ||
124 | while (m_running) | 124 | while (m_running) |
125 | { | 125 | { |
126 | Thread.Sleep(100); // let the world move .. back to faster rate | 126 | Thread.Sleep(1000); |
127 | Watchdog.UpdateThread(); | 127 | Watchdog.UpdateThread(); |
128 | lock (m_retryRequests) | ||
129 | { | ||
130 | while (m_retryRequests.Count > 0 && m_running) | ||
131 | m_requests.Enqueue(m_retryRequests.Dequeue()); | ||
132 | } | ||
133 | slowCount++; | ||
134 | if (slowCount >= 10) | ||
135 | { | ||
136 | slowCount = 0; | ||
137 | 128 | ||
138 | lock (m_slowRequests) | 129 | List<PollServiceHttpRequest> not_ready = new List<PollServiceHttpRequest>(); |
130 | lock (m_longPollRequests) | ||
131 | { | ||
132 | while (m_longPollRequests.Count > 0 && m_running) | ||
139 | { | 133 | { |
140 | while (m_slowRequests.Count > 0 && m_running) | 134 | PollServiceHttpRequest req = m_longPollRequests.Dequeue(); |
141 | m_requests.Enqueue(m_slowRequests.Dequeue()); | 135 | if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id) || // there are events in this EQ |
136 | (Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) // no events, but timeout | ||
137 | m_requests.Enqueue(req); | ||
138 | else | ||
139 | not_ready.Add(req); | ||
142 | } | 140 | } |
141 | |||
142 | foreach (PollServiceHttpRequest req in not_ready) | ||
143 | m_longPollRequests.Enqueue(req); | ||
144 | |||
143 | } | 145 | } |
144 | } | 146 | } |
145 | } | 147 | } |
@@ -153,24 +155,12 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
153 | foreach (Thread t in m_workerThreads) | 155 | foreach (Thread t in m_workerThreads) |
154 | Watchdog.AbortThread(t.ManagedThreadId); | 156 | Watchdog.AbortThread(t.ManagedThreadId); |
155 | 157 | ||
156 | try | ||
157 | { | ||
158 | foreach (PollServiceHttpRequest req in m_retryRequests) | ||
159 | { | ||
160 | req.DoHTTPGruntWork(m_server, req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); | ||
161 | } | ||
162 | } | ||
163 | catch | ||
164 | { | ||
165 | } | ||
166 | |||
167 | PollServiceHttpRequest wreq; | 158 | PollServiceHttpRequest wreq; |
168 | m_retryRequests.Clear(); | ||
169 | 159 | ||
170 | lock (m_slowRequests) | 160 | lock (m_longPollRequests) |
171 | { | 161 | { |
172 | while (m_slowRequests.Count > 0 && m_running) | 162 | while (m_longPollRequests.Count > 0 && m_running) |
173 | m_requests.Enqueue(m_slowRequests.Dequeue()); | 163 | m_requests.Enqueue(m_longPollRequests.Dequeue()); |
174 | } | 164 | } |
175 | 165 | ||
176 | while (m_requests.Count() > 0) | 166 | while (m_requests.Count() > 0) |
@@ -195,34 +185,33 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
195 | { | 185 | { |
196 | while (m_running) | 186 | while (m_running) |
197 | { | 187 | { |
198 | PollServiceHttpRequest req = m_requests.Dequeue(5000); | ||
199 | |||
200 | Watchdog.UpdateThread(); | 188 | Watchdog.UpdateThread(); |
201 | if (req != null) | 189 | |
190 | PollServiceHttpRequest req = null; | ||
191 | lock (m_requests) | ||
192 | { | ||
193 | if (m_requests.Count() > 0) | ||
194 | req = m_requests.Dequeue(); | ||
195 | } | ||
196 | if (req == null) | ||
197 | Thread.Sleep(100); | ||
198 | else | ||
202 | { | 199 | { |
203 | try | 200 | //PollServiceHttpRequest req = m_requests.Dequeue(5000); |
201 | //m_log.WarnFormat("[YYY]: Dequeued {0}", (req == null ? "null" : req.PollServiceArgs.Type.ToString())); | ||
202 | |||
203 | if (req != null) | ||
204 | { | 204 | { |
205 | if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id)) | 205 | try |
206 | { | 206 | { |
207 | Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id); | 207 | if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id)) |
208 | { | ||
209 | Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id); | ||
208 | 210 | ||
209 | if (responsedata == null) | 211 | if (responsedata == null) |
210 | continue; | 212 | continue; |
211 | 213 | ||
212 | if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.Normal) // This is the event queue | 214 | if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LongPoll) // This is the event queue |
213 | { | ||
214 | try | ||
215 | { | ||
216 | req.DoHTTPGruntWork(m_server, responsedata); | ||
217 | } | ||
218 | catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream | ||
219 | { | ||
220 | // Ignore it, no need to reply | ||
221 | } | ||
222 | } | ||
223 | else | ||
224 | { | ||
225 | m_threadPool.QueueWorkItem(x => | ||
226 | { | 215 | { |
227 | try | 216 | try |
228 | { | 217 | { |
@@ -232,27 +221,41 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
232 | { | 221 | { |
233 | // Ignore it, no need to reply | 222 | // Ignore it, no need to reply |
234 | } | 223 | } |
224 | } | ||
225 | else | ||
226 | { | ||
227 | m_threadPool.QueueWorkItem(x => | ||
228 | { | ||
229 | try | ||
230 | { | ||
231 | req.DoHTTPGruntWork(m_server, responsedata); | ||
232 | } | ||
233 | catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream | ||
234 | { | ||
235 | // Ignore it, no need to reply | ||
236 | } | ||
235 | 237 | ||
236 | return null; | 238 | return null; |
237 | }, null); | 239 | }, null); |
238 | } | 240 | } |
239 | } | ||
240 | else | ||
241 | { | ||
242 | if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) | ||
243 | { | ||
244 | req.DoHTTPGruntWork( | ||
245 | m_server, req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); | ||
246 | } | 241 | } |
247 | else | 242 | else |
248 | { | 243 | { |
249 | ReQueueEvent(req); | 244 | if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) |
245 | { | ||
246 | req.DoHTTPGruntWork( | ||
247 | m_server, req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); | ||
248 | } | ||
249 | else | ||
250 | { | ||
251 | ReQueueEvent(req); | ||
252 | } | ||
250 | } | 253 | } |
251 | } | 254 | } |
252 | } | 255 | catch (Exception e) |
253 | catch (Exception e) | 256 | { |
254 | { | 257 | m_log.ErrorFormat("Exception in poll service thread: " + e.ToString()); |
255 | m_log.ErrorFormat("Exception in poll service thread: " + e.ToString()); | 258 | } |
256 | } | 259 | } |
257 | } | 260 | } |
258 | } | 261 | } |