From 3d495b709ec897970b24ce48d6a8495d520864d4 Mon Sep 17 00:00:00 2001 From: Tom Grimshaw Date: Sat, 3 Jul 2010 06:08:18 -0700 Subject: Implement a timeout value in the SynchronousRestObjectRequester. Default is 100 seconds. --- .../HttpServer/SynchronousRestObjectRequester.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs index eab463c..bb3b8b1 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs @@ -57,6 +57,21 @@ namespace OpenSim.Framework.Servers.HttpServer /// the request. You'll want to make sure you deal with this as they're not uncommon public static TResponse MakeRequest(string verb, string requestUrl, TRequest obj) { + return MakeRequest(verb, requestUrl, obj, 100); + } + /// + /// Perform a synchronous REST request. + /// + /// + /// + /// + /// + /// + /// + /// Thrown if we encounter a network issue while posting + /// the request. You'll want to make sure you deal with this as they're not uncommon + public static TResponse MakeRequest(string verb, string requestUrl, TRequest obj, int pTimeout) + { Type type = typeof (TRequest); TResponse deserial = default(TResponse); @@ -81,7 +96,7 @@ namespace OpenSim.Framework.Servers.HttpServer int length = (int) buffer.Length; request.ContentLength = length; - + request.Timeout = pTimeout * 1000; Stream requestStream = null; try { -- cgit v1.1 From 7665013ad8c7ac876955dc803619405dfa2af71d Mon Sep 17 00:00:00 2001 From: Tom Grimshaw Date: Sun, 4 Jul 2010 19:25:54 -0700 Subject: Correct positioning of timeout modifier in the SynchronousRestObjectRequester --- OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs index bb3b8b1..f07f7ab 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs @@ -77,6 +77,7 @@ namespace OpenSim.Framework.Servers.HttpServer WebRequest request = WebRequest.Create(requestUrl); request.Method = verb; + request.Timeout = pTimeout * 1000; if ((verb == "POST") || (verb == "PUT")) { @@ -96,7 +97,6 @@ namespace OpenSim.Framework.Servers.HttpServer int length = (int) buffer.Length; request.ContentLength = length; - request.Timeout = pTimeout * 1000; Stream requestStream = null; try { -- cgit v1.1 From cecd660388e0cda34115be44955758e8221a77d1 Mon Sep 17 00:00:00 2001 From: Tom Grimshaw Date: Sat, 10 Jul 2010 18:48:49 -0700 Subject: Fix an issue where the SynchronousRestObjectRequester will fail if a webserver does not report a content length (-1), but the content is still valid --- OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs index f07f7ab..077a1e8 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs @@ -118,7 +118,7 @@ namespace OpenSim.Framework.Servers.HttpServer { using (WebResponse resp = request.GetResponse()) { - if (resp.ContentLength > 0) + if (resp.ContentLength != 0) { Stream respStream = resp.GetResponseStream(); XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); -- cgit v1.1 From cea856cfc294fb546332bb86abe9f70d791013d5 Mon Sep 17 00:00:00 2001 From: Tom Grimshaw Date: Sat, 10 Jul 2010 19:00:12 -0700 Subject: Fix the synchronousrestformsrequester so it will successfully handle a response from a server which does not provide a valid content length header --- OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs index b0cf34d..92a6caa 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs @@ -99,7 +99,7 @@ namespace OpenSim.Framework.Servers.HttpServer { using (WebResponse resp = request.GetResponse()) { - if (resp.ContentLength > 0) + if (resp.ContentLength != 0) { Stream respStream = null; try -- cgit v1.1 From 1bcb2e788fd895a7d8165797c29e6f2a652eff8b Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Wed, 25 Aug 2010 23:04:12 +0200 Subject: Change some e.Message to e.ToString. Don't use e.Message, it doesn't carry any useful information. Error messages are useless without location information. It looks more elegant, but is totally pointless. --- OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs index 92a6caa..e9ae3a3 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs @@ -81,7 +81,7 @@ namespace OpenSim.Framework.Servers.HttpServer } catch (Exception e) { - m_log.DebugFormat("[FORMS]: exception occured on sending request to {0}: {1}", requestUrl, e.Message); + m_log.DebugFormat("[FORMS]: exception occured on sending request to {0}: " + e.ToString(), requestUrl); } finally { @@ -112,7 +112,7 @@ namespace OpenSim.Framework.Servers.HttpServer } catch (Exception e) { - m_log.DebugFormat("[FORMS]: exception occured on receiving reply {0}", e.Message); + m_log.DebugFormat("[FORMS]: exception occured on receiving reply " + e.ToString()); } finally { -- cgit v1.1 From 1096f43f0d3db628b463d4494c98ad496cf1f039 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Wed, 25 Aug 2010 23:34:39 +0200 Subject: Prevent an object disposed exception that made forms comms unreliable. After starting an asynchronous write, one should not close the channel it will be written to synchrnously, that leads to grief. --- .../Servers/HttpServer/SynchronousRestFormsRequester.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs index e9ae3a3..f955df7 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs @@ -85,8 +85,13 @@ namespace OpenSim.Framework.Servers.HttpServer } finally { - if (requestStream != null) - requestStream.Close(); + // If this is closed, it will be disposed internally, + // but the above write is asynchronous and may hit after + // we're through here. So the thread handling that will + // throw and put us back into the catch above. Isn't + // .NET great? + //if (requestStream != null) + // requestStream.Close(); // Let's not close this //buffer.Close(); -- cgit v1.1 From e5936071711e35f9edf44d8393b8ad28ef4023db Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sun, 5 Sep 2010 14:16:42 +0200 Subject: Remove "Dwell" support from core and replace it with calls to methods on IDwellModule --- .../HttpServer/SynchronousRestFormsRequester.cs | 109 ++++++++++----------- 1 file changed, 51 insertions(+), 58 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs index f955df7..41ece86 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs @@ -57,80 +57,73 @@ namespace OpenSim.Framework.Servers.HttpServer { WebRequest request = WebRequest.Create(requestUrl); request.Method = verb; + string respstring = String.Empty; - if ((verb == "POST") || (verb == "PUT")) + using (MemoryStream buffer = new MemoryStream()) { - request.ContentType = "text/www-form-urlencoded"; - - MemoryStream buffer = new MemoryStream(); - int length = 0; - using (StreamWriter writer = new StreamWriter(buffer)) + if ((verb == "POST") || (verb == "PUT")) { - writer.Write(obj); - writer.Flush(); - } + request.ContentType = "text/www-form-urlencoded"; - length = (int)obj.Length; - request.ContentLength = length; + int length = 0; + using (StreamWriter writer = new StreamWriter(buffer)) + { + writer.Write(obj); + writer.Flush(); + } - Stream requestStream = null; - try - { - requestStream = request.GetRequestStream(); - requestStream.Write(buffer.ToArray(), 0, length); - } - catch (Exception e) - { - m_log.DebugFormat("[FORMS]: exception occured on sending request to {0}: " + e.ToString(), requestUrl); - } - finally - { - // If this is closed, it will be disposed internally, - // but the above write is asynchronous and may hit after - // we're through here. So the thread handling that will - // throw and put us back into the catch above. Isn't - // .NET great? - //if (requestStream != null) - // requestStream.Close(); - // Let's not close this - //buffer.Close(); + length = (int)obj.Length; + request.ContentLength = length; + Stream requestStream = null; + try + { + requestStream = request.GetRequestStream(); + requestStream.Write(buffer.ToArray(), 0, length); + } + catch (Exception e) + { + m_log.DebugFormat("[FORMS]: exception occured on sending request to {0}: " + e.ToString(), requestUrl); + } + finally + { + if (requestStream != null) + requestStream.Close(); + } } - } - - string respstring = String.Empty; - try - { - using (WebResponse resp = request.GetResponse()) + try { - if (resp.ContentLength != 0) + using (WebResponse resp = request.GetResponse()) { - Stream respStream = null; - try + if (resp.ContentLength != 0) { - respStream = resp.GetResponseStream(); - using (StreamReader reader = new StreamReader(respStream)) + Stream respStream = null; + try { - respstring = reader.ReadToEnd(); + respStream = resp.GetResponseStream(); + using (StreamReader reader = new StreamReader(respStream)) + { + respstring = reader.ReadToEnd(); + } + } + catch (Exception e) + { + m_log.DebugFormat("[FORMS]: exception occured on receiving reply " + e.ToString()); + } + finally + { + if (respStream != null) + respStream.Close(); } - } - catch (Exception e) - { - m_log.DebugFormat("[FORMS]: exception occured on receiving reply " + e.ToString()); - } - finally - { - if (respStream != null) - respStream.Close(); } } } - } - catch (System.InvalidOperationException) - { - // This is what happens when there is invalid XML - m_log.DebugFormat("[FORMS]: InvalidOperationException on receiving request"); + catch (System.InvalidOperationException) + { + // This is what happens when there is invalid XML + m_log.DebugFormat("[FORMS]: InvalidOperationException on receiving request"); + } } return respstring; } -- cgit v1.1 From f2e343d53081dbd6956d39b1e172e171101a4900 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Mon, 6 Sep 2010 14:09:46 +0200 Subject: Workaround for mono bug #312968 --- OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs index 41ece86..e481b2b 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs @@ -64,6 +64,7 @@ namespace OpenSim.Framework.Servers.HttpServer if ((verb == "POST") || (verb == "PUT")) { request.ContentType = "text/www-form-urlencoded"; + request.KeepAlive = true; int length = 0; using (StreamWriter writer = new StreamWriter(buffer)) -- cgit v1.1 From 06adbc13242c16d40f9e9a02652067131f2eb9b7 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Mon, 6 Sep 2010 17:24:10 +0200 Subject: Revert "Workaround for mono bug #312968" This reverts commit f2e343d53081dbd6956d39b1e172e171101a4900. Doesn't compile with our version of Mono. Patched Mono instead. --- OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs | 1 - 1 file changed, 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs index e481b2b..41ece86 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs @@ -64,7 +64,6 @@ namespace OpenSim.Framework.Servers.HttpServer if ((verb == "POST") || (verb == "PUT")) { request.ContentType = "text/www-form-urlencoded"; - request.KeepAlive = true; int length = 0; using (StreamWriter writer = new StreamWriter(buffer)) -- cgit v1.1 From 9b9ce8fb27f45009406e088284e4488749f3902e Mon Sep 17 00:00:00 2001 From: sacha Date: Sat, 4 Dec 2010 21:40:18 +0000 Subject: add more detail to the log in case of FORM Timeout cause nothing relevant are in the services logs --- OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs index 41ece86..d5646d0 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs @@ -83,7 +83,7 @@ namespace OpenSim.Framework.Servers.HttpServer } catch (Exception e) { - m_log.DebugFormat("[FORMS]: exception occured on sending request to {0}: " + e.ToString(), requestUrl); + m_log.DebugFormat("[FORMS]: exception occured on sending request to {0}: with {1} " + e.ToString(), requestUrl,obj); } finally { -- cgit v1.1 From f54ddd88a2d615a7d577671cd38e66e60994451d Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 14 Mar 2011 12:56:50 +0100 Subject: Up the timeout on slow requests to 3000 to stop console spam. Make sure request method and target are reported correctly and drop the txn id as it's empty 99% of the time. --- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 26 +++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 1d05b02..953ed85 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -378,6 +378,22 @@ namespace OpenSim.Framework.Servers.HttpServer /// public virtual void HandleRequest(OSHttpRequest request, OSHttpResponse response) { + if (request.HttpMethod == String.Empty) // Can't handle empty requests, not wasting a thread + { + try + { + SendHTML500(response); + } + catch + { + } + + return; + } + + string requestMethod = request.HttpMethod; + string uriString = request.RawUrl; + string reqnum = "unknown"; int tickstart = Environment.TickCount; @@ -495,7 +511,7 @@ namespace OpenSim.Framework.Servers.HttpServer request.InputStream.Close(); - // HTTP IN support. The script engine taes it from here + // HTTP IN support. The script engine takes it from here // Nothing to worry about for us. // if (buffer == null) @@ -609,9 +625,9 @@ namespace OpenSim.Framework.Servers.HttpServer { m_log.ErrorFormat("[BASE HTTP SERVER]: HandleRequest() threw ", e); } - catch (InvalidOperationException e) + catch (Exception e) { - m_log.ErrorFormat("[BASE HTTP SERVER]: HandleRequest() threw {0}", e); + m_log.ErrorFormat("[BASE HTTP SERVER]: HandleRequest() threw " + e.ToString()); SendHTML500(response); } finally @@ -619,9 +635,9 @@ namespace OpenSim.Framework.Servers.HttpServer // Every month or so this will wrap and give bad numbers, not really a problem // since its just for reporting, 200ms limit can be adjusted int tickdiff = Environment.TickCount - tickstart; - if (tickdiff > 500) + if (tickdiff > 3000) m_log.InfoFormat( - "[BASE HTTP SERVER]: slow request <{0}> for {1} took {2} ms", reqnum, request.RawUrl, tickdiff); + "[BASE HTTP SERVER]: slow {0} request for {1} from {2} took {3} ms", requestMethod, uriString, request.RemoteIPEndPoint.ToString(), tickdiff); } } -- cgit v1.1 From 74dd619575c2e260ba680312a87249e284f3d2c9 Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 17 May 2011 19:12:37 -0700 Subject: If a response cannot be obtained (the script has no handler) return a more friendly 500 error instead of crashing out with a null reference and letting the connection hang --- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 598e5d1..36c6c75 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -1510,11 +1510,25 @@ namespace OpenSim.Framework.Servers.HttpServer internal void DoHTTPGruntWork(Hashtable responsedata, OSHttpResponse response) { - //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response"); - int responsecode = (int)responsedata["int_response_code"]; - string responseString = (string)responsedata["str_response_string"]; - string contentType = (string)responsedata["content_type"]; + int responsecode; + string responseString; + string contentType; + if (responsedata == null) + { + responsecode = 500; + responseString = "No response could be obtained"; + contentType = "text/plain"; + responsedata = new Hashtable(); + } + else + { + + //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response"); + responsecode = (int)responsedata["int_response_code"]; + responseString = (string)responsedata["str_response_string"]; + contentType = (string)responsedata["content_type"]; + } if (responsedata.ContainsKey("error_status_text")) { -- cgit v1.1 From b000d9ba724ae12ae27c49dd94e36d4592bd6c26 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 26 May 2011 03:42:01 -0700 Subject: Some additional protection, it seems that responsedata needs to be locked, but I can't immediately see where it's being accessed from another thread. For now, this will protect the server --- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 36c6c75..c12d666 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -1523,11 +1523,20 @@ namespace OpenSim.Framework.Servers.HttpServer } else { - - //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response"); - responsecode = (int)responsedata["int_response_code"]; - responseString = (string)responsedata["str_response_string"]; - contentType = (string)responsedata["content_type"]; + try + { + //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response"); + responsecode = (int)responsedata["int_response_code"]; + responseString = (string)responsedata["str_response_string"]; + contentType = (string)responsedata["content_type"]; + } + catch + { + responsecode = 500; + responseString = "No response could be obtained"; + contentType = "text/plain"; + responsedata = new Hashtable(); + } } if (responsedata.ContainsKey("error_status_text")) -- cgit v1.1 From 9a8de52940ea6d9ce430d8d51094a353eca7d3c5 Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 26 Jun 2012 10:49:37 +0200 Subject: Add an event to the poll service manager thread to allow starting it when needed rather than once per second. That is just too slow! --- .../Framework/Servers/HttpServer/PollServiceRequestManager.cs | 7 +++++-- .../Framework/Servers/HttpServer/PollServiceWorkerThread.cs | 11 +++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 0062d4e..c3e1a79 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -41,6 +41,7 @@ namespace OpenSim.Framework.Servers.HttpServer private readonly BaseHttpServer m_server; private static Queue m_requests = Queue.Synchronized(new Queue()); + private static ManualResetEvent m_ev = new ManualResetEvent(false); private uint m_WorkerThreadCount = 0; private Thread[] m_workerThreads; private PollServiceWorkerThread[] m_PollServiceWorkerThreads; @@ -88,15 +89,17 @@ namespace OpenSim.Framework.Servers.HttpServer { lock (m_requests) m_requests.Enqueue(req); + m_ev.Set(); } public void ThreadStart() { while (m_running) { + m_ev.WaitOne(1000); + m_ev.Reset(); Watchdog.UpdateThread(); ProcessQueuedRequests(); - Thread.Sleep(1000); } } @@ -152,4 +155,4 @@ namespace OpenSim.Framework.Servers.HttpServer m_running = false; } } -} \ No newline at end of file +} diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs index 5e171f0..b39185f 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs @@ -89,9 +89,16 @@ namespace OpenSim.Framework.Servers.HttpServer continue; } - Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, str.ReadToEnd()); - m_server.DoHTTPGruntWork(responsedata, + try + { + Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, str.ReadToEnd()); + m_server.DoHTTPGruntWork(responsedata, new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request),req.HttpContext)); + } + catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream + { + // Ignore it, no need to reply + } } else { -- cgit v1.1 From d3f1fc79e50edb9ef851bdedfa83e9f5c13b4519 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 1 Jul 2012 01:33:20 +0100 Subject: *TO CHECK/REVIEW/REVERT/TEST whatever* pollService new requests get enqueued to unified requests queue directly. Retries get into that every 100ms. 3 working threads as before plus another that only does retries timming. --- .../HttpServer/PollServiceRequestManager.cs | 203 +++++++++++++++++++++ .../Servers/HttpServer/PollServiceWorkerThread.cs | 3 + 2 files changed, 206 insertions(+) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index c3e1a79..e488b38 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -33,8 +33,11 @@ using log4net; using HttpServer; using OpenSim.Framework; + +/* namespace OpenSim.Framework.Servers.HttpServer { + public class PollServiceRequestManager { // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -156,3 +159,203 @@ namespace OpenSim.Framework.Servers.HttpServer } } } + */ + +using System.IO; +using System.Text; +using System.Collections.Generic; + +namespace OpenSim.Framework.Servers.HttpServer +{ + public class PollServiceRequestManager + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private readonly BaseHttpServer m_server; + + private BlockingQueue m_requests = new BlockingQueue(); + private static Queue m_retry_requests = new Queue(); + + private uint m_WorkerThreadCount = 0; + private Thread[] m_workerThreads; + private Thread m_retrysThread; + + private bool m_running = true; + + private int m_timeout = 250; + + public PollServiceRequestManager(BaseHttpServer pSrv, uint pWorkerThreadCount, int pTimeout) + { + m_server = pSrv; + m_WorkerThreadCount = pWorkerThreadCount; + m_workerThreads = new Thread[m_WorkerThreadCount]; + + //startup worker threads + for (uint i = 0; i < m_WorkerThreadCount; i++) + { + m_workerThreads[i] + = Watchdog.StartThread( + poolWorkerJob, + String.Format("PollServiceWorkerThread{0}", i), + ThreadPriority.Normal, + false, + true, + int.MaxValue); + } + + m_retrysThread = Watchdog.StartThread( + this.CheckRetries, + "PollServiceWatcherThread", + ThreadPriority.Normal, + false, + true, + 1000 * 60 * 10); + } + + + private void ReQueueEvent(PollServiceHttpRequest req) + { + if (m_running) + { + lock (m_retry_requests) + m_retry_requests.Enqueue(req); + } + } + + public void Enqueue(PollServiceHttpRequest req) + { + if (m_running) + m_requests.Enqueue(req); + } + + private void CheckRetries() + { + while (m_running) + { + Thread.Sleep(100); // let the world move + Watchdog.UpdateThread(); + lock (m_retry_requests) + { + while (m_retry_requests.Count > 0 && m_running) + Enqueue(m_retry_requests.Dequeue()); + } + } + } + + ~PollServiceRequestManager() + { + m_running = false; + m_timeout = -10000; // cause all to expire + Thread.Sleep(1000); // let the world move + + foreach (Thread t in m_workerThreads) + { + try + { + t.Abort(); + } + catch + { + } + } + + try + { + foreach (PollServiceHttpRequest req in m_retry_requests) + { + m_server.DoHTTPGruntWork( + req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id), + new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext)); + } + } + catch + { + } + + PollServiceHttpRequest wreq; + m_retry_requests.Clear(); + + while (m_requests.Count() > 0) + { + try + { + wreq = m_requests.Dequeue(0); + m_server.DoHTTPGruntWork( + wreq.PollServiceArgs.NoEvents(wreq.RequestID, wreq.PollServiceArgs.Id), + new OSHttpResponse(new HttpResponse(wreq.HttpContext, wreq.Request), wreq.HttpContext)); + } + catch + { + } + } + + m_requests.Clear(); + } + + // work threads + + private void poolWorkerJob() + { + PollServiceHttpRequest req; + StreamReader str; + + while (true) + { + req = m_requests.Dequeue(5000); + + Watchdog.UpdateThread(); + if (req != null) + { + try + { + if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id)) + { + try + { + str = new StreamReader(req.Request.Body); + } + catch (System.ArgumentException) + { + // Stream was not readable means a child agent + // was closed due to logout, leaving the + // Event Queue request orphaned. + continue; + } + + try + { + Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, str.ReadToEnd()); + m_server.DoHTTPGruntWork(responsedata, + new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext)); + } + catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream + { + // Ignore it, no need to reply + } + + str.Close(); + + } + else + { + if ((Environment.TickCount - req.RequestTime) > m_timeout) + { + m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id), + new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext)); + } + else + { + ReQueueEvent(req); + } + } + } + catch (Exception e) + { + m_log.ErrorFormat("Exception in poll service thread: " + e.ToString()); + } + } + } + } + } +} + diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs index b39185f..7cd27e5 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs @@ -25,6 +25,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* Ubit work moved to PollServiceRequestManager + using System; using System.Collections; using System.Collections.Generic; @@ -128,3 +130,4 @@ namespace OpenSim.Framework.Servers.HttpServer } } } +*/ \ No newline at end of file -- cgit v1.1 From b2fa20001f8af9d62b0caa3612d8f1ab6f2caa87 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 4 Jul 2012 06:14:47 +0100 Subject: *test* slow http retries pool rate to original 1s --- OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index e488b38..36f2b9b 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -232,7 +232,7 @@ namespace OpenSim.Framework.Servers.HttpServer { while (m_running) { - Thread.Sleep(100); // let the world move + Thread.Sleep(1000); // let the world move slow it to original polling rate Watchdog.UpdateThread(); lock (m_retry_requests) { -- cgit v1.1 From e533eef962fe05ea7ca156fa3420cb2a1d679297 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 4 Jul 2012 15:07:10 +0100 Subject: *test2* http poll: increased again the pool rate do 10/s but increased timeout to 1s. So data there is less delay when there is new data, but enought waiting time for it to be avaiable --- OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 36f2b9b..125d9c2 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -182,7 +182,7 @@ namespace OpenSim.Framework.Servers.HttpServer private bool m_running = true; - private int m_timeout = 250; + private int m_timeout = 1000; // increase timeout 250; public PollServiceRequestManager(BaseHttpServer pSrv, uint pWorkerThreadCount, int pTimeout) { @@ -232,7 +232,7 @@ namespace OpenSim.Framework.Servers.HttpServer { while (m_running) { - Thread.Sleep(1000); // let the world move slow it to original polling rate + Thread.Sleep(100); // let the world move .. back to faster rate Watchdog.UpdateThread(); lock (m_retry_requests) { -- cgit v1.1 From 02cb0bf80a0b67eb0316ac74e1ea9741bfce1385 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 4 Jul 2012 17:40:02 +0100 Subject: added a timeout paramenter to PollServiceEventArgs, so each type can define it's timeout --- OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs index 9d512c6..2407533 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs @@ -44,13 +44,16 @@ namespace OpenSim.Framework.Servers.HttpServer public NoEventsMethod NoEvents; public RequestMethod Request; public UUID Id; - public PollServiceEventArgs(RequestMethod pRequest, HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents,UUID pId) + public int TimeOutms; + + public PollServiceEventArgs(RequestMethod pRequest, HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents, UUID pId, int pTimeOutms) { Request = pRequest; HasEvents = pHasEvents; GetEvents = pGetEvents; NoEvents = pNoEvents; Id = pId; + TimeOutms = pTimeOutms; } } } -- cgit v1.1 From bc5d554f548e973221f8a18cdcb5a5883ed6039f Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 4 Jul 2012 17:58:32 +0100 Subject: use the pollEvent timeout paramenter on pooling --- .../Framework/Servers/HttpServer/PollServiceRequestManager.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 125d9c2..45b1375 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -182,7 +182,7 @@ namespace OpenSim.Framework.Servers.HttpServer private bool m_running = true; - private int m_timeout = 1000; // increase timeout 250; +// private int m_timeout = 1000; // increase timeout 250; now use the event one public PollServiceRequestManager(BaseHttpServer pSrv, uint pWorkerThreadCount, int pTimeout) { @@ -245,7 +245,7 @@ namespace OpenSim.Framework.Servers.HttpServer ~PollServiceRequestManager() { m_running = false; - m_timeout = -10000; // cause all to expire +// m_timeout = -10000; // cause all to expire Thread.Sleep(1000); // let the world move foreach (Thread t in m_workerThreads) @@ -299,7 +299,8 @@ namespace OpenSim.Framework.Servers.HttpServer PollServiceHttpRequest req; StreamReader str; - while (true) +// while (true) + while (m_running) { req = m_requests.Dequeue(5000); @@ -338,7 +339,9 @@ namespace OpenSim.Framework.Servers.HttpServer } else { - if ((Environment.TickCount - req.RequestTime) > m_timeout) +// if ((Environment.TickCount - req.RequestTime) > m_timeout) + + if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) { m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id), new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext)); -- cgit v1.1 From 4854d779041e987ae13de4f30a37e4fab1b7a3d7 Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 5 Jul 2012 23:09:20 +0200 Subject: Add an EventType enum and Type field to the poll service event args. This allows the manager to tell what type of event it is. All events except for lsl http in go to the "slow queue" which is run once per second as before. --- .../Servers/HttpServer/PollServiceEventArgs.cs | 8 +++++ .../HttpServer/PollServiceRequestManager.cs | 37 +++++++++++++++------- 2 files changed, 34 insertions(+), 11 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs index 2407533..7c92a50 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs @@ -45,6 +45,13 @@ namespace OpenSim.Framework.Servers.HttpServer public RequestMethod Request; public UUID Id; public int TimeOutms; + public EventType Type; + + public enum EventType : int + { + Normal = 0, + LslHttp = 1 + } public PollServiceEventArgs(RequestMethod pRequest, HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents, UUID pId, int pTimeOutms) { @@ -54,6 +61,7 @@ namespace OpenSim.Framework.Servers.HttpServer NoEvents = pNoEvents; Id = pId; TimeOutms = pTimeOutms; + Type = EventType.Normal; } } } diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 45b1375..c7c7c13 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -174,13 +174,15 @@ namespace OpenSim.Framework.Servers.HttpServer private readonly BaseHttpServer m_server; private BlockingQueue m_requests = new BlockingQueue(); - private static Queue m_retry_requests = new Queue(); + private BlockingQueue m_slowRequests = new BlockingQueue(); + private static Queue m_retryRequests = new Queue(); private uint m_WorkerThreadCount = 0; private Thread[] m_workerThreads; private Thread m_retrysThread; private bool m_running = true; + private int slowCount = 0; // private int m_timeout = 1000; // increase timeout 250; now use the event one @@ -195,7 +197,7 @@ namespace OpenSim.Framework.Servers.HttpServer { m_workerThreads[i] = Watchdog.StartThread( - poolWorkerJob, + PoolWorkerJob, String.Format("PollServiceWorkerThread{0}", i), ThreadPriority.Normal, false, @@ -217,15 +219,20 @@ namespace OpenSim.Framework.Servers.HttpServer { if (m_running) { - lock (m_retry_requests) - m_retry_requests.Enqueue(req); + lock (m_retryRequests) + m_retryRequests.Enqueue(req); } } public void Enqueue(PollServiceHttpRequest req) { if (m_running) - m_requests.Enqueue(req); + { + if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LslHttp) + m_slowRequests.Enqueue(req); + else + m_requests.Enqueue(req); + } } private void CheckRetries() @@ -234,10 +241,18 @@ namespace OpenSim.Framework.Servers.HttpServer { Thread.Sleep(100); // let the world move .. back to faster rate Watchdog.UpdateThread(); - lock (m_retry_requests) + lock (m_retryRequests) { - while (m_retry_requests.Count > 0 && m_running) - Enqueue(m_retry_requests.Dequeue()); + while (m_retryRequests.Count > 0 && m_running) + m_requests.Enqueue(m_retryRequests.Dequeue()); + } + slowCount++; + if (slowCount >= 10) + { + slowCount = 0; + + while (m_slowRequests.Count() > 0 && m_running) + m_requests.Enqueue(m_retryRequests.Dequeue()); } } } @@ -261,7 +276,7 @@ namespace OpenSim.Framework.Servers.HttpServer try { - foreach (PollServiceHttpRequest req in m_retry_requests) + foreach (PollServiceHttpRequest req in m_retryRequests) { m_server.DoHTTPGruntWork( req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id), @@ -273,7 +288,7 @@ namespace OpenSim.Framework.Servers.HttpServer } PollServiceHttpRequest wreq; - m_retry_requests.Clear(); + m_retryRequests.Clear(); while (m_requests.Count() > 0) { @@ -294,7 +309,7 @@ namespace OpenSim.Framework.Servers.HttpServer // work threads - private void poolWorkerJob() + private void PoolWorkerJob() { PollServiceHttpRequest req; StreamReader str; -- cgit v1.1 From bf292ce26f5742eaf1ae534320506b28f3a5492c Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 5 Jul 2012 23:24:15 +0200 Subject: Fix the boo-boo --- OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index c7c7c13..06745f9 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -229,9 +229,9 @@ namespace OpenSim.Framework.Servers.HttpServer if (m_running) { if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LslHttp) - m_slowRequests.Enqueue(req); - else m_requests.Enqueue(req); + else + m_slowRequests.Enqueue(req); } } @@ -252,7 +252,7 @@ namespace OpenSim.Framework.Servers.HttpServer slowCount = 0; while (m_slowRequests.Count() > 0 && m_running) - m_requests.Enqueue(m_retryRequests.Dequeue()); + m_requests.Enqueue(m_slowRequests.Dequeue()); } } } -- cgit v1.1 From b8c2efa49c35d623a6a2969322536fde67cb86dc Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 6 Jul 2012 00:23:05 +0200 Subject: Convert the slow request queue into a regular queue and add some cleanup and locking. --- .../HttpServer/PollServiceRequestManager.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 06745f9..6f87c85 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -174,7 +174,7 @@ namespace OpenSim.Framework.Servers.HttpServer private readonly BaseHttpServer m_server; private BlockingQueue m_requests = new BlockingQueue(); - private BlockingQueue m_slowRequests = new BlockingQueue(); + private static Queue m_slowRequests = new Queue(); private static Queue m_retryRequests = new Queue(); private uint m_WorkerThreadCount = 0; @@ -229,9 +229,14 @@ namespace OpenSim.Framework.Servers.HttpServer if (m_running) { if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LslHttp) + { m_requests.Enqueue(req); + } else - m_slowRequests.Enqueue(req); + { + lock (m_slowRequests) + m_slowRequests.Enqueue(req); + } } } @@ -251,8 +256,11 @@ namespace OpenSim.Framework.Servers.HttpServer { slowCount = 0; - while (m_slowRequests.Count() > 0 && m_running) - m_requests.Enqueue(m_slowRequests.Dequeue()); + lock (m_slowRequests) + { + while (m_slowRequests.Count > 0 && m_running) + m_requests.Enqueue(m_slowRequests.Dequeue()); + } } } } @@ -290,6 +298,12 @@ namespace OpenSim.Framework.Servers.HttpServer PollServiceHttpRequest wreq; m_retryRequests.Clear(); + lock (m_slowRequests) + { + while (m_slowRequests.Count > 0 && m_running) + m_requests.Enqueue(m_slowRequests.Dequeue()); + } + while (m_requests.Count() > 0) { try -- cgit v1.1 From ad75a4b50b77dee08614dba9e57261d8b08c6860 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sun, 15 Jul 2012 12:28:58 +0200 Subject: Eliminate a spurious exception report when a https url is accessed with a wrong CN --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index ad5af1f..a3a5029 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -1809,6 +1809,8 @@ namespace OpenSim.Framework.Servers.HttpServer public void httpServerException(object source, Exception exception) { + if (source.ToString() == "HttpServer.HttpListener" && exception.ToString().StartsWith("Mono.Security.Protocol.Tls.TlsException")) + return; m_log.ErrorFormat("[BASE HTTP SERVER]: {0} had an exception {1}", source.ToString(), exception.ToString()); /* if (HTTPDRunning)// && NotSocketErrors > 5) -- cgit v1.1 From b35f97db4658f0dd4af0ad1f56a6303d6d45d51e Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 17 Jul 2012 10:21:12 +0200 Subject: Replace PollServiceRequestManager with older version, add extra logging to event exceptions to see call path leading up to it. --- .../Servers/HttpServer/PollServiceRequestManager.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 3a14b6f..af40185 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -70,7 +70,6 @@ namespace OpenSim.Framework.Servers.HttpServer ThreadPriority.Normal, false, true, - null, int.MaxValue); } @@ -80,7 +79,6 @@ namespace OpenSim.Framework.Servers.HttpServer ThreadPriority.Normal, false, true, - null, 1000 * 60 * 10); } @@ -146,8 +144,9 @@ namespace OpenSim.Framework.Servers.HttpServer foreach (object o in m_requests) { PollServiceHttpRequest req = (PollServiceHttpRequest) o; - PollServiceWorkerThread.DoHTTPGruntWork( - m_server, req, req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); + m_server.DoHTTPGruntWork( + req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id), + new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext)); } m_requests.Clear(); @@ -156,7 +155,6 @@ namespace OpenSim.Framework.Servers.HttpServer { t.Abort(); } - m_running = false; } } @@ -186,7 +184,7 @@ namespace OpenSim.Framework.Servers.HttpServer private bool m_running = true; private int slowCount = 0; - // private int m_timeout = 250; // increase timeout 250; now use the event one +// private int m_timeout = 1000; // increase timeout 250; now use the event one public PollServiceRequestManager(BaseHttpServer pSrv, uint pWorkerThreadCount, int pTimeout) { @@ -372,7 +370,8 @@ namespace OpenSim.Framework.Servers.HttpServer } else { - // if ((Environment.TickCount - req.RequestTime) > m_timeout) +// if ((Environment.TickCount - req.RequestTime) > m_timeout) + if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) { m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id), -- cgit v1.1 From 5874dfd3422d3ff7e35e8eb7e424f5f003f2d1a2 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 17 Jul 2012 09:47:20 +0100 Subject: fix PollServiceRequestManager --- .../HttpServer/PollServiceRequestManager.cs | 57 ++++++++++++++++++---- 1 file changed, 47 insertions(+), 10 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 3a14b6f..4fe783d 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -290,9 +290,8 @@ namespace OpenSim.Framework.Servers.HttpServer { foreach (PollServiceHttpRequest req in m_retryRequests) { - m_server.DoHTTPGruntWork( - req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id), - new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext)); + DoHTTPGruntWork(m_server,req, + req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); } } catch @@ -313,9 +312,8 @@ namespace OpenSim.Framework.Servers.HttpServer try { wreq = m_requests.Dequeue(0); - m_server.DoHTTPGruntWork( - wreq.PollServiceArgs.NoEvents(wreq.RequestID, wreq.PollServiceArgs.Id), - new OSHttpResponse(new HttpResponse(wreq.HttpContext, wreq.Request), wreq.HttpContext)); + DoHTTPGruntWork(m_server,wreq, + wreq.PollServiceArgs.NoEvents(wreq.RequestID, wreq.PollServiceArgs.Id)); } catch { @@ -359,8 +357,7 @@ namespace OpenSim.Framework.Servers.HttpServer try { Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, str.ReadToEnd()); - m_server.DoHTTPGruntWork(responsedata, - new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext)); + DoHTTPGruntWork(m_server, req, responsedata); } catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream { @@ -375,8 +372,8 @@ namespace OpenSim.Framework.Servers.HttpServer // if ((Environment.TickCount - req.RequestTime) > m_timeout) if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) { - m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id), - new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext)); + DoHTTPGruntWork(m_server, req, + req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); } else { @@ -391,6 +388,46 @@ namespace OpenSim.Framework.Servers.HttpServer } } } + + // DoHTTPGruntWork changed, not sending response + // do the same work around as core + + internal static void DoHTTPGruntWork(BaseHttpServer server, PollServiceHttpRequest req, Hashtable responsedata) + { + OSHttpResponse response + = new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext); + + byte[] buffer = server.DoHTTPGruntWork(responsedata, response); + + response.SendChunked = false; + response.ContentLength64 = buffer.Length; + response.ContentEncoding = Encoding.UTF8; + + try + { + response.OutputStream.Write(buffer, 0, buffer.Length); + } + catch (Exception ex) + { + m_log.Warn(string.Format("[POLL SERVICE WORKER THREAD]: Error ", ex)); + } + finally + { + //response.OutputStream.Close(); + try + { + response.OutputStream.Flush(); + response.Send(); + + //if (!response.KeepAlive && response.ReuseContext) + // response.FreeContext(); + } + catch (Exception e) + { + m_log.Warn(String.Format("[POLL SERVICE WORKER THREAD]: Error ", e)); + } + } + } } } -- cgit v1.1 From 7e17f4296e91129990c15cdaaa1689922a57f9aa Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 24 Aug 2012 23:48:01 +0200 Subject: Fix background inventory loading (Viewer 3) so it won't lag out the sim --- OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs | 3 ++- OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs index bb43cd2..c24a000 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs @@ -51,7 +51,8 @@ namespace OpenSim.Framework.Servers.HttpServer public enum EventType : int { Normal = 0, - LslHttp = 1 + LslHttp = 1, + Inventory = 2 } public PollServiceEventArgs( diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index a385110..a1dee4e 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -231,7 +231,8 @@ namespace OpenSim.Framework.Servers.HttpServer { if (m_running) { - if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LslHttp) + if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LslHttp || + req.PollServiceArgs.Type == PollServiceEventArgs.EventType.Inventory) { m_requests.Enqueue(req); } -- cgit v1.1 From a7250c6ea16971327f28296bdef9a264cf61efc0 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 10 Sep 2012 01:23:20 +0100 Subject: add a extra httppool thread to compensate for webfetchinventory --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index e45cb89..7384e39 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -1618,7 +1618,8 @@ namespace OpenSim.Framework.Servers.HttpServer m_httpListener2.Start(64); // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events - m_PollServiceManager = new PollServiceRequestManager(this, 3, 25000); +// m_PollServiceManager = new PollServiceRequestManager(this, 3, 25000); + m_PollServiceManager = new PollServiceRequestManager(this, 4, 25000); HTTPDRunning = true; //HttpListenerContext context; -- cgit v1.1 From 52d74cf274fbf002e7ec6ad82fe1a38dc2c02d59 Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 14 Sep 2012 00:11:23 +0200 Subject: Allow setting max connections for an endpoint --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 7384e39..57c9d7c 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -640,7 +640,7 @@ namespace OpenSim.Framework.Servers.HttpServer // Every month or so this will wrap and give bad numbers, not really a problem // since its just for reporting int tickdiff = requestEndTick - requestStartTick; - if (tickdiff > 3000) + if (tickdiff > 3000 && requestHandler.Name != "GetTexture") { m_log.InfoFormat( "[BASE HTTP SERVER]: Slow handling of {0} {1} {2} {3} from {4} took {5}ms", -- cgit v1.1 From 387e59ff7f60f2b12526eaacd93581f76abe26e1 Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 14 Sep 2012 21:24:25 +0200 Subject: Revamp the HTTP textures handler to allow a maximum of four fetches at any time and to drop requests for avatars n longer in the scene --- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 47 +++++++++++++++------- .../Servers/HttpServer/PollServiceEventArgs.cs | 3 +- .../HttpServer/PollServiceRequestManager.cs | 3 +- 3 files changed, 36 insertions(+), 17 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 57c9d7c..6121371 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -1449,7 +1449,8 @@ namespace OpenSim.Framework.Servers.HttpServer internal byte[] DoHTTPGruntWork(Hashtable responsedata, OSHttpResponse response) { int responsecode; - string responseString; + string responseString = String.Empty; + byte[] responseData = null; string contentType; if (responsedata == null) @@ -1465,7 +1466,10 @@ namespace OpenSim.Framework.Servers.HttpServer { //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response"); responsecode = (int)responsedata["int_response_code"]; - responseString = (string)responsedata["str_response_string"]; + if (responsedata["bin_response_data"] != null) + responseData = (byte[])responsedata["bin_response_data"]; + else + responseString = (string)responsedata["str_response_string"]; contentType = (string)responsedata["content_type"]; } catch @@ -1520,25 +1524,40 @@ namespace OpenSim.Framework.Servers.HttpServer response.AddHeader("Content-Type", contentType); + if (responsedata.ContainsKey("headers")) + { + Hashtable headerdata = (Hashtable)responsedata["headers"]; + + foreach (string header in headerdata.Keys) + response.AddHeader(header, (string)headerdata[header]); + } + byte[] buffer; - if (!(contentType.Contains("image") - || contentType.Contains("x-shockwave-flash") - || contentType.Contains("application/x-oar") - || contentType.Contains("application/vnd.ll.mesh"))) + if (responseData != null) { - // Text - buffer = Encoding.UTF8.GetBytes(responseString); + buffer = responseData; } else { - // Binary! - buffer = Convert.FromBase64String(responseString); - } + if (!(contentType.Contains("image") + || contentType.Contains("x-shockwave-flash") + || contentType.Contains("application/x-oar") + || contentType.Contains("application/vnd.ll.mesh"))) + { + // Text + buffer = Encoding.UTF8.GetBytes(responseString); + } + else + { + // Binary! + buffer = Convert.FromBase64String(responseString); + } - response.SendChunked = false; - response.ContentLength64 = buffer.Length; - response.ContentEncoding = Encoding.UTF8; + response.SendChunked = false; + response.ContentLength64 = buffer.Length; + response.ContentEncoding = Encoding.UTF8; + } return buffer; } diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs index c24a000..a80b1d7 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs @@ -52,7 +52,8 @@ namespace OpenSim.Framework.Servers.HttpServer { Normal = 0, LslHttp = 1, - Inventory = 2 + Inventory = 2, + Texture = 3 } public PollServiceEventArgs( diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index a1dee4e..db088e7 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -231,8 +231,7 @@ namespace OpenSim.Framework.Servers.HttpServer { if (m_running) { - if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LslHttp || - req.PollServiceArgs.Type == PollServiceEventArgs.EventType.Inventory) + if (req.PollServiceArgs.Type != PollServiceEventArgs.EventType.Normal) { m_requests.Enqueue(req); } -- cgit v1.1 From 2aa7a22129e2b5c226d3937c31bdcbdbc65a20f8 Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 14 Sep 2012 23:09:07 +0200 Subject: Sequence/throttle asset retrievals. --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 6121371..11852eb 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -1471,6 +1471,8 @@ namespace OpenSim.Framework.Servers.HttpServer else responseString = (string)responsedata["str_response_string"]; contentType = (string)responsedata["content_type"]; + if (responseString == null) + responseString = String.Empty; } catch { -- cgit v1.1 From a97436f2f16c2ef217963545349149cdbf9c21b8 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sun, 16 Sep 2012 16:42:30 +0200 Subject: Catch a nullref in the code to suppress GetTexture warnign spam we can't do a thing about anyway. --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 11852eb..2582b7b 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -640,7 +640,7 @@ namespace OpenSim.Framework.Servers.HttpServer // Every month or so this will wrap and give bad numbers, not really a problem // since its just for reporting int tickdiff = requestEndTick - requestStartTick; - if (tickdiff > 3000 && requestHandler.Name != "GetTexture") + if (tickdiff > 3000 && (requestHandler == null || requestHandler.Name == null || requestHandler.Name != "GetTexture")) { m_log.InfoFormat( "[BASE HTTP SERVER]: Slow handling of {0} {1} {2} {3} from {4} took {5}ms", -- cgit v1.1 From 2d02405186841d5aeea30b608d106212f5fee1c3 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sun, 23 Sep 2012 23:16:25 +0200 Subject: Change the poll service to use a thread pool for replies to make sure the event queues aren't blocked by other traffic. --- .../HttpServer/PollServiceRequestManager.cs | 45 ++++++++++++++++++---- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index db088e7..c13c65b 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -33,6 +33,7 @@ using log4net; using HttpServer; using OpenSim.Framework; using OpenSim.Framework.Monitoring; +using Amib.Threading; /* @@ -185,6 +186,8 @@ namespace OpenSim.Framework.Servers.HttpServer private bool m_running = true; private int slowCount = 0; + private SmartThreadPool m_threadPool = new SmartThreadPool(20000, 12, 2); + // private int m_timeout = 1000; // increase timeout 250; now use the event one public PollServiceRequestManager(BaseHttpServer pSrv, uint pWorkerThreadCount, int pTimeout) @@ -353,18 +356,46 @@ namespace OpenSim.Framework.Servers.HttpServer continue; } - try + // "Normal" means the viewer evebt queue. We need to push these out fast. + // Process them inline. The rest go to the thread pool. + if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.Normal) { - Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, str.ReadToEnd()); - DoHTTPGruntWork(m_server, req, responsedata); + try + { + Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, str.ReadToEnd()); + DoHTTPGruntWork(m_server, req, responsedata); + } + catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream + { + // Ignore it, no need to reply + } + finally + { + str.Close(); + } } - catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream + else { - // Ignore it, no need to reply + m_threadPool.QueueWorkItem(x => + { + try + { + Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, str.ReadToEnd()); + DoHTTPGruntWork(m_server, req, responsedata); + } + catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream + { + // Ignore it, no need to reply + } + finally + { + str.Close(); + } + + return null; + }, null); } - str.Close(); - } else { -- cgit v1.1 From 654dd289f263a4eef4f2aa70a1cb8d289ec7e04c Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 26 Sep 2012 03:05:27 +0100 Subject: more changes to PollService --- .../Servers/HttpServer/PollServiceEventArgs.cs | 1 + .../HttpServer/PollServiceRequestManager.cs | 41 +++++++++------------- 2 files changed, 18 insertions(+), 24 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs index a80b1d7..9b27a6e 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs @@ -47,6 +47,7 @@ namespace OpenSim.Framework.Servers.HttpServer public UUID Id; public int TimeOutms; public EventType Type; + public bool GetEventsNeedsRequest = true; public enum EventType : int { diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index c13c65b..c234537 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -205,7 +205,7 @@ namespace OpenSim.Framework.Servers.HttpServer String.Format("PollServiceWorkerThread{0}", i), ThreadPriority.Normal, false, - true, + false, null, int.MaxValue); } @@ -344,35 +344,36 @@ namespace OpenSim.Framework.Servers.HttpServer { if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id)) { - try + string strreq = ""; + if (req.PollServiceArgs.GetEventsNeedsRequest) { - str = new StreamReader(req.Request.Body); + try + { + str = new StreamReader(req.Request.Body); + strreq = str.ReadToEnd(); + str.Close(); + } + catch + { + continue; + } } - catch (System.ArgumentException) - { - // Stream was not readable means a child agent - // was closed due to logout, leaving the - // Event Queue request orphaned. + + Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, strreq); + + if (responsedata == null) continue; - } - // "Normal" means the viewer evebt queue. We need to push these out fast. - // Process them inline. The rest go to the thread pool. if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.Normal) { try { - Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, str.ReadToEnd()); DoHTTPGruntWork(m_server, req, responsedata); } catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream { // Ignore it, no need to reply } - finally - { - str.Close(); - } } else { @@ -380,27 +381,19 @@ namespace OpenSim.Framework.Servers.HttpServer { try { - Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, str.ReadToEnd()); DoHTTPGruntWork(m_server, req, responsedata); } catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream { // Ignore it, no need to reply } - finally - { - str.Close(); - } return null; }, null); } - } else { -// if ((Environment.TickCount - req.RequestTime) > m_timeout) - if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) { DoHTTPGruntWork(m_server, req, -- cgit v1.1 From 67fa6577461bf1e2a39c501f73d8bfc9045ee69e Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 26 Sep 2012 04:52:19 +0100 Subject: keep watchdog happy using it to kill his threads --- .../Framework/Servers/HttpServer/PollServiceRequestManager.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index c234537..cc9ddc2 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -278,15 +278,7 @@ namespace OpenSim.Framework.Servers.HttpServer Thread.Sleep(1000); // let the world move foreach (Thread t in m_workerThreads) - { - try - { - t.Abort(); - } - catch - { - } - } + Watchdog.AbortThread(t.ManagedThreadId); try { -- cgit v1.1 From 7e3eba1064197024690c5b3cae4c2cf87319e48c Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 26 Sep 2012 15:41:57 +0100 Subject: Seems nothing actually need the request body for getevents. so change control flag to false --- OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs | 10 ++++++++-- .../Framework/Servers/HttpServer/PollServiceRequestManager.cs | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs index 9b27a6e..f85509a 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs @@ -46,8 +46,14 @@ namespace OpenSim.Framework.Servers.HttpServer public RequestMethod Request; public UUID Id; public int TimeOutms; - public EventType Type; - public bool GetEventsNeedsRequest = true; + public EventType Type; + // must be set true for cases where GetEvents needs to access the request body + // at each pool. http can start processing before having the full body + // but not sure if this is active for poll events + // if original coder thinked its needed i keep it + // if the Event has a Request method this seems to smoke for now + // seems for now nothing actually uses this so default to false + public bool GetEventsNeedsRequestBody = false; public enum EventType : int { diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index cc9ddc2..c379747 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -337,10 +337,11 @@ namespace OpenSim.Framework.Servers.HttpServer if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id)) { string strreq = ""; - if (req.PollServiceArgs.GetEventsNeedsRequest) + if (req.PollServiceArgs.GetEventsNeedsRequestBody) { try { + // should we try to seek back? fear we can't str = new StreamReader(req.Request.Body); strreq = str.ReadToEnd(); str.Close(); -- cgit v1.1 From 617f1b9223375a2dda925e26c395901810d37697 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 26 Sep 2012 16:17:49 +0100 Subject: just remove the damm thing --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 1 + .../Servers/HttpServer/PollServiceEventArgs.cs | 9 +-------- .../Servers/HttpServer/PollServiceRequestManager.cs | 18 +----------------- 3 files changed, 3 insertions(+), 25 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 2582b7b..788a0b9 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -317,6 +317,7 @@ namespace OpenSim.Framework.Servers.HttpServer StreamReader reader = new StreamReader(requestStream, encoding); string requestBody = reader.ReadToEnd(); + reader.Close(); Hashtable keysvals = new Hashtable(); Hashtable headervals = new Hashtable(); diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs index f85509a..d0a37d0 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs @@ -34,7 +34,7 @@ namespace OpenSim.Framework.Servers.HttpServer public delegate void RequestMethod(UUID requestID, Hashtable request); public delegate bool HasEventsMethod(UUID requestID, UUID pId); - public delegate Hashtable GetEventsMethod(UUID requestID, UUID pId, string request); + public delegate Hashtable GetEventsMethod(UUID requestID, UUID pId); public delegate Hashtable NoEventsMethod(UUID requestID, UUID pId); @@ -47,13 +47,6 @@ namespace OpenSim.Framework.Servers.HttpServer public UUID Id; public int TimeOutms; public EventType Type; - // must be set true for cases where GetEvents needs to access the request body - // at each pool. http can start processing before having the full body - // but not sure if this is active for poll events - // if original coder thinked its needed i keep it - // if the Event has a Request method this seems to smoke for now - // seems for now nothing actually uses this so default to false - public bool GetEventsNeedsRequestBody = false; public enum EventType : int { diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index c379747..c09bf14 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -336,23 +336,7 @@ namespace OpenSim.Framework.Servers.HttpServer { if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id)) { - string strreq = ""; - if (req.PollServiceArgs.GetEventsNeedsRequestBody) - { - try - { - // should we try to seek back? fear we can't - str = new StreamReader(req.Request.Body); - strreq = str.ReadToEnd(); - str.Close(); - } - catch - { - continue; - } - } - - Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, strreq); + Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id); if (responsedata == null) continue; -- cgit v1.1 From a0065ad61611b1a078116327f826b109bd90dba4 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 27 Sep 2012 00:14:50 +0100 Subject: create a new PollServiceHttpRequest req per loop since they can be sent to another working thread --- OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index c09bf14..4be8bf4 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -321,13 +321,9 @@ namespace OpenSim.Framework.Servers.HttpServer private void PoolWorkerJob() { - PollServiceHttpRequest req; - StreamReader str; - -// while (true) while (m_running) { - req = m_requests.Dequeue(5000); + PollServiceHttpRequest req = m_requests.Dequeue(5000); Watchdog.UpdateThread(); if (req != null) -- cgit v1.1 From cda127e30f0049cda21137363e4d759fd7fd4959 Mon Sep 17 00:00:00 2001 From: teravus Date: Fri, 9 Nov 2012 23:55:30 -0500 Subject: * Prep work switching the GetMeshModule over to a poll service. * This still has the image throttler in it.. as is... so it's not suitable for live yet.... The throttler keeps track of the task throttle but doesn't balance the UDP throttle yet. --- OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs index d0a37d0..c19ac32 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs @@ -53,7 +53,8 @@ namespace OpenSim.Framework.Servers.HttpServer Normal = 0, LslHttp = 1, Inventory = 2, - Texture = 3 + Texture = 3, + Mesh = 4 } public PollServiceEventArgs( -- cgit v1.1 From e39156c6569b10d48b0005b271f103387e16f527 Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 25 Apr 2013 01:38:21 +0200 Subject: Send 503 when throttling textures --- OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 07bd48a..7628e23 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -345,7 +345,7 @@ namespace OpenSim.Framework.Servers.HttpServer if (responsedata == null) continue; - if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.Normal) + if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.Normal) // This is the event queue { try { -- cgit v1.1 From 17a902fed44ec3c28ee71dc686faeb00162bad73 Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 7 Jun 2013 22:39:27 +0200 Subject: Clean up poll service --- .../HttpServer/PollServiceRequestManager.cs | 144 ----------------- .../Servers/HttpServer/PollServiceWorkerThread.cs | 175 --------------------- 2 files changed, 319 deletions(-) delete mode 100644 OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 7628e23..5406f00 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -34,143 +34,6 @@ using HttpServer; using OpenSim.Framework; using OpenSim.Framework.Monitoring; using Amib.Threading; - - -/* -namespace OpenSim.Framework.Servers.HttpServer -{ - - public class PollServiceRequestManager - { -// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private readonly BaseHttpServer m_server; - private static Queue m_requests = Queue.Synchronized(new Queue()); - private static ManualResetEvent m_ev = new ManualResetEvent(false); - private uint m_WorkerThreadCount = 0; - private Thread[] m_workerThreads; - private PollServiceWorkerThread[] m_PollServiceWorkerThreads; - private volatile bool m_running = true; - private int m_pollTimeout; - - public PollServiceRequestManager(BaseHttpServer pSrv, uint pWorkerThreadCount, int pTimeout) - { - m_server = pSrv; - m_WorkerThreadCount = pWorkerThreadCount; - m_pollTimeout = pTimeout; - } - - public void Start() - { - m_running = true; - m_workerThreads = new Thread[m_WorkerThreadCount]; - m_PollServiceWorkerThreads = new PollServiceWorkerThread[m_WorkerThreadCount]; - - //startup worker threads - for (uint i = 0; i < m_WorkerThreadCount; i++) - { - m_PollServiceWorkerThreads[i] = new PollServiceWorkerThread(m_server, m_pollTimeout); - m_PollServiceWorkerThreads[i].ReQueue += ReQueueEvent; - - m_workerThreads[i] - = Watchdog.StartThread( - m_PollServiceWorkerThreads[i].ThreadStart, - String.Format("PollServiceWorkerThread{0}", i), - ThreadPriority.Normal, - false, - true, - int.MaxValue); - } - - Watchdog.StartThread( - this.ThreadStart, - "PollServiceWatcherThread", - ThreadPriority.Normal, - false, - true, - 1000 * 60 * 10); - } - - internal void ReQueueEvent(PollServiceHttpRequest req) - { - // Do accounting stuff here - Enqueue(req); - } - - public void Enqueue(PollServiceHttpRequest req) - { - lock (m_requests) - m_requests.Enqueue(req); - m_ev.Set(); - } - - public void ThreadStart() - { - while (m_running) - { - m_ev.WaitOne(1000); - m_ev.Reset(); - Watchdog.UpdateThread(); - ProcessQueuedRequests(); - } - } - - private void ProcessQueuedRequests() - { - lock (m_requests) - { - if (m_requests.Count == 0) - return; - -// m_log.DebugFormat("[POLL SERVICE REQUEST MANAGER]: Processing {0} requests", m_requests.Count); - - int reqperthread = (int) (m_requests.Count/m_WorkerThreadCount) + 1; - - // For Each WorkerThread - for (int tc = 0; tc < m_WorkerThreadCount && m_requests.Count > 0; tc++) - { - //Loop over number of requests each thread handles. - for (int i = 0; i < reqperthread && m_requests.Count > 0; i++) - { - try - { - m_PollServiceWorkerThreads[tc].Enqueue((PollServiceHttpRequest)m_requests.Dequeue()); - } - catch (InvalidOperationException) - { - // The queue is empty, we did our calculations wrong! - return; - } - - } - } - } - - } - - public void Stop() - { - m_running = false; - - foreach (object o in m_requests) - { - PollServiceHttpRequest req = (PollServiceHttpRequest) o; - m_server.DoHTTPGruntWork( - req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id), - new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext)); - } - - m_requests.Clear(); - - foreach (Thread t in m_workerThreads) - { - t.Abort(); - } - } - } -} - */ - using System.IO; using System.Text; using System.Collections.Generic; @@ -196,8 +59,6 @@ namespace OpenSim.Framework.Servers.HttpServer private SmartThreadPool m_threadPool = new SmartThreadPool(20000, 12, 2); -// private int m_timeout = 1000; // increase timeout 250; now use the event one - public PollServiceRequestManager(BaseHttpServer pSrv, uint pWorkerThreadCount, int pTimeout) { m_server = pSrv; @@ -282,7 +143,6 @@ namespace OpenSim.Framework.Servers.HttpServer ~PollServiceRequestManager() { m_running = false; -// m_timeout = -10000; // cause all to expire Thread.Sleep(1000); // let the world move foreach (Thread t in m_workerThreads) @@ -418,14 +278,10 @@ namespace OpenSim.Framework.Servers.HttpServer } finally { - //response.OutputStream.Close(); try { response.OutputStream.Flush(); response.Send(); - - //if (!response.KeepAlive && response.ReuseContext) - // response.FreeContext(); } catch (Exception e) { diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs deleted file mode 100644 index 1c529b6..0000000 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* Ubit work moved to PollServiceRequestManager - -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Text; -using HttpServer; -using OpenMetaverse; -using System.Reflection; -using log4net; -using OpenSim.Framework.Monitoring; - -namespace OpenSim.Framework.Servers.HttpServer -{ - public delegate void ReQueuePollServiceItem(PollServiceHttpRequest req); - - public class PollServiceWorkerThread - { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); - - public event ReQueuePollServiceItem ReQueue; - - private readonly BaseHttpServer m_server; - private BlockingQueue m_request; - private bool m_running = true; - private int m_timeout = 250; - - public PollServiceWorkerThread(BaseHttpServer pSrv, int pTimeout) - { - m_request = new BlockingQueue(); - m_server = pSrv; - m_timeout = pTimeout; - } - - public void ThreadStart() - { - Run(); - } - - public void Run() - { - while (m_running) - { - PollServiceHttpRequest req = m_request.Dequeue(); - - Watchdog.UpdateThread(); - - try - { - if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id)) - { - StreamReader str; - try - { - str = new StreamReader(req.Request.Body); - } - catch (System.ArgumentException) - { - // Stream was not readable means a child agent - // was closed due to logout, leaving the - // Event Queue request orphaned. - continue; - } - - try - { - Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, str.ReadToEnd()); - DoHTTPGruntWork(m_server, req, responsedata); - } - catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream - { - // Ignore it, no need to reply - } - } - else - { - if ((Environment.TickCount - req.RequestTime) > m_timeout) - { - DoHTTPGruntWork( - m_server, - req, - req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); - } - else - { - ReQueuePollServiceItem reQueueItem = ReQueue; - if (reQueueItem != null) - reQueueItem(req); - } - } - } - catch (Exception e) - { - m_log.ErrorFormat("Exception in poll service thread: " + e.ToString()); - } - } - } - - internal void Enqueue(PollServiceHttpRequest pPollServiceHttpRequest) - { - m_request.Enqueue(pPollServiceHttpRequest); - } - - /// - /// FIXME: This should be part of BaseHttpServer - /// - internal static void DoHTTPGruntWork(BaseHttpServer server, PollServiceHttpRequest req, Hashtable responsedata) - { - OSHttpResponse response - = new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext); - - byte[] buffer = server.DoHTTPGruntWork(responsedata, response); - - response.SendChunked = false; - response.ContentLength64 = buffer.Length; - response.ContentEncoding = Encoding.UTF8; - - try - { - response.OutputStream.Write(buffer, 0, buffer.Length); - } - catch (Exception ex) - { - m_log.Warn(string.Format("[POLL SERVICE WORKER THREAD]: Error ", ex)); - } - finally - { - //response.OutputStream.Close(); - try - { - response.OutputStream.Flush(); - response.Send(); - - //if (!response.KeepAlive && response.ReuseContext) - // response.FreeContext(); - } - catch (Exception e) - { - m_log.Warn(String.Format("[POLL SERVICE WORKER THREAD]: Error ", e)); - } - } - } - } -} -*/ \ No newline at end of file -- cgit v1.1 From ece2d24077cacba677de5cebdd3a9da463306ecd Mon Sep 17 00:00:00 2001 From: teravus Date: Sat, 5 Oct 2013 17:36:58 -0500 Subject: * Fixes cases where Last Attachment Point gets overwritten with 0 when it shouldn't * Fixes cases where Last Attachment Point doesn't get written when it should. * Fixes Null Reference in BaseHttpServer when shutting down, null path provided. * Drop then Wear retains Last Attachment Point --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index ed733cf..5681ece 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -1967,6 +1967,7 @@ namespace OpenSim.Framework.Servers.HttpServer public void RemoveHTTPHandler(string httpMethod, string path) { + if (path == null) return; // Caps module isn't loaded, tries to remove handler where path = null lock (m_HTTPHandlers) { if (httpMethod != null && httpMethod.Length == 0) -- cgit v1.1 From f236b2e5d3f8ba02d3db8ec35d74887723d1ee7b Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 23 Jul 2014 02:14:15 +0100 Subject: request.DoHTTPGruntWork(..) is now identical to our version, so use those again, getting code closer to os again --- .../HttpServer/PollServiceRequestManager.cs | 45 +++------------------- 1 file changed, 5 insertions(+), 40 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 44f7045..21e52ca 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -154,7 +154,7 @@ namespace OpenSim.Framework.Servers.HttpServer { foreach (PollServiceHttpRequest req in m_retryRequests) { - DoHTTPGruntWork(m_server,req, + req.DoHTTPGruntWork(m_server, req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); } } @@ -176,7 +176,7 @@ namespace OpenSim.Framework.Servers.HttpServer try { wreq = m_requests.Dequeue(0); - DoHTTPGruntWork(m_server,wreq, + wreq.DoHTTPGruntWork(m_server, wreq.PollServiceArgs.NoEvents(wreq.RequestID, wreq.PollServiceArgs.Id)); } catch @@ -211,7 +211,7 @@ namespace OpenSim.Framework.Servers.HttpServer { try { - DoHTTPGruntWork(m_server, req, responsedata); + req.DoHTTPGruntWork(m_server, responsedata); } catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream { @@ -224,7 +224,7 @@ namespace OpenSim.Framework.Servers.HttpServer { try { - DoHTTPGruntWork(m_server, req, responsedata); + req.DoHTTPGruntWork(m_server, responsedata); } catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream { @@ -239,7 +239,7 @@ namespace OpenSim.Framework.Servers.HttpServer { if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) { - DoHTTPGruntWork(m_server, req, + req.DoHTTPGruntWork(m_server, req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); } else @@ -256,41 +256,6 @@ namespace OpenSim.Framework.Servers.HttpServer } } - // DoHTTPGruntWork changed, not sending response - // do the same work around as core - - internal static void DoHTTPGruntWork(BaseHttpServer server, PollServiceHttpRequest req, Hashtable responsedata) - { - OSHttpResponse response - = new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext); - - byte[] buffer = server.DoHTTPGruntWork(responsedata, response); - - response.SendChunked = false; - response.ContentLength64 = buffer.Length; - response.ContentEncoding = Encoding.UTF8; - - try - { - response.OutputStream.Write(buffer, 0, buffer.Length); - } - catch (Exception ex) - { - m_log.Warn(string.Format("[POLL SERVICE WORKER THREAD]: Error ", ex)); - } - finally - { - try - { - response.OutputStream.Flush(); - response.Send(); - } - catch (Exception e) - { - m_log.Warn(String.Format("[POLL SERVICE WORKER THREAD]: Error ", e)); - } - } - } } } -- cgit v1.1 From 86a9710e77b76fb8a37faf9dacd22a0973628d92 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 24 Jul 2014 23:32:39 +0100 Subject: change previus code, send a NoEvents response back to http server, even if we know there is no one there, so that the server finishes handling it. --- OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | 3 --- 1 file changed, 3 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 21e52ca..4058229 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -204,9 +204,6 @@ namespace OpenSim.Framework.Servers.HttpServer { Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id); - if (responsedata == null) - continue; - if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LongPoll) // This is the event queue { try -- cgit v1.1 From 8558e97a44048e2d15c58e6d994c317d58154642 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 13 Oct 2014 11:38:51 +0100 Subject: tune poll smartThreadpool use and give it a name --- OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 4058229..51a1136 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -57,24 +57,27 @@ namespace OpenSim.Framework.Servers.HttpServer private bool m_running = true; private int slowCount = 0; - private SmartThreadPool m_threadPool = new SmartThreadPool(20000, 12, 2); + private SmartThreadPool m_threadPool; public PollServiceRequestManager(BaseHttpServer pSrv, uint pWorkerThreadCount, int pTimeout) { m_server = pSrv; m_WorkerThreadCount = pWorkerThreadCount; m_workerThreads = new Thread[m_WorkerThreadCount]; + m_threadPool = new SmartThreadPool(30000, 15, 1); + m_threadPool.Name = "PoolService"; } public void Start() { + m_threadPool.Start(); //startup worker threads for (uint i = 0; i < m_WorkerThreadCount; i++) { m_workerThreads[i] = Watchdog.StartThread( PoolWorkerJob, - string.Format("PollServiceWorkerThread{0}:{1}", i, m_server.Port), + string.Format("PollServiceWorkerThread {0}:{1}", i, m_server.Port), ThreadPriority.Normal, false, false, -- cgit v1.1 From cd87c4bec5490311d47e401acab3915f394f1a22 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 13 Oct 2014 12:00:31 +0100 Subject: change/fix previus commits --- .../Servers/HttpServer/PollServiceRequestManager.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 51a1136..e75b705 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -64,8 +64,16 @@ namespace OpenSim.Framework.Servers.HttpServer m_server = pSrv; m_WorkerThreadCount = pWorkerThreadCount; m_workerThreads = new Thread[m_WorkerThreadCount]; - m_threadPool = new SmartThreadPool(30000, 15, 1); - m_threadPool.Name = "PoolService"; + + STPStartInfo startInfo = new STPStartInfo(); + startInfo.IdleTimeout = 30000; + startInfo.MaxWorkerThreads = 15; + startInfo.MinWorkerThreads = 1; + startInfo.ThreadPriority = ThreadPriority.Normal; + startInfo.StartSuspended = true; + startInfo.ThreadPoolName = "PoolService"; + + m_threadPool = new SmartThreadPool(startInfo); } public void Start() -- cgit v1.1 From fd79f75ba6766e1edc196a73dd05fc5f806f82b2 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 24 Oct 2014 02:12:30 +0100 Subject: TEST**** wingridproxy detection at grid login. Untested possible not very reliable. Adds some load even on region servers because of code at BaseHttpServer. --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 7841f47..799ab80 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -966,6 +966,19 @@ namespace OpenSim.Framework.Servers.HttpServer string responseString = String.Empty; XmlRpcRequest xmlRprcRequest = null; + bool gridproxy = false; + if (requestBody.Contains("encoding=\"utf-8")) + { + int channelindx = -1; + int optionsindx = requestBody.IndexOf(">options<"); + if(optionsindx >0) + { + channelindx = requestBody.IndexOf(">channel<"); + if (optionsindx < channelindx) + gridproxy = true; + } + } + try { xmlRprcRequest = (XmlRpcRequest) (new XmlRpcRequestDeserializer()).Deserialize(requestBody); @@ -1023,6 +1036,8 @@ namespace OpenSim.Framework.Servers.HttpServer } xmlRprcRequest.Params.Add(request.Headers.Get(xff)); // Param[3] + if (gridproxy) + xmlRprcRequest.Params.Add("gridproxy"); // Param[4] try { xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint); -- cgit v1.1 From 2cac56340a079fad8a16736778b6ebef78fb6d56 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 18 Aug 2015 21:03:34 +0100 Subject: try to serialize http requests from same connection, so they are processed in order. ( next commits will be about necessary keepAlive changes needed) --- .../Servers/HttpServer/PollServiceHttpRequest.cs | 38 ++++++++++++++++++ .../HttpServer/PollServiceRequestManager.cs | 46 ++++++++++++++++++++++ 2 files changed, 84 insertions(+) (limited to 'OpenSim/Framework/Servers/HttpServer') 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 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Reflection; using System.Text; using HttpServer; @@ -44,6 +45,24 @@ namespace OpenSim.Framework.Servers.HttpServer public readonly IHttpRequest Request; public readonly int RequestTime; public readonly UUID RequestID; + public int contextHash; + + private void GenContextHash() + { + Random rnd = new Random(); + contextHash = 0; + if (Request.Headers["remote_addr"] != null) + contextHash = (Request.Headers["remote_addr"]).GetHashCode() << 16; + else + contextHash = rnd.Next() << 16; + if (Request.Headers["remote_port"] != null) + { + string[] strPorts = Request.Headers["remote_port"].Split(new char[] { ',' }); + contextHash += Int32.Parse(strPorts[0]); + } + else + contextHash += rnd.Next() & 0xffff; + } public PollServiceHttpRequest( PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest) @@ -53,6 +72,7 @@ namespace OpenSim.Framework.Servers.HttpServer Request = pRequest; RequestTime = System.Environment.TickCount; RequestID = UUID.Random(); + GenContextHash(); } internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata) @@ -65,6 +85,7 @@ namespace OpenSim.Framework.Servers.HttpServer response.SendChunked = false; response.ContentLength64 = buffer.Length; response.ContentEncoding = Encoding.UTF8; + response.ReuseContext = false; try { @@ -93,5 +114,22 @@ namespace OpenSim.Framework.Servers.HttpServer PollServiceArgs.RequestsHandled++; } } + + } + + class PollServiceHttpRequestComparer : IEqualityComparer + { + public bool Equals(PollServiceHttpRequest b1, PollServiceHttpRequest b2) + { + if (b1.contextHash != b2.contextHash) + return false; + bool b = Object.ReferenceEquals(b1.HttpContext, b2.HttpContext); + return b; + } + + public int GetHashCode(PollServiceHttpRequest b2) + { + return (int)b2.contextHash; + } } } \ 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 private readonly BaseHttpServer m_server; + private Dictionary> m_bycontext; private BlockingQueue m_requests = new BlockingQueue(); private static Queue m_slowRequests = new Queue(); private static Queue m_retryRequests = new Queue(); @@ -65,6 +66,9 @@ namespace OpenSim.Framework.Servers.HttpServer m_WorkerThreadCount = pWorkerThreadCount; m_workerThreads = new Thread[m_WorkerThreadCount]; + PollServiceHttpRequestComparer preqCp = new PollServiceHttpRequestComparer(); + m_bycontext = new Dictionary>(preqCp); + STPStartInfo startInfo = new STPStartInfo(); startInfo.IdleTimeout = 30000; startInfo.MaxWorkerThreads = 15; @@ -114,6 +118,45 @@ namespace OpenSim.Framework.Servers.HttpServer public void Enqueue(PollServiceHttpRequest req) { + lock (m_bycontext) + { + Queue ctxQeueue; + if (m_bycontext.TryGetValue(req, out ctxQeueue)) + { + ctxQeueue.Enqueue(req); + } + else + { + ctxQeueue = new Queue(); + m_bycontext[req] = ctxQeueue; + EnqueueInt(req); + } + } + } + + public void byContextDequeue(PollServiceHttpRequest req) + { + Queue ctxQeueue; + lock (m_bycontext) + { + if (m_bycontext.TryGetValue(req, out ctxQeueue)) + { + if (ctxQeueue.Count > 0) + { + PollServiceHttpRequest newreq = ctxQeueue.Dequeue(); + EnqueueInt(newreq); + } + else + { + m_bycontext.Remove(req); + } + } + } + } + + + public void EnqueueInt(PollServiceHttpRequest req) + { if (m_running) { if (req.PollServiceArgs.Type != PollServiceEventArgs.EventType.LongPoll) @@ -220,6 +263,7 @@ namespace OpenSim.Framework.Servers.HttpServer try { req.DoHTTPGruntWork(m_server, responsedata); + byContextDequeue(req); } catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream { @@ -233,6 +277,7 @@ namespace OpenSim.Framework.Servers.HttpServer try { req.DoHTTPGruntWork(m_server, responsedata); + byContextDequeue(req); } catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream { @@ -249,6 +294,7 @@ namespace OpenSim.Framework.Servers.HttpServer { req.DoHTTPGruntWork(m_server, req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); + byContextDequeue(req); } else { -- cgit v1.1 From 05d72f77ff38585817dead9b4a812ff97a001dce Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 18 Aug 2015 21:32:03 +0100 Subject: do keepalive on mesh and texture GET. Dont use reusecontext any where. setting of keepalive is wrong, it should follow the requested one ( or always as http1.1) only deny if needed (errors). KeepAlive may increase stress on number of avaiable file descritors. --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 799ab80..1363eab 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -459,7 +459,7 @@ namespace OpenSim.Framework.Servers.HttpServer } OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context); - resp.ReuseContext = true; + resp.ReuseContext = false; HandleRequest(req, resp); // !!!HACK ALERT!!! -- cgit v1.1 From 48ef22f62e07c0b9e6d23ee758a4800d05cfb231 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 18 Aug 2015 23:59:55 +0100 Subject: change pollService stop() to send 503 error and no keepalive. ( untested ) --- .../Servers/HttpServer/PollServiceHttpRequest.cs | 24 +++++++++++++++++++++- .../HttpServer/PollServiceRequestManager.cs | 14 ++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs index e636c38..5bd63a6 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs @@ -114,7 +114,29 @@ namespace OpenSim.Framework.Servers.HttpServer PollServiceArgs.RequestsHandled++; } } - + + internal void DoHTTPstop(BaseHttpServer server) + { + OSHttpResponse response + = new OSHttpResponse(new HttpResponse(HttpContext, Request), HttpContext); + + response.SendChunked = false; + response.ContentLength64 = 0; + response.ContentEncoding = Encoding.UTF8; + response.ReuseContext = false; + response.KeepAlive = false; + response.SendChunked = false; + response.StatusCode = 503; + + try + { + response.OutputStream.Flush(); + response.Send(); + } + catch (Exception e) + { + } + } } class PollServiceHttpRequestComparer : IEqualityComparer diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 2c5c41d..b56ade8 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -204,12 +204,17 @@ namespace OpenSim.Framework.Servers.HttpServer foreach (Thread t in m_workerThreads) Watchdog.AbortThread(t.ManagedThreadId); + // any entry in m_bycontext should have a active request on the other queues + // so just delete contents to easy GC + foreach (Queue qu in m_bycontext.Values) + qu.Clear(); + m_bycontext.Clear(); + try { foreach (PollServiceHttpRequest req in m_retryRequests) { - req.DoHTTPGruntWork(m_server, - req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); + req.DoHTTPstop(m_server); } } catch @@ -221,7 +226,7 @@ namespace OpenSim.Framework.Servers.HttpServer lock (m_slowRequests) { - while (m_slowRequests.Count > 0 && m_running) + while (m_slowRequests.Count > 0) m_requests.Enqueue(m_slowRequests.Dequeue()); } @@ -230,8 +235,7 @@ namespace OpenSim.Framework.Servers.HttpServer try { wreq = m_requests.Dequeue(0); - wreq.DoHTTPGruntWork(m_server, - wreq.PollServiceArgs.NoEvents(wreq.RequestID, wreq.PollServiceArgs.Id)); + wreq.DoHTTPstop(m_server); } catch { -- cgit v1.1