aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs79
1 files changed, 46 insertions, 33 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
index 4cb551c..1b9010a 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
@@ -47,11 +47,12 @@ 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_longPollRequests = new Queue<PollServiceHttpRequest>(); 50 private static Queue<PollServiceHttpRequest> m_slowRequests = new Queue<PollServiceHttpRequest>();
51 private static Queue<PollServiceHttpRequest> m_retryRequests = new Queue<PollServiceHttpRequest>();
51 52
52 private uint m_WorkerThreadCount = 0; 53 private uint m_WorkerThreadCount = 0;
53 private Thread[] m_workerThreads; 54 private Thread[] m_workerThreads;
54 private Thread m_longPollThread; 55 private Thread m_retrysThread;
55 56
56 private bool m_running = true; 57 private bool m_running = true;
57 private int slowCount = 0; 58 private int slowCount = 0;
@@ -83,9 +84,9 @@ namespace OpenSim.Framework.Servers.HttpServer
83 int.MaxValue); 84 int.MaxValue);
84 } 85 }
85 86
86 m_longPollThread = Watchdog.StartThread( 87 m_retrysThread = Watchdog.StartThread(
87 this.CheckLongPollThreads, 88 this.CheckRetries,
88 string.Format("LongPollServiceWatcherThread:{0}", m_server.Port), 89 string.Format("PollServiceWatcherThread:{0}", m_server.Port),
89 ThreadPriority.Normal, 90 ThreadPriority.Normal,
90 false, 91 false,
91 true, 92 true,
@@ -96,47 +97,48 @@ namespace OpenSim.Framework.Servers.HttpServer
96 private void ReQueueEvent(PollServiceHttpRequest req) 97 private void ReQueueEvent(PollServiceHttpRequest req)
97 { 98 {
98 if (m_running) 99 if (m_running)
99 m_requests.Enqueue(req); 100 {
101 lock (m_retryRequests)
102 m_retryRequests.Enqueue(req);
103 }
100 } 104 }
101 105
102 public void Enqueue(PollServiceHttpRequest req) 106 public void Enqueue(PollServiceHttpRequest req)
103 { 107 {
104 if (m_running) 108 if (m_running)
105 { 109 {
106 if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LongPoll) 110 if (req.PollServiceArgs.Type != PollServiceEventArgs.EventType.Normal)
107 { 111 {
108 lock (m_longPollRequests) 112 m_requests.Enqueue(req);
109 m_longPollRequests.Enqueue(req);
110 } 113 }
111 else 114 else
112 m_requests.Enqueue(req); 115 {
116 lock (m_slowRequests)
117 m_slowRequests.Enqueue(req);
118 }
113 } 119 }
114 } 120 }
115 121
116 private void CheckLongPollThreads() 122 private void CheckRetries()
117 { 123 {
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(1000); 126 Thread.Sleep(100); // let the world move .. back to faster rate
127 Watchdog.UpdateThread(); 127 Watchdog.UpdateThread();
128 128 lock (m_retryRequests)
129 PollServiceHttpRequest req; 129 {
130 lock (m_longPollRequests) 130 while (m_retryRequests.Count > 0 && m_running)
131 m_requests.Enqueue(m_retryRequests.Dequeue());
132 }
133 slowCount++;
134 if (slowCount >= 10)
131 { 135 {
132 while (m_longPollRequests.Count > 0 && m_running) 136 slowCount = 0;
137
138 lock (m_slowRequests)
133 { 139 {
134 req = m_longPollRequests.Dequeue(); 140 while (m_slowRequests.Count > 0 && m_running)
135 if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id) || // there are events in this EQ 141 m_requests.Enqueue(m_slowRequests.Dequeue());
136 (Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) // no events, but timeout
137 m_requests.Enqueue(req);
138 else
139 m_longPollRequests.Enqueue(req);
140 } 142 }
141 } 143 }
142 } 144 }
@@ -151,12 +153,24 @@ namespace OpenSim.Framework.Servers.HttpServer
151 foreach (Thread t in m_workerThreads) 153 foreach (Thread t in m_workerThreads)
152 Watchdog.AbortThread(t.ManagedThreadId); 154 Watchdog.AbortThread(t.ManagedThreadId);
153 155
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
154 PollServiceHttpRequest wreq; 167 PollServiceHttpRequest wreq;
168 m_retryRequests.Clear();
155 169
156 lock (m_longPollRequests) 170 lock (m_slowRequests)
157 { 171 {
158 while (m_longPollRequests.Count > 0 && m_running) 172 while (m_slowRequests.Count > 0 && m_running)
159 m_requests.Enqueue(m_longPollRequests.Dequeue()); 173 m_requests.Enqueue(m_slowRequests.Dequeue());
160 } 174 }
161 175
162 while (m_requests.Count() > 0) 176 while (m_requests.Count() > 0)
@@ -182,7 +196,6 @@ namespace OpenSim.Framework.Servers.HttpServer
182 while (m_running) 196 while (m_running)
183 { 197 {
184 PollServiceHttpRequest req = m_requests.Dequeue(5000); 198 PollServiceHttpRequest req = m_requests.Dequeue(5000);
185 //m_log.WarnFormat("[YYY]: Dequeued {0}", (req == null ? "null" : req.PollServiceArgs.Type.ToString()));
186 199
187 Watchdog.UpdateThread(); 200 Watchdog.UpdateThread();
188 if (req != null) 201 if (req != null)
@@ -196,7 +209,7 @@ namespace OpenSim.Framework.Servers.HttpServer
196 if (responsedata == null) 209 if (responsedata == null)
197 continue; 210 continue;
198 211
199 if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LongPoll) // This is the event queue 212 if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.Normal) // This is the event queue
200 { 213 {
201 try 214 try
202 { 215 {