From 2ed59ad8ac3ec836517b60580f13ab37102a0c67 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Wed, 17 Oct 2012 21:08:15 +0100
Subject: If RecycleBaseUDPPackets = true, also pool IncomingPackets to reduce
memory churn
---
.../ClientStack/Linden/UDP/IncomingPacket.cs | 7 +++++-
.../Region/ClientStack/Linden/UDP/LLUDPServer.cs | 25 +++++++++++++++++++++-
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/IncomingPacket.cs b/OpenSim/Region/ClientStack/Linden/UDP/IncomingPacket.cs
index 1b8535c..e22670b 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/IncomingPacket.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/IncomingPacket.cs
@@ -45,7 +45,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public Packet Packet;
///
- /// Default constructor
+ /// No arg constructor.
+ ///
+ public IncomingPacket() {}
+
+ ///
+ /// Constructor
///
/// Reference to the client this packet came from
/// Packet data
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
index 42247ca..286d931 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
@@ -168,6 +168,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// Flag to signal when clients should send pings
protected bool m_sendPing;
+ private Pool m_incomingPacketPool;
+
private int m_defaultRTO = 0;
private int m_maxRTO = 0;
private int m_ackTimeout = 0;
@@ -274,6 +276,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
m_throttle = new TokenBucket(null, sceneThrottleBps);
ThrottleRates = new ThrottleRates(configSource);
+
+ if (UsePools)
+ m_incomingPacketPool = new Pool(() => new IncomingPacket(), 500);
}
public void Start()
@@ -1012,8 +1017,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP
#endregion Ping Check Handling
+ IncomingPacket incomingPacket;
+
// Inbox insertion
- packetInbox.Enqueue(new IncomingPacket((LLClientView)client, packet));
+ if (UsePools)
+ {
+ incomingPacket = m_incomingPacketPool.GetObject();
+ incomingPacket.Client = (LLClientView)client;
+ incomingPacket.Packet = packet;
+ }
+ else
+ {
+ incomingPacket = new IncomingPacket((LLClientView)client, packet);
+ }
+
+ packetInbox.Enqueue(incomingPacket);
}
#region BinaryStats
@@ -1283,7 +1301,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
}
if (packetInbox.Dequeue(100, ref incomingPacket))
+ {
ProcessInPacket(incomingPacket);//, incomingPacket); Util.FireAndForget(ProcessInPacket, incomingPacket);
+
+ if (UsePools)
+ m_incomingPacketPool.ReturnObject(incomingPacket);
+ }
}
catch (Exception ex)
{
--
cgit v1.1
From faf6b568393d8edfed103e0a656c98322c195e95 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Wed, 17 Oct 2012 23:08:14 +0100
Subject: Explicitly return only the incoming AgentUpdate packet as this is the
only one we pool atm, rather than attempting to return all incoming packets.
---
OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs | 11 +++++++----
OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs | 17 +++++++++++++++--
OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs | 10 ++++++++--
3 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
index 0d4f09d..1e93b84 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
@@ -5425,16 +5425,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP
#region Scene/Avatar
- private bool HandleAgentUpdate(IClientAPI sener, Packet Pack)
+ private bool HandleAgentUpdate(IClientAPI sener, Packet packet)
{
if (OnAgentUpdate != null)
{
bool update = false;
- AgentUpdatePacket agenUpdate = (AgentUpdatePacket)Pack;
+ AgentUpdatePacket agenUpdate = (AgentUpdatePacket)packet;
#region Packet Session and User Check
if (agenUpdate.AgentData.SessionID != SessionId || agenUpdate.AgentData.AgentID != AgentId)
+ {
+ PacketPool.Instance.ReturnPacket(packet);
return false;
+ }
#endregion
AgentUpdatePacket.AgentDataBlock x = agenUpdate.AgentData;
@@ -5499,6 +5502,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
}
}
+ PacketPool.Instance.ReturnPacket(packet);
+
return true;
}
@@ -11851,8 +11856,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (!ProcessPacketMethod(packet))
m_log.Warn("[CLIENT]: unhandled packet " + packet.Type);
-
- PacketPool.Instance.ReturnPacket(packet);
}
private static PrimitiveBaseShape GetShapeFromAddPacket(ObjectAddPacket addPacket)
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
index 286d931..419de66 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
@@ -314,7 +314,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
base.StartOutbound();
- // This thread will process the packets received that are placed on the packetInbox
Watchdog.StartThread(
OutgoingPacketHandler,
string.Format("Outgoing Packets ({0})", m_scene.RegionInfo.RegionName),
@@ -930,6 +929,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// Handle appended ACKs
if (packet.Header.AppendedAcks && packet.Header.AckList != null)
{
+// m_log.DebugFormat(
+// "[LLUDPSERVER]: Handling {0} appended acks from {1} in {2}",
+// packet.Header.AckList.Length, client.Name, m_scene.Name);
+
for (int i = 0; i < packet.Header.AckList.Length; i++)
udpClient.NeedAcks.Acknowledge(packet.Header.AckList[i], now, packet.Header.Resent);
}
@@ -939,6 +942,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
{
PacketAckPacket ackPacket = (PacketAckPacket)packet;
+// m_log.DebugFormat(
+// "[LLUDPSERVER]: Handling {0} packet acks for {1} in {2}",
+// ackPacket.Packets.Length, client.Name, m_scene.Name);
+
for (int i = 0; i < ackPacket.Packets.Length; i++)
udpClient.NeedAcks.Acknowledge(ackPacket.Packets[i].ID, now, packet.Header.Resent);
@@ -952,6 +959,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (packet.Header.Reliable)
{
+// m_log.DebugFormat(
+// "[LLUDPSERVER]: Adding ack request for {0} {1} from {2} in {3}",
+// packet.Type, packet.Header.Sequence, client.Name, m_scene.Name);
+
udpClient.PendingAcks.Enqueue(packet.Header.Sequence);
// This is a somewhat odd sequence of steps to pull the client.BytesSinceLastACK value out,
@@ -998,6 +1009,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (packet.Type == PacketType.StartPingCheck)
{
+// m_log.DebugFormat("[LLUDPSERVER]: Handling ping from {0} in {1}", client.Name, m_scene.Name);
+
// We don't need to do anything else with ping checks
StartPingCheckPacket startPing = (StartPingCheckPacket)packet;
CompletePing(udpClient, startPing.PingID.PingID);
@@ -1286,7 +1299,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// on to en-US to avoid number parsing issues
Culture.SetCurrentCulture();
- while (base.IsRunningInbound)
+ while (IsRunningInbound)
{
try
{
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs b/OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs
index 71f6fe1..2a3d14f 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs
@@ -108,15 +108,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP
{
if (!pool.ContainsKey(type) || pool[type] == null || (pool[type]).Count == 0)
{
+// m_log.DebugFormat("[PACKETPOOL]: Building {0} packet", type);
+
// Creating a new packet if we cannot reuse an old package
packet = Packet.BuildPacket(type);
}
else
{
+// m_log.DebugFormat("[PACKETPOOL]: Pulling {0} packet", type);
+
// Recycle old packages
m_packetsReusedStat.Antecedent++;
- packet = (pool[type]).Pop();
+ packet = pool[type].Pop();
}
}
@@ -227,7 +231,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if ((pool[type]).Count < 50)
{
- (pool[type]).Push(packet);
+// m_log.DebugFormat("[PACKETPOOL]: Pushing {0} packet", type);
+
+ pool[type].Push(packet);
}
}
break;
--
cgit v1.1