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 +++++++++++++++++++++ 1 file changed, 203 insertions(+) (limited to 'OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs') 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()); + } + } + } + } + } +} + -- 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/PollServiceRequestManager.cs') 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/PollServiceRequestManager.cs') 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 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/PollServiceRequestManager.cs') 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. --- .../HttpServer/PollServiceRequestManager.cs | 37 +++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs') 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/PollServiceRequestManager.cs') 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/PollServiceRequestManager.cs') 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