From 62bcf0e69405ee1443f66eecd1f3fbd684f0c2a5 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sat, 2 May 2009 13:16:41 +0000 Subject: Numerous packet improvements. Don't allow packets to be resent before they have actually been sent for the first time. Switch from serializing a packet to get it's length to the LibOMV provided Length property. Fix resend timing. Fix the use of dangling references to Acked packets. Fix the packet handler to play nice with the packet pool. Fix the packet pool. Add data block recycling to the packet pool. Packet pool is now ENABLED by default. Add config option to disable packet and data block reuse. Add ObjectUpdate and ImprovedTerseObjectUpdate to the packets being recycled. --- OpenSim/Framework/PacketPool.cs | 104 +++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 44 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/PacketPool.cs b/OpenSim/Framework/PacketPool.cs index f17d654..37924d7 100644 --- a/OpenSim/Framework/PacketPool.cs +++ b/OpenSim/Framework/PacketPool.cs @@ -41,7 +41,8 @@ namespace OpenSim.Framework private static readonly PacketPool instance = new PacketPool(); - private bool packetPoolEnabled = false; + private bool packetPoolEnabled = true; + private bool dataBlockPoolEnabled = true; private readonly Dictionary> pool = new Dictionary>(); @@ -57,6 +58,18 @@ namespace OpenSim.Framework get { return instance; } } + public bool RecyclePackets + { + set { packetPoolEnabled = value; } + get { return packetPoolEnabled; } + } + + public bool RecycleDataBlocks + { + set { dataBlockPoolEnabled = value; } + get { return dataBlockPoolEnabled; } + } + public Packet GetPacket(PacketType type) { Packet packet; @@ -140,55 +153,58 @@ namespace OpenSim.Framework /// public void ReturnPacket(Packet packet) { - switch (packet.Type) + if (dataBlockPoolEnabled) { - 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; + 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; - - switch (packet.Type) + if (packetPoolEnabled) { - // List pooling packets here - case PacketType.PacketAck: - case PacketType.ObjectUpdate: - case PacketType.ImprovedTerseObjectUpdate: - lock (pool) - { - PacketType type = packet.Type; - - if (!pool.ContainsKey(type)) - { - pool[type] = new Stack(); - } - if ((pool[type]).Count < 50) + switch (packet.Type) + { + // List pooling packets here + case PacketType.PacketAck: + case PacketType.ObjectUpdate: + case PacketType.ImprovedTerseObjectUpdate: + lock (pool) { - (pool[type]).Push(packet); + PacketType type = packet.Type; + + if (!pool.ContainsKey(type)) + { + pool[type] = new Stack(); + } + if ((pool[type]).Count < 50) + { + (pool[type]).Push(packet); + } } - } - break; - - // Other packets wont pool - default: - return; + break; + + // Other packets wont pool + default: + return; + } } } -- cgit v1.1