diff options
author | Melanie | 2013-01-20 18:38:00 +0100 |
---|---|---|
committer | Melanie | 2013-01-20 18:38:00 +0100 |
commit | b7b3063849c8d7299fa0c262e122ff1a050bfdcb (patch) | |
tree | 90c910a0b2421d49a6c52eb80e6c977e7fccd452 | |
parent | Revert "Refactor scripted http request to use async calls rather than hard th... (diff) | |
download | opensim-SC-b7b3063849c8d7299fa0c262e122ff1a050bfdcb.zip opensim-SC-b7b3063849c8d7299fa0c262e122ff1a050bfdcb.tar.gz opensim-SC-b7b3063849c8d7299fa0c262e122ff1a050bfdcb.tar.bz2 opensim-SC-b7b3063849c8d7299fa0c262e122ff1a050bfdcb.tar.xz |
Implement HTTP Request froma thread pool to avoid packet congestion
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs | 59 | ||||
-rw-r--r-- | prebuild.xml | 1 |
2 files changed, 46 insertions, 14 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs index a0ae203..708b99d 100644 --- a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs +++ b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs | |||
@@ -42,6 +42,7 @@ using OpenSim.Framework.Servers.HttpServer; | |||
42 | using OpenSim.Region.Framework.Interfaces; | 42 | using OpenSim.Region.Framework.Interfaces; |
43 | using OpenSim.Region.Framework.Scenes; | 43 | using OpenSim.Region.Framework.Scenes; |
44 | using Mono.Addins; | 44 | using Mono.Addins; |
45 | using Amib.Threading; | ||
45 | 46 | ||
46 | /***************************************************** | 47 | /***************************************************** |
47 | * | 48 | * |
@@ -102,6 +103,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
102 | private Dictionary<UUID, HttpRequestClass> m_pendingRequests; | 103 | private Dictionary<UUID, HttpRequestClass> m_pendingRequests; |
103 | private Scene m_scene; | 104 | private Scene m_scene; |
104 | // private Queue<HttpRequestClass> rpcQueue = new Queue<HttpRequestClass>(); | 105 | // private Queue<HttpRequestClass> rpcQueue = new Queue<HttpRequestClass>(); |
106 | public static SmartThreadPool ThreadPool = null; | ||
105 | 107 | ||
106 | public HttpRequestModule() | 108 | public HttpRequestModule() |
107 | { | 109 | { |
@@ -279,7 +281,30 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
279 | m_proxyurl = config.Configs["Startup"].GetString("HttpProxy"); | 281 | m_proxyurl = config.Configs["Startup"].GetString("HttpProxy"); |
280 | m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions"); | 282 | m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions"); |
281 | 283 | ||
284 | int maxThreads = 50; | ||
285 | |||
286 | IConfig httpConfig = config.Configs["HttpRequestModule"]; | ||
287 | if (httpConfig != null) | ||
288 | { | ||
289 | maxThreads = httpConfig.GetInt("MaxPoolThreads", maxThreads); | ||
290 | } | ||
291 | |||
282 | m_pendingRequests = new Dictionary<UUID, HttpRequestClass>(); | 292 | m_pendingRequests = new Dictionary<UUID, HttpRequestClass>(); |
293 | |||
294 | // First instance sets this up for all sims | ||
295 | if (ThreadPool == null) | ||
296 | { | ||
297 | STPStartInfo startInfo = new STPStartInfo(); | ||
298 | startInfo.IdleTimeout = 20000; | ||
299 | startInfo.MaxWorkerThreads = maxThreads; | ||
300 | startInfo.MinWorkerThreads = 5; | ||
301 | startInfo.ThreadPriority = ThreadPriority.BelowNormal; | ||
302 | startInfo.StartSuspended = true; | ||
303 | |||
304 | ThreadPool = new SmartThreadPool(startInfo); | ||
305 | |||
306 | ThreadPool.Start(); | ||
307 | } | ||
283 | } | 308 | } |
284 | 309 | ||
285 | public void AddRegion(Scene scene) | 310 | public void AddRegion(Scene scene) |
@@ -340,7 +365,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
340 | public string HttpMIMEType = "text/plain;charset=utf-8"; | 365 | public string HttpMIMEType = "text/plain;charset=utf-8"; |
341 | public int HttpTimeout; | 366 | public int HttpTimeout; |
342 | public bool HttpVerifyCert = true; | 367 | public bool HttpVerifyCert = true; |
343 | private Thread httpThread; | 368 | public IWorkItemResult WorkItem = null; |
344 | 369 | ||
345 | // Request info | 370 | // Request info |
346 | private UUID _itemID; | 371 | private UUID _itemID; |
@@ -374,12 +399,16 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
374 | 399 | ||
375 | public void Process() | 400 | public void Process() |
376 | { | 401 | { |
377 | httpThread = new Thread(SendRequest); | ||
378 | httpThread.Name = "HttpRequestThread"; | ||
379 | httpThread.Priority = ThreadPriority.BelowNormal; | ||
380 | httpThread.IsBackground = true; | ||
381 | _finished = false; | 402 | _finished = false; |
382 | httpThread.Start(); | 403 | |
404 | lock (HttpRequestModule.ThreadPool) | ||
405 | WorkItem = HttpRequestModule.ThreadPool.QueueWorkItem(new WorkItemCallback(StpSendWrapper), null); | ||
406 | } | ||
407 | |||
408 | private object StpSendWrapper(object o) | ||
409 | { | ||
410 | SendRequest(); | ||
411 | return null; | ||
383 | } | 412 | } |
384 | 413 | ||
385 | /* | 414 | /* |
@@ -409,13 +438,8 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
409 | { | 438 | { |
410 | // We could hijack Connection Group Name to identify | 439 | // We could hijack Connection Group Name to identify |
411 | // a desired security exception. But at the moment we'll use a dummy header instead. | 440 | // a desired security exception. But at the moment we'll use a dummy header instead. |
412 | // Request.ConnectionGroupName = "NoVerify"; | ||
413 | Request.Headers.Add("NoVerifyCert", "true"); | 441 | Request.Headers.Add("NoVerifyCert", "true"); |
414 | } | 442 | } |
415 | // else | ||
416 | // { | ||
417 | // Request.ConnectionGroupName="Verify"; | ||
418 | // } | ||
419 | if (proxyurl != null && proxyurl.Length > 0) | 443 | if (proxyurl != null && proxyurl.Length > 0) |
420 | { | 444 | { |
421 | if (proxyexcepts != null && proxyexcepts.Length > 0) | 445 | if (proxyexcepts != null && proxyexcepts.Length > 0) |
@@ -485,9 +509,9 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
485 | 509 | ||
486 | ResponseBody = sb.ToString().Replace("\r", ""); | 510 | ResponseBody = sb.ToString().Replace("\r", ""); |
487 | } | 511 | } |
488 | catch (Exception e) | 512 | catch (WebException e) |
489 | { | 513 | { |
490 | if (e is WebException && ((WebException)e).Status == WebExceptionStatus.ProtocolError) | 514 | if (e.Status == WebExceptionStatus.ProtocolError) |
491 | { | 515 | { |
492 | HttpWebResponse webRsp = (HttpWebResponse)((WebException)e).Response; | 516 | HttpWebResponse webRsp = (HttpWebResponse)((WebException)e).Response; |
493 | Status = (int)webRsp.StatusCode; | 517 | Status = (int)webRsp.StatusCode; |
@@ -512,6 +536,10 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
512 | _finished = true; | 536 | _finished = true; |
513 | return; | 537 | return; |
514 | } | 538 | } |
539 | catch (Exception e) | ||
540 | { | ||
541 | // Don't crash on anything else | ||
542 | } | ||
515 | finally | 543 | finally |
516 | { | 544 | { |
517 | if (response != null) | 545 | if (response != null) |
@@ -525,7 +553,10 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
525 | { | 553 | { |
526 | try | 554 | try |
527 | { | 555 | { |
528 | httpThread.Abort(); | 556 | if (!WorkItem.Cancel()) |
557 | { | ||
558 | WorkItem.Abort(); | ||
559 | } | ||
529 | } | 560 | } |
530 | catch (Exception) | 561 | catch (Exception) |
531 | { | 562 | { |
diff --git a/prebuild.xml b/prebuild.xml index 7fff2e0..fa21722 100644 --- a/prebuild.xml +++ b/prebuild.xml | |||
@@ -1680,6 +1680,7 @@ | |||
1680 | 1680 | ||
1681 | <!-- To allow regions to have mono addins --> | 1681 | <!-- To allow regions to have mono addins --> |
1682 | <Reference name="Mono.Addins" path="../../../bin/"/> | 1682 | <Reference name="Mono.Addins" path="../../../bin/"/> |
1683 | <Reference name="SmartThreadPool"/> | ||
1683 | 1684 | ||
1684 | <Files> | 1685 | <Files> |
1685 | <Match buildAction="EmbeddedResource" path="Resources" pattern="*.addin.xml" recurse="true"/> | 1686 | <Match buildAction="EmbeddedResource" path="Resources" pattern="*.addin.xml" recurse="true"/> |