From be2ad79e52efb5eb543057e8e73fa601d0b91c87 Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Thu, 20 Dec 2007 05:43:02 +0000 Subject: Added patch from Johan. First attempt to solve the LibSL.Packet GC problem. Works with LibSL rev>1532 --- OpenSim/Region/ClientStack/ClientView.cs | 37 +++++++----- .../Region/ClientStack/RegionApplicationBase.cs | 2 +- OpenSim/Region/ClientStack/UDPServer.cs | 65 +++++++++++++++++++++- 3 files changed, 87 insertions(+), 17 deletions(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs index 75c4187..58cb9a2 100644 --- a/OpenSim/Region/ClientStack/ClientView.cs +++ b/OpenSim/Region/ClientStack/ClientView.cs @@ -535,7 +535,7 @@ namespace OpenSim.Region.ClientStack /// public void SendRegionHandshake(RegionInfo regionInfo) { - RegionHandshakePacket handshake = new RegionHandshakePacket(); + RegionHandshakePacket handshake = (RegionHandshakePacket) PacketPool.Instance.GetPacket(PacketType.RegionHandshake); handshake.RegionInfo.BillableFactor = regionInfo.EstateSettings.billableFactor; handshake.RegionInfo.IsEstateManager = false; @@ -2187,17 +2187,22 @@ namespace OpenSim.Region.ClientStack // Actually make the byte array and send it try { - byte[] sendbuffer = Pack.ToBytes(); - if (Pack.Header.Zerocoded) - { - byte[] ZeroOutBuffer = new byte[4096]; - int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer); - m_networkServer.SendPacketTo(ZeroOutBuffer, packetsize, SocketFlags.None, m_circuitCode); - } - else - { - m_networkServer.SendPacketTo(sendbuffer, sendbuffer.Length, SocketFlags.None, m_circuitCode); - } + byte[] sendbuffer = Pack.ToBytes(); + if (Pack is RegionHandshakePacket) + { + PacketPool.Instance.ReturnPacket(Pack); + } + + if (Pack.Header.Zerocoded) + { + byte[] ZeroOutBuffer = new byte[4096]; + int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer); + m_networkServer.SendPacketTo(ZeroOutBuffer, packetsize, SocketFlags.None, m_circuitCode); + } + else + { + m_networkServer.SendPacketTo(sendbuffer, sendbuffer.Length, SocketFlags.None, m_circuitCode); + } } catch (Exception e) { @@ -2801,7 +2806,7 @@ namespace OpenSim.Region.ClientStack case PacketType.AssetUploadRequest: AssetUploadRequestPacket request = (AssetUploadRequestPacket) Pack; // Console.WriteLine("upload request " + Pack.ToString()); - // Console.WriteLine("upload request was for assetid: " + request.AssetBlock.TransactionID.Combine(this.SecureSessionId).ToStringHyphenated()); + // Console.WriteLine("upload request was for assetid: " + request.AssetBlock.TransactionID.Combine(this.SecureSessionId).ToString()); if (OnAssetUploadRequest != null) { LLUUID temp=libsecondlife.LLUUID.Combine(request.AssetBlock.TransactionID, SecureSessionId); @@ -2928,7 +2933,7 @@ namespace OpenSim.Region.ClientStack AssetBase asset = m_assetCache.GetAsset(update.InventoryData[i].TransactionID.Combine(this.SecureSessionId)); if (asset != null) { - // Console.WriteLine("updating inventory item, found asset" + asset.FullID.ToStringHyphenated() + " already in cache"); + // Console.WriteLine("updating inventory item, found asset" + asset.FullID.ToString() + " already in cache"); m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset); } else @@ -2936,7 +2941,7 @@ namespace OpenSim.Region.ClientStack asset = this.UploadAssets.AddUploadToAssetCache(update.InventoryData[i].TransactionID); if (asset != null) { - //Console.WriteLine("updating inventory item, adding asset" + asset.FullID.ToStringHyphenated() + " to cache"); + //Console.WriteLine("updating inventory item, adding asset" + asset.FullID.ToString() + " to cache"); m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset); } else @@ -3351,6 +3356,8 @@ namespace OpenSim.Region.ClientStack #endregion } } + + PacketPool.Instance.ReturnPacket(Pack); } private static PrimitiveBaseShape GetShapeFromAddPacket(ObjectAddPacket addPacket) diff --git a/OpenSim/Region/ClientStack/RegionApplicationBase.cs b/OpenSim/Region/ClientStack/RegionApplicationBase.cs index 51155ac..f20b132 100644 --- a/OpenSim/Region/ClientStack/RegionApplicationBase.cs +++ b/OpenSim/Region/ClientStack/RegionApplicationBase.cs @@ -134,7 +134,7 @@ namespace OpenSim.Region.ClientStack if (masterAvatar != null) { - m_log.Verbose("PARCEL", "Found master avatar [" + masterAvatar.UUID.ToStringHyphenated() + "]"); + m_log.Verbose("PARCEL", "Found master avatar [" + masterAvatar.UUID.ToString() + "]"); scene.RegionInfo.MasterAvatarAssignedUUID = masterAvatar.UUID; } else diff --git a/OpenSim/Region/ClientStack/UDPServer.cs b/OpenSim/Region/ClientStack/UDPServer.cs index f91e5e2..5cad041 100644 --- a/OpenSim/Region/ClientStack/UDPServer.cs +++ b/OpenSim/Region/ClientStack/UDPServer.cs @@ -26,6 +26,7 @@ * */ using System; +using System.Collections; using System.Collections.Generic; using System.Net; using System.Net.Sockets; @@ -36,6 +37,68 @@ using OpenSim.Framework.Console; namespace OpenSim.Region.ClientStack { + public sealed class PacketPool + { + // Set up a thread-safe singleton pattern + static PacketPool() + { + } + + static readonly PacketPool instance = new PacketPool(); + + public static PacketPool Instance + { + get + { + return instance; + } + } + + private Hashtable pool = new Hashtable(); + + public Packet GetPacket(PacketType type) { + Packet packet = null; + + lock(pool) + { + if(pool[type] == null || ((Stack) pool[type]).Count == 0) + { + // Creating a new packet if we cannot reuse an old package + packet = Packet.BuildPacket(type); + } + else + { + // Recycle old packages + packet=(Packet) ((Stack) pool[type]).Pop(); + } + } + + return packet; + } + + public Packet GetPacket(byte[] bytes, ref int packetEnd, byte[] zeroBuffer) { + Packet packet = GetPacket(Packet.GetType(bytes, packetEnd, zeroBuffer)); + + int i = 0; + packet.FromBytes(bytes, ref i, ref packetEnd, zeroBuffer); + return packet; + } + + public void ReturnPacket(Packet packet) { + lock(pool) + { + PacketType type=packet.Type; + + if(pool[type] == null) + { + pool[type] = new Stack(); + } + + ((Stack) pool[type]).Push(packet); + } + } + } + public class UDPServer : ClientStackNetworkHandler { protected Dictionary clientCircuits = new Dictionary(); @@ -194,7 +257,7 @@ namespace OpenSim.Region.ClientStack try { - packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer); + packet = PacketPool.Instance.GetPacket(RecvBuffer, ref packetEnd, ZeroBuffer); } catch(Exception) { -- cgit v1.1