aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/Linden/UDP
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs43
1 files changed, 35 insertions, 8 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs b/OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs
index fc9406b..3d9f94f 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs
@@ -31,6 +31,7 @@ using System.Reflection;
31using OpenMetaverse; 31using OpenMetaverse;
32using OpenMetaverse.Packets; 32using OpenMetaverse.Packets;
33using log4net; 33using log4net;
34using OpenSim.Framework.Monitoring;
34 35
35namespace OpenSim.Region.ClientStack.LindenUDP 36namespace OpenSim.Region.ClientStack.LindenUDP
36{ 37{
@@ -43,17 +44,28 @@ namespace OpenSim.Region.ClientStack.LindenUDP
43 private bool packetPoolEnabled = true; 44 private bool packetPoolEnabled = true;
44 private bool dataBlockPoolEnabled = true; 45 private bool dataBlockPoolEnabled = true;
45 46
47 private PercentageStat m_packetsReusedStat = new PercentageStat(
48 "PacketsReused",
49 "Packets reused",
50 "simulator",
51 "simulator",
52 StatVerbosity.Debug,
53 "Number of packets reused out of all requests to the packet pool");
54
55 private PercentageStat m_blocksReusedStat = new PercentageStat(
56 "BlocksReused",
57 "Blocks reused",
58 "simulator",
59 "simulator",
60 StatVerbosity.Debug,
61 "Number of data blocks reused out of all requests to the packet pool");
62
46 /// <summary> 63 /// <summary>
47 /// Pool of packets available for reuse. 64 /// Pool of packets available for reuse.
48 /// </summary> 65 /// </summary>
49 private readonly Dictionary<PacketType, Stack<Packet>> pool = new Dictionary<PacketType, Stack<Packet>>(); 66 private readonly Dictionary<PacketType, Stack<Packet>> pool = new Dictionary<PacketType, Stack<Packet>>();
50 67
51 private static Dictionary<Type, Stack<Object>> DataBlocks = 68 private static Dictionary<Type, Stack<Object>> DataBlocks = new Dictionary<Type, Stack<Object>>();
52 new Dictionary<Type, Stack<Object>>();
53
54 static PacketPool()
55 {
56 }
57 69
58 public static PacketPool Instance 70 public static PacketPool Instance
59 { 71 {
@@ -72,8 +84,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP
72 get { return dataBlockPoolEnabled; } 84 get { return dataBlockPoolEnabled; }
73 } 85 }
74 86
87 private PacketPool()
88 {
89 StatsManager.RegisterStat(m_packetsReusedStat);
90 StatsManager.RegisterStat(m_blocksReusedStat);
91 }
92
75 public Packet GetPacket(PacketType type) 93 public Packet GetPacket(PacketType type)
76 { 94 {
95 m_packetsReusedStat.Consequent++;
96
77 Packet packet; 97 Packet packet;
78 98
79 if (!packetPoolEnabled) 99 if (!packetPoolEnabled)
@@ -89,6 +109,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
89 else 109 else
90 { 110 {
91 // Recycle old packages 111 // Recycle old packages
112 m_packetsReusedStat.Antecedent++;
113
92 packet = (pool[type]).Pop(); 114 packet = (pool[type]).Pop();
93 } 115 }
94 } 116 }
@@ -211,16 +233,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP
211 } 233 }
212 } 234 }
213 235
214 public static T GetDataBlock<T>() where T: new() 236 public T GetDataBlock<T>() where T: new()
215 { 237 {
216 lock (DataBlocks) 238 lock (DataBlocks)
217 { 239 {
240 m_blocksReusedStat.Consequent++;
241
218 Stack<Object> s; 242 Stack<Object> s;
219 243
220 if (DataBlocks.TryGetValue(typeof(T), out s)) 244 if (DataBlocks.TryGetValue(typeof(T), out s))
221 { 245 {
222 if (s.Count > 0) 246 if (s.Count > 0)
247 {
248 m_blocksReusedStat.Antecedent++;
223 return (T)s.Pop(); 249 return (T)s.Pop();
250 }
224 } 251 }
225 else 252 else
226 { 253 {
@@ -231,7 +258,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
231 } 258 }
232 } 259 }
233 260
234 public static void ReturnDataBlock<T>(T block) where T: new() 261 public void ReturnDataBlock<T>(T block) where T: new()
235 { 262 {
236 if (block == null) 263 if (block == null)
237 return; 264 return;