From 6a02ac634b99468a0df62cdf43254020488fcb7b Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 17 Jul 2016 11:39:38 +0100 Subject: identify contexts by ID now avaiable ( pipeline serialization) --- .../Framework/Servers/HttpServer/PollServiceHttpRequest.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs index 0e4a941..9083e12 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs @@ -47,8 +47,10 @@ namespace OpenSim.Framework.Servers.HttpServer public readonly UUID RequestID; public int contextHash; +/* private void GenContextHash() { + Random rnd = new Random(); contextHash = 0; if (Request.Headers["remote_addr"] != null) @@ -62,8 +64,9 @@ namespace OpenSim.Framework.Servers.HttpServer } else contextHash += rnd.Next() & 0xffff; - } + } +*/ public PollServiceHttpRequest( PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest) { @@ -72,7 +75,8 @@ namespace OpenSim.Framework.Servers.HttpServer Request = pRequest; RequestTime = System.Environment.TickCount; RequestID = UUID.Random(); - GenContextHash(); +// GenContextHash(); + contextHash = HttpContext.contextID; } internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata) @@ -132,8 +136,9 @@ namespace OpenSim.Framework.Servers.HttpServer { if (b1.contextHash != b2.contextHash) return false; - bool b = Object.ReferenceEquals(b1.HttpContext, b2.HttpContext); - return b; +// bool b = Object.ReferenceEquals(b1.HttpContext, b2.HttpContext); +// return b; + return true; } public int GetHashCode(PollServiceHttpRequest b2) -- cgit v1.1 From 442b27222828381a27c7c5eddc967a0de4c82d0a Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 17 Jul 2016 13:20:56 +0100 Subject: add a Drop method to PollService Event handlers, Drop requests on connections known to be lost or delay event check if they are sending a response --- OpenSim/Framework/Console/RemoteConsole.cs | 11 ++- .../Servers/HttpServer/PollServiceEventArgs.cs | 5 +- .../HttpServer/PollServiceRequestManager.cs | 95 ++++++++++++++-------- 3 files changed, 77 insertions(+), 34 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Console/RemoteConsole.cs b/OpenSim/Framework/Console/RemoteConsole.cs index 8ad7b0d..4b88923 100644 --- a/OpenSim/Framework/Console/RemoteConsole.cs +++ b/OpenSim/Framework/Console/RemoteConsole.cs @@ -234,7 +234,7 @@ namespace OpenSim.Framework.Console string uri = "/ReadResponses/" + sessionID.ToString() + "/"; m_Server.AddPollServiceHTTPHandler( - uri, new PollServiceEventArgs(null, uri, HasEvents, GetEvents, NoEvents, sessionID,25000)); // 25 secs timeout + uri, new PollServiceEventArgs(null, uri, HasEvents, GetEvents, NoEvents, Drop, sessionID, 25000)); // 25 secs timeout XmlDocument xmldoc = new XmlDocument(); XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, @@ -425,6 +425,15 @@ namespace OpenSim.Framework.Console return false; } + private void Drop(UUID RequestID, UUID sessionID) + { + lock (m_Connections) + { + if (m_Connections.ContainsKey(sessionID)) + m_Connections.Remove(sessionID); + } + } + private Hashtable GetEvents(UUID RequestID, UUID sessionID) { ConsoleConnection c = null; diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs index 3fd3bf7..a9860cc 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs @@ -37,6 +37,7 @@ namespace OpenSim.Framework.Servers.HttpServer public delegate Hashtable GetEventsMethod(UUID requestID, UUID pId); public delegate Hashtable NoEventsMethod(UUID requestID, UUID pId); + public delegate void DropMethod(UUID requestID, UUID pId); public class PollServiceEventArgs : EventArgs { @@ -44,6 +45,7 @@ namespace OpenSim.Framework.Servers.HttpServer public GetEventsMethod GetEvents; public NoEventsMethod NoEvents; public RequestMethod Request; + public DropMethod Drop; public UUID Id; public int TimeOutms; public EventType Type; @@ -73,13 +75,14 @@ namespace OpenSim.Framework.Servers.HttpServer RequestMethod pRequest, string pUrl, HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents, - UUID pId, int pTimeOutms) + DropMethod pDrop, UUID pId, int pTimeOutms) { Request = pRequest; Url = pUrl; HasEvents = pHasEvents; GetEvents = pGetEvents; NoEvents = pNoEvents; + Drop = pDrop; Id = pId; TimeOutms = pTimeOutms; Type = EventType.LongPoll; diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index ffcad0f..5b40590 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -160,6 +160,19 @@ namespace OpenSim.Framework.Servers.HttpServer } } + public void DropByContext(PollServiceHttpRequest req) + { + Queue ctxQeueue; + lock (m_bycontext) + { + if (m_bycontext.TryGetValue(req, out ctxQeueue)) + { + ctxQeueue.Clear(); + m_bycontext.Remove(req); + } + } + } + public void EnqueueInt(PollServiceHttpRequest req) { if (m_running) @@ -263,22 +276,61 @@ namespace OpenSim.Framework.Servers.HttpServer PollServiceHttpRequest req = m_requests.Dequeue(5000); Watchdog.UpdateThread(); - if (req != null) + if(req == null) + continue; + + try { - try + if(!req.HttpContext.CanSend()) { - if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id)) + req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id); + byContextDequeue(req); + continue; + } + + if(req.HttpContext.IsSending()) + { + if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) { - Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id); + req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id); + byContextDequeue(req); + } + else + ReQueueEvent(req); + continue; + } + if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id)) + { + Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id); + + m_threadPool.QueueWorkItem(x => + { + try + { + req.DoHTTPGruntWork(m_server, responsedata); + byContextDequeue(req); + } + catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream + { + // Ignore it, no need to reply + } + return null; + }, null); + } + else + { + if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) + { m_threadPool.QueueWorkItem(x => { try { - req.DoHTTPGruntWork(m_server, responsedata); + req.DoHTTPGruntWork(m_server, + req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); byContextDequeue(req); } - catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream + catch (ObjectDisposedException) { // Ignore it, no need to reply } @@ -287,36 +339,15 @@ namespace OpenSim.Framework.Servers.HttpServer } else { - if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) - { - m_threadPool.QueueWorkItem(x => - { - try - { - req.DoHTTPGruntWork(m_server, - req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); - byContextDequeue(req); - } - catch (ObjectDisposedException) - { - // Ignore it, no need to reply - } - return null; - }, null); - } - else - { - ReQueueEvent(req); - } + ReQueueEvent(req); } } - catch (Exception e) - { - m_log.ErrorFormat("Exception in poll service thread: " + e.ToString()); - } + } + catch (Exception e) + { + m_log.ErrorFormat("Exception in poll service thread: " + e.ToString()); } } } - } } -- cgit v1.1 From 79e464f33fa60e5164874e4c3e2a189c52924ae1 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 17 Jul 2016 16:16:24 +0100 Subject: dont try dequeues if didnt reacquired lock --- OpenSim/Framework/BlockingQueue.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/BlockingQueue.cs b/OpenSim/Framework/BlockingQueue.cs index daf99a8..f6861e4 100644 --- a/OpenSim/Framework/BlockingQueue.cs +++ b/OpenSim/Framework/BlockingQueue.cs @@ -78,7 +78,8 @@ namespace OpenSim.Framework { if (m_queue.Count < 1 && m_pqueue.Count < 1) { - Monitor.Wait(m_queueSync, msTimeout); + if(!Monitor.Wait(m_queueSync, msTimeout)) + return default(T); } if (m_pqueue.Count > 0) -- cgit v1.1