From ac944def3fbea9cbad58780e3996e4c586237ab5 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sat, 2 May 2009 00:14:04 +0000 Subject: Fix the issue that stopped the packet pool from working. Add a mechanism to recycley data blocs within a packet. Recycle the ObjectUpdate* data blocks. Speeds up loading even more. This may mean that the packet pool is now viable. --- OpenSim/Framework/PacketPool.cs | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/PacketPool.cs b/OpenSim/Framework/PacketPool.cs index a4f7d96..4d9591e 100644 --- a/OpenSim/Framework/PacketPool.cs +++ b/OpenSim/Framework/PacketPool.cs @@ -34,6 +34,7 @@ using log4net; namespace OpenSim.Framework { + public sealed class PacketPool { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -44,6 +45,9 @@ namespace OpenSim.Framework private readonly Dictionary> pool = new Dictionary>(); + private static Dictionary> DataBlocks = + new Dictionary>(); + static PacketPool() { } @@ -136,6 +140,28 @@ namespace OpenSim.Framework /// public void ReturnPacket(Packet packet) { + switch (packet.Type) + { + case PacketType.ObjectUpdate: + ObjectUpdatePacket oup = (ObjectUpdatePacket)packet; + + foreach (ObjectUpdatePacket.ObjectDataBlock oupod in + oup.ObjectData) + ReturnDataBlock(oupod); + oup.ObjectData = null; + break; + + case PacketType.ImprovedTerseObjectUpdate: + ImprovedTerseObjectUpdatePacket itoup = + (ImprovedTerseObjectUpdatePacket)packet; + + foreach (ImprovedTerseObjectUpdatePacket.ObjectDataBlock + itoupod in itoup.ObjectData) + ReturnDataBlock(itoupod); + itoup.ObjectData = null; + break; + } + if (!packetPoolEnabled) return; @@ -163,5 +189,45 @@ namespace OpenSim.Framework return; } } + + public static T GetDataBlock() where T: new() + { + lock(DataBlocks) + { + if (DataBlocks.ContainsKey(typeof(T)) && DataBlocks[typeof(T)].Count > 0) + { + T block = (T)DataBlocks[typeof(T)][0]; + DataBlocks[typeof(T)].RemoveAt(0); + if (block == null) + return new T(); + return block; + } + else + { + return new T(); + } + } + } + + public static void ReturnDataBlock(T block) where T: new() + { + if (block == null) + return; + + lock (DataBlocks) + { + if (!DataBlocks.ContainsKey(typeof(T))) + { + List l = new List(); + l.Add(block); + DataBlocks.Add(typeof(T), l); + } + else + { + if (DataBlocks[typeof(T)].Count < 500) + DataBlocks[typeof(T)].Add(block); + } + } + } } } -- cgit v1.1