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/PollServiceRequestManager.cs') 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 --- .../HttpServer/PollServiceRequestManager.cs | 41 +++++++++------------- 1 file changed, 17 insertions(+), 24 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 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/PollServiceRequestManager.cs') 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/PollServiceRequestManager.cs | 3 ++- 1 file changed, 2 insertions(+), 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 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 --- .../Servers/HttpServer/PollServiceRequestManager.cs | 18 +----------------- 1 file changed, 1 insertion(+), 17 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 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/PollServiceRequestManager.cs') 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