From b7c1a37676127ed6616e9034c5a8009a71fc9f1f Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 15 Nov 2012 01:14:18 +0000 Subject: [PATCH] Add IncomingPacketsProcessedCount stat for diagnostics. Also puts some packet processing counts in a container named after the scene so that stats can be collected from more than one scene. --- .../ClientStack/Linden/UDP/LLUDPServer.cs | 103 +++++++++++++++--- .../ClientStack/Linden/UDP/OpenSimUDPBase.cs | 33 ++---- 2 files changed, 97 insertions(+), 39 deletions(-) diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs index 14cc863f6b..f8391d77bd 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs @@ -70,6 +70,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP public void AddScene(IScene scene) { m_udpServer.AddScene(scene); + + StatsManager.RegisterStat( + new Stat( + "IncomingPacketsProcessedCount", + "Number of inbound UDP packets processed", + "Number of inbound UDP packets processed", + "", + "clientstack", + scene.Name, + StatType.Pull, + stat => stat.Value = m_udpServer.IncomingPacketsProcessed, + StatVerbosity.Debug)); } public bool HandlesRegion(Location x) @@ -170,6 +182,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP private Pool m_incomingPacketPool; + /// + /// Stat for number of packets in the main pool awaiting use. + /// + private Stat m_poolCountStat; + + /// + /// Stat for number of packets in the inbound packet pool awaiting use. + /// private Stat m_incomingPacketPoolStat; private int m_defaultRTO = 0; @@ -342,20 +362,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP m_incomingPacketPool = new Pool(() => new IncomingPacket(), 500); - m_incomingPacketPoolStat - = new Stat( - "IncomingPacketPoolCount", - "Objects within incoming packet pool", - "The number of objects currently stored within the incoming packet pool", - "", - "clientstack", - "packetpool", - StatType.Pull, - stat => stat.Value = m_incomingPacketPool.Count, - StatVerbosity.Debug); - - StatsManager.RegisterStat(m_incomingPacketPoolStat); - return true; } @@ -378,6 +384,53 @@ namespace OpenSim.Region.ClientStack.LindenUDP return false; } + /// + /// This is a seperate method so that it can be called once we have an m_scene to distinguish different scene + /// stats. + /// + private void EnablePoolStats() + { + m_poolCountStat + = new Stat( + "UDPPacketBufferPoolCount", + "Objects within the UDPPacketBuffer pool", + "The number of objects currently stored within the UDPPacketBuffer pool", + "", + "clientstack", + m_scene.Name, + StatType.Pull, + stat => stat.Value = Pool.Count, + StatVerbosity.Debug); + + StatsManager.RegisterStat(m_poolCountStat); + + m_incomingPacketPoolStat + = new Stat( + "IncomingPacketPoolCount", + "Objects within incoming packet pool", + "The number of objects currently stored within the incoming packet pool", + "", + "clientstack", + m_scene.Name, + StatType.Pull, + stat => stat.Value = m_incomingPacketPool.Count, + StatVerbosity.Debug); + + StatsManager.RegisterStat(m_incomingPacketPoolStat); + } + + /// + /// Disables pool stats. + /// + private void DisablePoolStats() + { + StatsManager.DeregisterStat(m_poolCountStat); + m_poolCountStat = null; + + StatsManager.DeregisterStat(m_incomingPacketPoolStat); + m_incomingPacketPoolStat = null; + } + /// /// If the outgoing UDP thread times out, then return client that was being processed to help with debugging. /// @@ -416,6 +469,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP m_scene = (Scene)scene; m_location = new Location(m_scene.RegionInfo.RegionHandle); + + // We delay enabling pool stats to AddScene() instead of Initialize() so that we can distinguish pool stats by + // scene name + if (UsePools) + EnablePoolStats(); MainConsole.Instance.Commands.AddCommand( "Debug", @@ -505,12 +563,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (enabled == "on") { if (EnablePools()) + { + EnablePoolStats(); MainConsole.Instance.OutputFormat("Packet pools enabled on {0}", m_scene.Name); + } } else if (enabled == "off") { if (DisablePools()) + { + DisablePoolStats(); MainConsole.Instance.OutputFormat("Packet pools disabled on {0}", m_scene.Name); + } } else { @@ -1556,6 +1620,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP private int npacksSent = 0; private int npackNotSent = 0; + /// + /// Number of inbound packets processed since startup. + /// + public long IncomingPacketsProcessed { get; private set; } + private void MonitoredClientOutgoingPacketHandler(IClientAPI client) { nticks++; @@ -1615,7 +1684,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP npacksSent++; } else + { npackNotSent++; + } watch2.Stop(); avgDequeueTicks = (nticks - 1) / (float)nticks * avgDequeueTicks + (watch2.ElapsedTicks / (float)nticks); @@ -1623,7 +1694,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP } else + { m_log.WarnFormat("[LLUDPSERVER]: Client is not connected"); + } } } catch (Exception ex) @@ -1687,6 +1760,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP "[LLUDPSERVER]: Dropped incoming {0} for dead client {1} in {2}", packet.Type, client.Name, m_scene.RegionInfo.RegionName); } + + IncomingPacketsProcessed++; } protected void LogoutHandler(IClientAPI client) diff --git a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs index 85cbb0659b..808d177dfa 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs @@ -60,16 +60,16 @@ namespace OpenMetaverse /// Flag to process packets asynchronously or synchronously private bool m_asyncPacketHandling; - /// - /// Pool to use for handling data. May be null if UsePools = false; - /// - protected OpenSim.Framework.Pool m_pool; - /// /// Are we to use object pool(s) to reduce memory churn when receiving data? /// public bool UsePools { get; protected set; } + /// + /// Pool to use for handling data. May be null if UsePools = false; + /// + protected OpenSim.Framework.Pool Pool { get; private set; } + /// Returns true if the server is currently listening for inbound packets, otherwise false public bool IsRunningInbound { get; private set; } @@ -77,8 +77,6 @@ namespace OpenMetaverse /// If IsRunningOut = false, then any request to send a packet is simply dropped. public bool IsRunningOutbound { get; private set; } - private Stat m_poolCountStat; - /// /// Default constructor /// @@ -182,21 +180,7 @@ namespace OpenMetaverse { if (!UsePools) { - m_pool = new Pool(() => new UDPPacketBuffer(), 500); - - m_poolCountStat - = new Stat( - "UDPPacketBufferPoolCount", - "Objects within the UDPPacketBuffer pool", - "The number of objects currently stored within the UDPPacketBuffer pool", - "", - "clientstack", - "packetpool", - StatType.Pull, - stat => stat.Value = m_pool.Count, - StatVerbosity.Debug); - - StatsManager.RegisterStat(m_poolCountStat); + Pool = new Pool(() => new UDPPacketBuffer(), 500); UsePools = true; @@ -211,7 +195,6 @@ namespace OpenMetaverse if (UsePools) { UsePools = false; - StatsManager.DeregisterStat(m_poolCountStat); // We won't null out the pool to avoid a race condition with code that may be in the middle of using it. @@ -226,7 +209,7 @@ namespace OpenMetaverse UDPPacketBuffer buf; if (UsePools) - buf = m_pool.GetObject(); + buf = Pool.GetObject(); else buf = new UDPPacketBuffer(); @@ -309,7 +292,7 @@ namespace OpenMetaverse finally { if (UsePools) - m_pool.ReturnObject(buffer); + Pool.ReturnObject(buffer); // Synchronous mode waits until the packet callback completes // before starting the receive to fetch another packet