diff options
author | Melanie Thielker | 2009-05-02 00:14:04 +0000 |
---|---|---|
committer | Melanie Thielker | 2009-05-02 00:14:04 +0000 |
commit | ac944def3fbea9cbad58780e3996e4c586237ab5 (patch) | |
tree | 3c8551f27e2d3ef7d19011575ab9f77464d1b08d /OpenSim/Framework/PacketPool.cs | |
parent | Add a tweakable for the prim queue preload (diff) | |
download | opensim-SC-ac944def3fbea9cbad58780e3996e4c586237ab5.zip opensim-SC-ac944def3fbea9cbad58780e3996e4c586237ab5.tar.gz opensim-SC-ac944def3fbea9cbad58780e3996e4c586237ab5.tar.bz2 opensim-SC-ac944def3fbea9cbad58780e3996e4c586237ab5.tar.xz |
Fix the issue that stopped the packet pool from working. Add a mechanism
to recycley data blocs within a packet. Recycle the ObjectUpdate* data
blocks. Speeds up loading even more.
This may mean that the packet pool is now viable.
Diffstat (limited to 'OpenSim/Framework/PacketPool.cs')
-rw-r--r-- | OpenSim/Framework/PacketPool.cs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/OpenSim/Framework/PacketPool.cs b/OpenSim/Framework/PacketPool.cs index a4f7d96..4d9591e 100644 --- a/OpenSim/Framework/PacketPool.cs +++ b/OpenSim/Framework/PacketPool.cs | |||
@@ -34,6 +34,7 @@ using log4net; | |||
34 | 34 | ||
35 | namespace OpenSim.Framework | 35 | namespace OpenSim.Framework |
36 | { | 36 | { |
37 | |||
37 | public sealed class PacketPool | 38 | public sealed class PacketPool |
38 | { | 39 | { |
39 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 40 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
@@ -44,6 +45,9 @@ namespace OpenSim.Framework | |||
44 | 45 | ||
45 | private readonly Dictionary<PacketType, Stack<Packet>> pool = new Dictionary<PacketType, Stack<Packet>>(); | 46 | private readonly Dictionary<PacketType, Stack<Packet>> pool = new Dictionary<PacketType, Stack<Packet>>(); |
46 | 47 | ||
48 | private static Dictionary<Type, List<Object>> DataBlocks = | ||
49 | new Dictionary<Type, List<Object>>(); | ||
50 | |||
47 | static PacketPool() | 51 | static PacketPool() |
48 | { | 52 | { |
49 | } | 53 | } |
@@ -136,6 +140,28 @@ namespace OpenSim.Framework | |||
136 | /// <param name="packet"></param> | 140 | /// <param name="packet"></param> |
137 | public void ReturnPacket(Packet packet) | 141 | public void ReturnPacket(Packet packet) |
138 | { | 142 | { |
143 | switch (packet.Type) | ||
144 | { | ||
145 | case PacketType.ObjectUpdate: | ||
146 | ObjectUpdatePacket oup = (ObjectUpdatePacket)packet; | ||
147 | |||
148 | foreach (ObjectUpdatePacket.ObjectDataBlock oupod in | ||
149 | oup.ObjectData) | ||
150 | ReturnDataBlock<ObjectUpdatePacket.ObjectDataBlock>(oupod); | ||
151 | oup.ObjectData = null; | ||
152 | break; | ||
153 | |||
154 | case PacketType.ImprovedTerseObjectUpdate: | ||
155 | ImprovedTerseObjectUpdatePacket itoup = | ||
156 | (ImprovedTerseObjectUpdatePacket)packet; | ||
157 | |||
158 | foreach (ImprovedTerseObjectUpdatePacket.ObjectDataBlock | ||
159 | itoupod in itoup.ObjectData) | ||
160 | ReturnDataBlock<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>(itoupod); | ||
161 | itoup.ObjectData = null; | ||
162 | break; | ||
163 | } | ||
164 | |||
139 | if (!packetPoolEnabled) | 165 | if (!packetPoolEnabled) |
140 | return; | 166 | return; |
141 | 167 | ||
@@ -163,5 +189,45 @@ namespace OpenSim.Framework | |||
163 | return; | 189 | return; |
164 | } | 190 | } |
165 | } | 191 | } |
192 | |||
193 | public static T GetDataBlock<T>() where T: new() | ||
194 | { | ||
195 | lock(DataBlocks) | ||
196 | { | ||
197 | if (DataBlocks.ContainsKey(typeof(T)) && DataBlocks[typeof(T)].Count > 0) | ||
198 | { | ||
199 | T block = (T)DataBlocks[typeof(T)][0]; | ||
200 | DataBlocks[typeof(T)].RemoveAt(0); | ||
201 | if (block == null) | ||
202 | return new T(); | ||
203 | return block; | ||
204 | } | ||
205 | else | ||
206 | { | ||
207 | return new T(); | ||
208 | } | ||
209 | } | ||
210 | } | ||
211 | |||
212 | public static void ReturnDataBlock<T>(T block) where T: new() | ||
213 | { | ||
214 | if (block == null) | ||
215 | return; | ||
216 | |||
217 | lock (DataBlocks) | ||
218 | { | ||
219 | if (!DataBlocks.ContainsKey(typeof(T))) | ||
220 | { | ||
221 | List<Object> l = new List<Object>(); | ||
222 | l.Add(block); | ||
223 | DataBlocks.Add(typeof(T), l); | ||
224 | } | ||
225 | else | ||
226 | { | ||
227 | if (DataBlocks[typeof(T)].Count < 500) | ||
228 | DataBlocks[typeof(T)].Add(block); | ||
229 | } | ||
230 | } | ||
231 | } | ||
166 | } | 232 | } |
167 | } | 233 | } |