From 1b7b664c8696531fec26378d1386362d8a3da55e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 15 Jul 2013 23:22:39 +0100 Subject: Add request received/handling stats for caps which are served by http poll handlers. This adds explicit cap poll handler supporting to the Caps classes rather than relying on callers to do the complicated coding. Other refactoring was required to get logic into the right places to support this. --- .../Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 13 +-- .../Linden/Caps/EventQueue/EventQueueGetModule.cs | 2 +- .../Linden/Caps/WebFetchInvDescModule.cs | 66 ++++++++-------- .../Framework/Caps/CapabilitiesModule.cs | 92 +++++++++++++++++----- .../CoreModules/Scripting/LSLHttp/UrlModule.cs | 6 +- 5 files changed, 110 insertions(+), 69 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index 5c6bc1c..1d4c7f0 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs @@ -285,18 +285,7 @@ namespace OpenSim.Region.ClientStack.Linden foreach (OSD c in capsRequested) validCaps.Add(c.AsString()); - Hashtable caps = m_HostCapsObj.CapsHandlers.GetCapsDetails(true, validCaps); - - // Add the external too - foreach (KeyValuePair kvp in m_HostCapsObj.ExternalCapsHandlers) - { - if (!validCaps.Contains(kvp.Key)) - continue; - - caps[kvp.Key] = kvp.Value; - } - - string result = LLSDHelpers.SerialiseLLSDReply(caps); + string result = LLSDHelpers.SerialiseLLSDReply(m_HostCapsObj.GetCapsDetails(true, validCaps)); //m_log.DebugFormat("[CAPS] CapsRequest {0}", result); diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs index 50bfda1..ca38a97 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs @@ -377,7 +377,7 @@ namespace OpenSim.Region.ClientStack.Linden // TODO: Add EventQueueGet name/description for diagnostics MainServer.Instance.AddPollServiceHTTPHandler( eventQueueGetPath, - new PollServiceEventArgs(null, HasEvents, GetEvents, NoEvents, agentID, 40000)); + new PollServiceEventArgs(null, eventQueueGetPath, HasEvents, GetEvents, NoEvents, agentID, 40000)); // m_log.DebugFormat( // "[EVENT QUEUE GET MODULE]: Registered EQG handler {0} for {1} in {2}", diff --git a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs index b90df17..86a0298 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs @@ -77,7 +77,6 @@ namespace OpenSim.Region.ClientStack.Linden private static WebFetchInvDescHandler m_webFetchHandler; - private Dictionary m_capsDict = new Dictionary(); private static Thread[] m_workerThreads = null; private static DoubleQueue m_queue = @@ -114,7 +113,6 @@ namespace OpenSim.Region.ClientStack.Linden return; m_scene.EventManager.OnRegisterCaps -= RegisterCaps; - m_scene.EventManager.OnDeregisterCaps -= DeregisterCaps; foreach (Thread t in m_workerThreads) Watchdog.AbortThread(t.ManagedThreadId); @@ -134,7 +132,6 @@ namespace OpenSim.Region.ClientStack.Linden m_webFetchHandler = new WebFetchInvDescHandler(m_InventoryService, m_LibraryService); m_scene.EventManager.OnRegisterCaps += RegisterCaps; - m_scene.EventManager.OnDeregisterCaps += DeregisterCaps; if (m_workerThreads == null) { @@ -177,8 +174,8 @@ namespace OpenSim.Region.ClientStack.Linden private Scene m_scene; - public PollServiceInventoryEventArgs(Scene scene, UUID pId) : - base(null, null, null, null, pId, int.MaxValue) + public PollServiceInventoryEventArgs(Scene scene, string url, UUID pId) : + base(null, url, null, null, null, pId, int.MaxValue) { m_scene = scene; @@ -308,40 +305,39 @@ namespace OpenSim.Region.ClientStack.Linden if (m_fetchInventoryDescendents2Url == "") return; - string capUrl = "/CAPS/" + UUID.Random() + "/"; - // Register this as a poll service - PollServiceInventoryEventArgs args = new PollServiceInventoryEventArgs(m_scene, agentID); - + PollServiceInventoryEventArgs args + = new PollServiceInventoryEventArgs(m_scene, "/CAPS/" + UUID.Random() + "/", agentID); args.Type = PollServiceEventArgs.EventType.Inventory; - MainServer.Instance.AddPollServiceHTTPHandler(capUrl, args); - - string hostName = m_scene.RegionInfo.ExternalHostName; - uint port = (MainServer.Instance == null) ? 0 : MainServer.Instance.Port; - string protocol = "http"; - - if (MainServer.Instance.UseSSL) - { - hostName = MainServer.Instance.SSLCommonName; - port = MainServer.Instance.SSLPort; - protocol = "https"; - } - - caps.RegisterHandler("FetchInventoryDescendents2", String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, capUrl)); - m_capsDict[agentID] = capUrl; + caps.RegisterPollHandler("FetchInventoryDescendents2", args); + +// MainServer.Instance.AddPollServiceHTTPHandler(capUrl, args); +// +// string hostName = m_scene.RegionInfo.ExternalHostName; +// uint port = (MainServer.Instance == null) ? 0 : MainServer.Instance.Port; +// string protocol = "http"; +// +// if (MainServer.Instance.UseSSL) +// { +// hostName = MainServer.Instance.SSLCommonName; +// port = MainServer.Instance.SSLPort; +// protocol = "https"; +// } +// +// caps.RegisterHandler("FetchInventoryDescendents2", String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, capUrl)); } - private void DeregisterCaps(UUID agentID, Caps caps) - { - string capUrl; - - if (m_capsDict.TryGetValue(agentID, out capUrl)) - { - MainServer.Instance.RemoveHTTPHandler("", capUrl); - m_capsDict.Remove(agentID); - } - } +// private void DeregisterCaps(UUID agentID, Caps caps) +// { +// string capUrl; +// +// if (m_capsDict.TryGetValue(agentID, out capUrl)) +// { +// MainServer.Instance.RemoveHTTPHandler("", capUrl); +// m_capsDict.Remove(agentID); +// } +// } private void DoInventoryRequests() { @@ -355,4 +351,4 @@ namespace OpenSim.Region.ClientStack.Linden } } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs b/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs index bd60611..ad1c4ce 100644 --- a/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs +++ b/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs @@ -80,7 +80,7 @@ namespace OpenSim.Region.CoreModules.Framework MainConsole.Instance.Commands.AddCommand( "Comms", false, "show caps stats by user", - "show caps stats [ ]", + "show caps stats by user [ ]", "Shows statistics on capabilities use by user.", "If a user name is given, then prints a detailed breakdown of caps use ordered by number of requests received.", HandleShowCapsStatsByUserCommand); @@ -285,27 +285,31 @@ namespace OpenSim.Region.CoreModules.Framework if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_scene) return; - StringBuilder caps = new StringBuilder(); - caps.AppendFormat("Region {0}:\n", m_scene.RegionInfo.RegionName); + StringBuilder capsReport = new StringBuilder(); + capsReport.AppendFormat("Region {0}:\n", m_scene.RegionInfo.RegionName); lock (m_capsObjects) { foreach (KeyValuePair kvp in m_capsObjects) { - caps.AppendFormat("** User {0}:\n", kvp.Key); + capsReport.AppendFormat("** User {0}:\n", kvp.Key); + Caps caps = kvp.Value; - for (IDictionaryEnumerator kvp2 = kvp.Value.CapsHandlers.GetCapsDetails(false, null).GetEnumerator(); kvp2.MoveNext(); ) + for (IDictionaryEnumerator kvp2 = caps.CapsHandlers.GetCapsDetails(false, null).GetEnumerator(); kvp2.MoveNext(); ) { Uri uri = new Uri(kvp2.Value.ToString()); - caps.AppendFormat(m_showCapsCommandFormat, kvp2.Key, uri.PathAndQuery); + capsReport.AppendFormat(m_showCapsCommandFormat, kvp2.Key, uri.PathAndQuery); } - foreach (KeyValuePair kvp3 in kvp.Value.ExternalCapsHandlers) - caps.AppendFormat(m_showCapsCommandFormat, kvp3.Key, kvp3.Value); + foreach (KeyValuePair kvp2 in caps.GetPollHandlers()) + capsReport.AppendFormat(m_showCapsCommandFormat, kvp2.Key, kvp2.Value.Url); + + foreach (KeyValuePair kvp3 in caps.ExternalCapsHandlers) + capsReport.AppendFormat(m_showCapsCommandFormat, kvp3.Key, kvp3.Value); } } - MainConsole.Instance.Output(caps.ToString()); + MainConsole.Instance.Output(capsReport.ToString()); } private void HandleShowCapsStatsByCapCommand(string module, string[] cmdParams) @@ -362,7 +366,16 @@ namespace OpenSim.Region.CoreModules.Framework { receivedStats[sp.Name] = reqHandler.RequestsReceived; handledStats[sp.Name] = reqHandler.RequestsHandled; - } + } + else + { + PollServiceEventArgs pollHandler = null; + if (caps.TryGetPollHandler(capName, out pollHandler)) + { + receivedStats[sp.Name] = pollHandler.RequestsReceived; + handledStats[sp.Name] = pollHandler.RequestsHandled; + } + } } ); @@ -391,11 +404,9 @@ namespace OpenSim.Region.CoreModules.Framework Caps caps = m_scene.CapsModule.GetCapsForUser(sp.UUID); if (caps == null) - return; - - Dictionary capsHandlers = caps.CapsHandlers.GetCapsHandlers(); + return; - foreach (IRequestHandler reqHandler in capsHandlers.Values) + foreach (IRequestHandler reqHandler in caps.CapsHandlers.GetCapsHandlers().Values) { string reqName = reqHandler.Name ?? ""; @@ -410,6 +421,23 @@ namespace OpenSim.Region.CoreModules.Framework handledStats[reqName] += reqHandler.RequestsHandled; } } + + foreach (KeyValuePair kvp in caps.GetPollHandlers()) + { + string name = kvp.Key; + PollServiceEventArgs pollHandler = kvp.Value; + + if (!receivedStats.ContainsKey(name)) + { + receivedStats[name] = pollHandler.RequestsReceived; + handledStats[name] = pollHandler.RequestsHandled; + } + else + { + receivedStats[name] += pollHandler.RequestsReceived; + handledStats[name] += pollHandler.RequestsHandled; + } + } } ); @@ -468,12 +496,16 @@ namespace OpenSim.Region.CoreModules.Framework if (caps == null) return; - Dictionary capsHandlers = caps.CapsHandlers.GetCapsHandlers(); + List capRows = new List(); - foreach (IRequestHandler reqHandler in capsHandlers.Values.OrderByDescending(rh => rh.RequestsReceived)) - { - cdt.AddRow(reqHandler.Name, reqHandler.RequestsReceived, reqHandler.RequestsHandled); - } + foreach (IRequestHandler reqHandler in caps.CapsHandlers.GetCapsHandlers().Values) + capRows.Add(new CapTableRow(reqHandler.Name, reqHandler.RequestsReceived, reqHandler.RequestsHandled)); + + foreach (KeyValuePair kvp in caps.GetPollHandlers()) + capRows.Add(new CapTableRow(kvp.Key, kvp.Value.RequestsReceived, kvp.Value.RequestsHandled)); + + foreach (CapTableRow ctr in capRows.OrderByDescending(ctr => ctr.RequestsReceived)) + cdt.AddRow(ctr.Name, ctr.RequestsReceived, ctr.RequestsHandled); sb.Append(cdt.ToString()); } @@ -505,6 +537,14 @@ namespace OpenSim.Region.CoreModules.Framework totalRequestsReceived += reqHandler.RequestsReceived; totalRequestsHandled += reqHandler.RequestsHandled; } + + Dictionary capsPollHandlers = caps.GetPollHandlers(); + + foreach (PollServiceEventArgs handler in capsPollHandlers.Values) + { + totalRequestsReceived += handler.RequestsReceived; + totalRequestsHandled += handler.RequestsHandled; + } cdt.AddRow(sp.Name, sp.IsChildAgent ? "child" : "root", totalRequestsReceived, totalRequestsHandled); } @@ -512,5 +552,19 @@ namespace OpenSim.Region.CoreModules.Framework sb.Append(cdt.ToString()); } + + private class CapTableRow + { + public string Name { get; set; } + public int RequestsReceived { get; set; } + public int RequestsHandled { get; set; } + + public CapTableRow(string name, int requestsReceived, int requestsHandled) + { + Name = name; + RequestsReceived = requestsReceived; + RequestsHandled = requestsHandled; + } + } } } \ No newline at end of file diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs index def8162..99a3122 100644 --- a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs @@ -235,7 +235,8 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp string uri = "/lslhttp/" + urlcode.ToString() + "/"; - PollServiceEventArgs args = new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode, 25000); + PollServiceEventArgs args + = new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, urlcode, 25000); args.Type = PollServiceEventArgs.EventType.LslHttp; m_HttpServer.AddPollServiceHTTPHandler(uri, args); @@ -280,7 +281,8 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp string uri = "/lslhttps/" + urlcode.ToString() + "/"; - PollServiceEventArgs args = new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode, 25000); + PollServiceEventArgs args + = new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, urlcode, 25000); args.Type = PollServiceEventArgs.EventType.LslHttp; m_HttpsServer.AddPollServiceHTTPHandler(uri, args); -- cgit v1.1