From 813778b39e0ede607e299e4d7bf2808899aa8c05 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 11 Oct 2012 23:58:37 +0100 Subject: [PATCH] Fix packetpool for ImprovedTerseObjectUpdate packets. These were neither being returned or in many places reused. Getting packets from a pool rather than deallocating and reallocating reduces memory churn which in turn reduces garbage collection time and frequency. --- OpenSim/Framework/Monitoring/StatsManager.cs | 16 +++++++++++++--- .../ClientStack/Linden/UDP/LLClientView.cs | 14 +++++++++++--- .../Region/ClientStack/Linden/UDP/LLUDPServer.cs | 2 ++ .../Region/ClientStack/Linden/UDP/PacketPool.cs | 4 ++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/OpenSim/Framework/Monitoring/StatsManager.cs b/OpenSim/Framework/Monitoring/StatsManager.cs index a67c5f8375..d365190915 100644 --- a/OpenSim/Framework/Monitoring/StatsManager.cs +++ b/OpenSim/Framework/Monitoring/StatsManager.cs @@ -126,8 +126,7 @@ namespace OpenSim.Framework.Monitoring { foreach (Stat stat in container.Values) { - con.OutputFormat( - "{0}.{1}.{2} : {3}{4}", stat.Category, stat.Container, stat.ShortName, stat.Value, stat.UnitName); + con.Output(stat.ToConsoleString()); } } } @@ -330,6 +329,12 @@ namespace OpenSim.Framework.Monitoring { return string.Format("{0}+{1}+{2}", container, category, shortName); } + + public virtual string ToConsoleString() + { + return string.Format( + "{0}.{1}.{2} : {3}{4}", Category, Container, ShortName, Value, UnitName); + } } public class PercentageStat : Stat @@ -358,8 +363,13 @@ namespace OpenSim.Framework.Monitoring public PercentageStat( string shortName, string name, string category, string container, StatVerbosity verbosity, string description) - : base(shortName, name, "%", category, container, verbosity, description) + : base(shortName, name, "%", category, container, verbosity, description) {} + + public override string ToConsoleString() { + return string.Format( + "{0}.{1}.{2} : {3:0.###}{4} ({5}/{6})", + Category, Container, ShortName, Value, UnitName, Antecedent, Consequent); } } } \ No newline at end of file diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index d05ffea1bd..7f3e22ef22 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs @@ -3921,7 +3921,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP { List blocks = terseAgentUpdateBlocks.Value; - ImprovedTerseObjectUpdatePacket packet = new ImprovedTerseObjectUpdatePacket(); + ImprovedTerseObjectUpdatePacket packet + = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate); + packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle; packet.RegionData.TimeDilation = timeDilation; packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[blocks.Count]; @@ -3966,7 +3968,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP { List blocks = terseUpdateBlocks.Value; - ImprovedTerseObjectUpdatePacket packet = new ImprovedTerseObjectUpdatePacket(); + ImprovedTerseObjectUpdatePacket packet + = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket( + PacketType.ImprovedTerseObjectUpdate); + packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle; packet.RegionData.TimeDilation = timeDilation; packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[blocks.Count]; @@ -12284,7 +12289,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP ushort timeDilation = Utils.FloatToUInt16(TIME_DILATION, 0.0f, 1.0f); - ImprovedTerseObjectUpdatePacket packet = new ImprovedTerseObjectUpdatePacket(); + ImprovedTerseObjectUpdatePacket packet + = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket( + PacketType.ImprovedTerseObjectUpdate); + packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle; packet.RegionData.TimeDilation = timeDilation; packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs index ab670a7b1d..6d2cda5de3 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs @@ -420,6 +420,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP byte[] data = packet.ToBytes(); SendPacketData(udpClient, data, packet.Type, category, method); } + + PacketPool.Instance.ReturnPacket(packet); } /// diff --git a/OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs b/OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs index 3d9f94fa9f..fd6b0eda47 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs @@ -47,7 +47,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP private PercentageStat m_packetsReusedStat = new PercentageStat( "PacketsReused", "Packets reused", - "simulator", + "clientstack", "simulator", StatVerbosity.Debug, "Number of packets reused out of all requests to the packet pool"); @@ -55,7 +55,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP private PercentageStat m_blocksReusedStat = new PercentageStat( "BlocksReused", "Blocks reused", - "simulator", + "clientstack", "simulator", StatVerbosity.Debug, "Number of data blocks reused out of all requests to the packet pool");