From dcdfde834fc1bfdcf46357e4106be96e63209c71 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Sun, 12 Oct 2008 00:56:54 +0000 Subject: LLUDP Client View * Experimenting with the PacketPool mechanism. * It's still disabled in the code, however there's now a flag to enable it. * Converted to use Generic Collections vs Hashtables, also now uses a list of 'OK to pool' packets, starting with the high volume PacketAck packet. --- OpenSim/Framework/PacketPool.cs | 54 +++++++++++++--------- .../Region/ClientStack/LindenUDP/LLUDPServer.cs | 1 + 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/OpenSim/Framework/PacketPool.cs b/OpenSim/Framework/PacketPool.cs index e6c519e..597375c 100644 --- a/OpenSim/Framework/PacketPool.cs +++ b/OpenSim/Framework/PacketPool.cs @@ -26,8 +26,7 @@ */ using System; -using System.Collections; -using System.Net; +using System.Collections.Generic; using OpenMetaverse; using OpenMetaverse.Packets; @@ -37,7 +36,9 @@ namespace OpenSim.Framework { private static readonly PacketPool instance = new PacketPool(); - private Hashtable pool = new Hashtable(); + private const bool packetPoolEnabled = false; + + private readonly Dictionary> pool = new Dictionary>(); static PacketPool() { @@ -54,7 +55,7 @@ namespace OpenSim.Framework lock (pool) { - if (pool[type] == null || ((Stack) pool[type]).Count == 0) + if (pool[type] == null || (pool[type]).Count == 0) { // Creating a new packet if we cannot reuse an old package packet = Packet.BuildPacket(type); @@ -62,7 +63,7 @@ namespace OpenSim.Framework else { // Recycle old packages - packet = (Packet) ((Stack) pool[type]).Pop(); + packet = (pool[type]).Pop(); } } @@ -94,13 +95,13 @@ namespace OpenSim.Framework } else { - id = (ushort) decoded_header[7]; + id = decoded_header[7]; freq = PacketFrequency.Medium; } } else { - id = (ushort) decoded_header[6]; + id = decoded_header[6]; freq = PacketFrequency.High; } @@ -113,7 +114,7 @@ namespace OpenSim.Framework int z; for (z = 0 ; z < zeroBuffer.Length ; z++) - zeroBuffer[z] = (byte)0; + zeroBuffer[z] = 0; int i = 0; Packet packet = GetPacket(type); @@ -127,23 +128,32 @@ namespace OpenSim.Framework /// public void ReturnPacket(Packet packet) { - return; // packet pool disabled + if(!packetPoolEnabled) + return; - /* // Commented out to remove a compiler warning. :) - lock (pool) + switch(packet.Type) { - PacketType type=packet.Type; - - if (pool[type] == null) - { - pool[type] = new Stack(); - } - if (((Stack)pool[type]).Count < 50) - { - ((Stack)pool[type]).Push(packet); - } + // List pooling packets here + case PacketType.PacketAck: + lock (pool) + { + PacketType type = packet.Type; + + if (pool[type] == null) + { + pool[type] = new Stack(); + } + if ((pool[type]).Count < 50) + { + (pool[type]).Push(packet); + } + } + break; + + // Other packets wont pool + default: + return; } - */ } } } diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index 71f854a..d64e0a4 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -327,6 +327,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP try { + m_socket.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); -- cgit v1.1