diff options
author | UbitUmarov | 2018-01-22 00:24:29 +0000 |
---|---|---|
committer | UbitUmarov | 2018-01-22 00:24:29 +0000 |
commit | 73b587989cf64bee78d3a5a62e96cb4646d71970 (patch) | |
tree | b184cf93db7b9b9d42e73701602ff3f085149abd /OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs | |
parent | give BlockingCollection another chance (diff) | |
download | opensim-SC-73b587989cf64bee78d3a5a62e96cb4646d71970.zip opensim-SC-73b587989cf64bee78d3a5a62e96cb4646d71970.tar.gz opensim-SC-73b587989cf64bee78d3a5a62e96cb4646d71970.tar.bz2 opensim-SC-73b587989cf64bee78d3a5a62e96cb4646d71970.tar.xz |
give BlockingCollection more chances
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs | 69 |
1 files changed, 40 insertions, 29 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs index 9a561ea..736e18f 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs | |||
@@ -28,6 +28,7 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Collections.Concurrent; | ||
31 | using System.Reflection; | 32 | using System.Reflection; |
32 | using System.Threading; | 33 | using System.Threading; |
33 | using log4net; | 34 | using log4net; |
@@ -51,7 +52,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
51 | public class GetTextureModule : INonSharedRegionModule | 52 | public class GetTextureModule : INonSharedRegionModule |
52 | { | 53 | { |
53 | 54 | ||
54 | struct aPollRequest | 55 | class APollRequest |
55 | { | 56 | { |
56 | public PollServiceTextureEventArgs thepoll; | 57 | public PollServiceTextureEventArgs thepoll; |
57 | public UUID reqID; | 58 | public UUID reqID; |
@@ -59,7 +60,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
59 | public bool send503; | 60 | public bool send503; |
60 | } | 61 | } |
61 | 62 | ||
62 | public class aPollResponse | 63 | public class APollResponse |
63 | { | 64 | { |
64 | public Hashtable response; | 65 | public Hashtable response; |
65 | public int bytes; | 66 | public int bytes; |
@@ -77,8 +78,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
77 | private Dictionary<UUID, string> m_capsDict = new Dictionary<UUID, string>(); | 78 | private Dictionary<UUID, string> m_capsDict = new Dictionary<UUID, string>(); |
78 | private static Thread[] m_workerThreads = null; | 79 | private static Thread[] m_workerThreads = null; |
79 | private static int m_NumberScenes = 0; | 80 | private static int m_NumberScenes = 0; |
80 | private static OpenSim.Framework.BlockingQueue<aPollRequest> m_queue = | 81 | private static BlockingCollection<APollRequest> m_queue = new BlockingCollection<APollRequest>(); |
81 | new OpenSim.Framework.BlockingQueue<aPollRequest>(); | ||
82 | 82 | ||
83 | private Dictionary<UUID,PollServiceTextureEventArgs> m_pollservices = new Dictionary<UUID,PollServiceTextureEventArgs>(); | 83 | private Dictionary<UUID,PollServiceTextureEventArgs> m_pollservices = new Dictionary<UUID,PollServiceTextureEventArgs>(); |
84 | 84 | ||
@@ -107,26 +107,29 @@ namespace OpenSim.Region.ClientStack.Linden | |||
107 | public void AddRegion(Scene s) | 107 | public void AddRegion(Scene s) |
108 | { | 108 | { |
109 | m_scene = s; | 109 | m_scene = s; |
110 | m_assetService = s.AssetService; | ||
111 | } | 110 | } |
112 | 111 | ||
113 | public void RemoveRegion(Scene s) | 112 | public void RemoveRegion(Scene s) |
114 | { | 113 | { |
115 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; | 114 | s.EventManager.OnRegisterCaps -= RegisterCaps; |
116 | m_scene.EventManager.OnDeregisterCaps -= DeregisterCaps; | 115 | s.EventManager.OnDeregisterCaps -= DeregisterCaps; |
117 | m_scene.EventManager.OnThrottleUpdate -= ThrottleUpdate; | 116 | s.EventManager.OnThrottleUpdate -= ThrottleUpdate; |
118 | m_NumberScenes--; | 117 | m_NumberScenes--; |
119 | m_scene = null; | 118 | m_scene = null; |
120 | } | 119 | } |
121 | 120 | ||
122 | public void RegionLoaded(Scene s) | 121 | public void RegionLoaded(Scene s) |
123 | { | 122 | { |
124 | // We'll reuse the same handler for all requests. | 123 | if(m_assetService == null) |
125 | m_getTextureHandler = new GetTextureHandler(m_assetService); | 124 | { |
125 | m_assetService = s.RequestModuleInterface<IAssetService>(); | ||
126 | // We'll reuse the same handler for all requests. | ||
127 | m_getTextureHandler = new GetTextureHandler(m_assetService); | ||
128 | } | ||
126 | 129 | ||
127 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; | 130 | s.EventManager.OnRegisterCaps += RegisterCaps; |
128 | m_scene.EventManager.OnDeregisterCaps += DeregisterCaps; | 131 | s.EventManager.OnDeregisterCaps += DeregisterCaps; |
129 | m_scene.EventManager.OnThrottleUpdate += ThrottleUpdate; | 132 | s.EventManager.OnThrottleUpdate += ThrottleUpdate; |
130 | 133 | ||
131 | m_NumberScenes++; | 134 | m_NumberScenes++; |
132 | 135 | ||
@@ -173,7 +176,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
173 | foreach (Thread t in m_workerThreads) | 176 | foreach (Thread t in m_workerThreads) |
174 | Watchdog.AbortThread(t.ManagedThreadId); | 177 | Watchdog.AbortThread(t.ManagedThreadId); |
175 | 178 | ||
176 | m_queue.Clear(); | 179 | m_queue.Dispose(); |
177 | } | 180 | } |
178 | } | 181 | } |
179 | 182 | ||
@@ -190,8 +193,8 @@ namespace OpenSim.Region.ClientStack.Linden | |||
190 | { | 193 | { |
191 | private List<Hashtable> requests = | 194 | private List<Hashtable> requests = |
192 | new List<Hashtable>(); | 195 | new List<Hashtable>(); |
193 | private Dictionary<UUID, aPollResponse> responses = | 196 | private Dictionary<UUID, APollResponse> responses = |
194 | new Dictionary<UUID, aPollResponse>(); | 197 | new Dictionary<UUID, APollResponse>(); |
195 | private HashSet<UUID> dropedResponses = new HashSet<UUID>(); | 198 | private HashSet<UUID> dropedResponses = new HashSet<UUID>(); |
196 | 199 | ||
197 | private Scene m_scene; | 200 | private Scene m_scene; |
@@ -239,7 +242,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
239 | // x is request id, y is request data hashtable | 242 | // x is request id, y is request data hashtable |
240 | Request = (x, y) => | 243 | Request = (x, y) => |
241 | { | 244 | { |
242 | aPollRequest reqinfo = new aPollRequest(); | 245 | APollRequest reqinfo = new APollRequest(); |
243 | reqinfo.thepoll = this; | 246 | reqinfo.thepoll = this; |
244 | reqinfo.reqID = x; | 247 | reqinfo.reqID = x; |
245 | reqinfo.request = y; | 248 | reqinfo.request = y; |
@@ -249,14 +252,14 @@ namespace OpenSim.Region.ClientStack.Linden | |||
249 | { | 252 | { |
250 | if (responses.Count > 0) | 253 | if (responses.Count > 0) |
251 | { | 254 | { |
252 | if (m_queue.Count() >= 4) | 255 | if (m_queue.Count >= 4) |
253 | { | 256 | { |
254 | // Never allow more than 4 fetches to wait | 257 | // Never allow more than 4 fetches to wait |
255 | reqinfo.send503 = true; | 258 | reqinfo.send503 = true; |
256 | } | 259 | } |
257 | } | 260 | } |
258 | } | 261 | } |
259 | m_queue.Enqueue(reqinfo); | 262 | m_queue.Add(reqinfo); |
260 | m_throttler.PassTime(); | 263 | m_throttler.PassTime(); |
261 | }; | 264 | }; |
262 | 265 | ||
@@ -282,7 +285,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
282 | }; | 285 | }; |
283 | } | 286 | } |
284 | 287 | ||
285 | public void Process(aPollRequest requestinfo) | 288 | public void Process(APollRequest requestinfo) |
286 | { | 289 | { |
287 | Hashtable response; | 290 | Hashtable response; |
288 | 291 | ||
@@ -316,7 +319,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
316 | headers["Retry-After"] = 30; | 319 | headers["Retry-After"] = 30; |
317 | response["headers"] = headers; | 320 | response["headers"] = headers; |
318 | 321 | ||
319 | responses[requestID] = new aPollResponse() {bytes = 0, response = response}; | 322 | responses[requestID] = new APollResponse() {bytes = 0, response = response}; |
320 | 323 | ||
321 | return; | 324 | return; |
322 | } | 325 | } |
@@ -332,7 +335,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
332 | response["keepalive"] = false; | 335 | response["keepalive"] = false; |
333 | response["reusecontext"] = false; | 336 | response["reusecontext"] = false; |
334 | 337 | ||
335 | responses[requestID] = new aPollResponse() {bytes = 0, response = response}; | 338 | responses[requestID] = new APollResponse() {bytes = 0, response = response}; |
336 | 339 | ||
337 | return; | 340 | return; |
338 | } | 341 | } |
@@ -351,7 +354,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
351 | return; | 354 | return; |
352 | } | 355 | } |
353 | } | 356 | } |
354 | responses[requestID] = new aPollResponse() | 357 | responses[requestID] = new APollResponse() |
355 | { | 358 | { |
356 | bytes = (int) response["int_bytes"], | 359 | bytes = (int) response["int_bytes"], |
357 | response = response | 360 | response = response |
@@ -420,12 +423,20 @@ namespace OpenSim.Region.ClientStack.Linden | |||
420 | 423 | ||
421 | private static void DoTextureRequests() | 424 | private static void DoTextureRequests() |
422 | { | 425 | { |
423 | while (true) | 426 | APollRequest poolreq; |
427 | while (m_NumberScenes > 0) | ||
424 | { | 428 | { |
425 | aPollRequest poolreq = m_queue.Dequeue(4500); | 429 | poolreq = null; |
426 | Watchdog.UpdateThread(); | 430 | if(!m_queue.TryTake(out poolreq, 4500) || poolreq == null) |
431 | { | ||
432 | Watchdog.UpdateThread(); | ||
433 | continue; | ||
434 | } | ||
435 | |||
427 | if(m_NumberScenes <= 0) | 436 | if(m_NumberScenes <= 0) |
428 | return; | 437 | break; |
438 | |||
439 | Watchdog.UpdateThread(); | ||
429 | if(poolreq.reqID != UUID.Zero) | 440 | if(poolreq.reqID != UUID.Zero) |
430 | poolreq.thepoll.Process(poolreq); | 441 | poolreq.thepoll.Process(poolreq); |
431 | } | 442 | } |
@@ -442,7 +453,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
442 | ThrottleBytes = pBytes; | 453 | ThrottleBytes = pBytes; |
443 | lastTimeElapsed = Util.GetTimeStampMS(); | 454 | lastTimeElapsed = Util.GetTimeStampMS(); |
444 | } | 455 | } |
445 | public bool hasEvents(UUID key, Dictionary<UUID, GetTextureModule.aPollResponse> responses) | 456 | public bool hasEvents(UUID key, Dictionary<UUID, GetTextureModule.APollResponse> responses) |
446 | { | 457 | { |
447 | PassTime(); | 458 | PassTime(); |
448 | // Note, this is called IN LOCK | 459 | // Note, this is called IN LOCK |
@@ -451,7 +462,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
451 | { | 462 | { |
452 | return false; | 463 | return false; |
453 | } | 464 | } |
454 | GetTextureModule.aPollResponse response; | 465 | GetTextureModule.APollResponse response; |
455 | if (responses.TryGetValue(key, out response)) | 466 | if (responses.TryGetValue(key, out response)) |
456 | { | 467 | { |
457 | // This is any error response | 468 | // This is any error response |