aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs')
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs86
1 files changed, 52 insertions, 34 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs b/OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs
index 2a3d14f..1fdc410 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/PacketPool.cs
@@ -41,25 +41,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
41 41
42 private static readonly PacketPool instance = new PacketPool(); 42 private static readonly PacketPool instance = new PacketPool();
43 43
44 private bool packetPoolEnabled = true;
45 private bool dataBlockPoolEnabled = true;
46
47 private PercentageStat m_packetsReusedStat = new PercentageStat(
48 "PacketsReused",
49 "Packets reused",
50 "clientstack",
51 "packetpool",
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 "clientstack",
59 "packetpool",
60 StatVerbosity.Debug,
61 "Number of data blocks reused out of all requests to the packet pool");
62
63 /// <summary> 44 /// <summary>
64 /// Pool of packets available for reuse. 45 /// Pool of packets available for reuse.
65 /// </summary> 46 /// </summary>
@@ -72,22 +53,59 @@ namespace OpenSim.Region.ClientStack.LindenUDP
72 get { return instance; } 53 get { return instance; }
73 } 54 }
74 55
75 public bool RecyclePackets 56 public bool RecyclePackets { get; set; }
57
58 public bool RecycleDataBlocks { get; set; }
59
60 /// <summary>
61 /// The number of packets pooled
62 /// </summary>
63 public int PacketsPooled
76 { 64 {
77 set { packetPoolEnabled = value; } 65 get
78 get { return packetPoolEnabled; } 66 {
67 lock (pool)
68 return pool.Count;
69 }
79 } 70 }
80 71
81 public bool RecycleDataBlocks 72 /// <summary>
73 /// The number of blocks pooled.
74 /// </summary>
75 public int BlocksPooled
82 { 76 {
83 set { dataBlockPoolEnabled = value; } 77 get
84 get { return dataBlockPoolEnabled; } 78 {
79 lock (DataBlocks)
80 return DataBlocks.Count;
81 }
85 } 82 }
86 83
84 /// <summary>
85 /// Number of packets requested.
86 /// </summary>
87 public long PacketsRequested { get; private set; }
88
89 /// <summary>
90 /// Number of packets reused.
91 /// </summary>
92 public long PacketsReused { get; private set; }
93
94 /// <summary>
95 /// Number of packet blocks requested.
96 /// </summary>
97 public long BlocksRequested { get; private set; }
98
99 /// <summary>
100 /// Number of packet blocks reused.
101 /// </summary>
102 public long BlocksReused { get; private set; }
103
87 private PacketPool() 104 private PacketPool()
88 { 105 {
89 StatsManager.RegisterStat(m_packetsReusedStat); 106 // defaults
90 StatsManager.RegisterStat(m_blocksReusedStat); 107 RecyclePackets = true;
108 RecycleDataBlocks = true;
91 } 109 }
92 110
93 /// <summary> 111 /// <summary>
@@ -97,11 +115,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
97 /// <returns>Guaranteed to always return a packet, whether from the pool or newly constructed.</returns> 115 /// <returns>Guaranteed to always return a packet, whether from the pool or newly constructed.</returns>
98 public Packet GetPacket(PacketType type) 116 public Packet GetPacket(PacketType type)
99 { 117 {
100 m_packetsReusedStat.Consequent++; 118 PacketsRequested++;
101 119
102 Packet packet; 120 Packet packet;
103 121
104 if (!packetPoolEnabled) 122 if (!RecyclePackets)
105 return Packet.BuildPacket(type); 123 return Packet.BuildPacket(type);
106 124
107 lock (pool) 125 lock (pool)
@@ -118,7 +136,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
118// m_log.DebugFormat("[PACKETPOOL]: Pulling {0} packet", type); 136// m_log.DebugFormat("[PACKETPOOL]: Pulling {0} packet", type);
119 137
120 // Recycle old packages 138 // Recycle old packages
121 m_packetsReusedStat.Antecedent++; 139 PacketsReused++;
122 140
123 packet = pool[type].Pop(); 141 packet = pool[type].Pop();
124 } 142 }
@@ -187,7 +205,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
187 /// <param name="packet"></param> 205 /// <param name="packet"></param>
188 public void ReturnPacket(Packet packet) 206 public void ReturnPacket(Packet packet)
189 { 207 {
190 if (dataBlockPoolEnabled) 208 if (RecycleDataBlocks)
191 { 209 {
192 switch (packet.Type) 210 switch (packet.Type)
193 { 211 {
@@ -211,7 +229,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
211 } 229 }
212 } 230 }
213 231
214 if (packetPoolEnabled) 232 if (RecyclePackets)
215 { 233 {
216 switch (packet.Type) 234 switch (packet.Type)
217 { 235 {
@@ -249,7 +267,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
249 { 267 {
250 lock (DataBlocks) 268 lock (DataBlocks)
251 { 269 {
252 m_blocksReusedStat.Consequent++; 270 BlocksRequested++;
253 271
254 Stack<Object> s; 272 Stack<Object> s;
255 273
@@ -257,7 +275,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
257 { 275 {
258 if (s.Count > 0) 276 if (s.Count > 0)
259 { 277 {
260 m_blocksReusedStat.Antecedent++; 278 BlocksReused++;
261 return (T)s.Pop(); 279 return (T)s.Pop();
262 } 280 }
263 } 281 }