diff options
author | Justin Clark-Casey (justincc) | 2012-10-16 23:35:05 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-10-16 23:35:05 +0100 |
commit | fc861c7904840b2b0b9de0621e9b5d976c8071b1 (patch) | |
tree | a0ed86f346171665d95196c33ec952ddd3753883 /OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs | |
parent | Make it possible to separate start and stop lludp packet processing from the ... (diff) | |
download | opensim-SC-fc861c7904840b2b0b9de0621e9b5d976c8071b1.zip opensim-SC-fc861c7904840b2b0b9de0621e9b5d976c8071b1.tar.gz opensim-SC-fc861c7904840b2b0b9de0621e9b5d976c8071b1.tar.bz2 opensim-SC-fc861c7904840b2b0b9de0621e9b5d976c8071b1.tar.xz |
Add optional pool for the UDPPacketBuffer objects that handle all incoming UDP data.
Even when an avatar is standing still, it's sending in a constant stream of AgentUpdate packets that the client creates new UDPPacketBuffer objects to handle.
This option pools those objects. This reduces memory churn.
Currently off by default. Works but the scope can be expanded.
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs index 828c23c..6e6b3ef 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs | |||
@@ -30,6 +30,7 @@ using System.Net; | |||
30 | using System.Net.Sockets; | 30 | using System.Net.Sockets; |
31 | using System.Threading; | 31 | using System.Threading; |
32 | using log4net; | 32 | using log4net; |
33 | using OpenSim.Framework; | ||
33 | 34 | ||
34 | namespace OpenMetaverse | 35 | namespace OpenMetaverse |
35 | { | 36 | { |
@@ -58,6 +59,16 @@ namespace OpenMetaverse | |||
58 | /// <summary>Flag to process packets asynchronously or synchronously</summary> | 59 | /// <summary>Flag to process packets asynchronously or synchronously</summary> |
59 | private bool m_asyncPacketHandling; | 60 | private bool m_asyncPacketHandling; |
60 | 61 | ||
62 | /// <summary> | ||
63 | /// Pool to use for handling data. May be null if UsePools = false; | ||
64 | /// </summary> | ||
65 | protected OpenSim.Framework.Pool<UDPPacketBuffer> m_pool; | ||
66 | |||
67 | /// <summary> | ||
68 | /// Are we to use object pool(s) to reduce memory churn when receiving data? | ||
69 | /// </summary> | ||
70 | public bool UsePools { get; protected set; } | ||
71 | |||
61 | /// <summary>Returns true if the server is currently listening for inbound packets, otherwise false</summary> | 72 | /// <summary>Returns true if the server is currently listening for inbound packets, otherwise false</summary> |
62 | public bool IsRunningInbound { get; private set; } | 73 | public bool IsRunningInbound { get; private set; } |
63 | 74 | ||
@@ -70,6 +81,7 @@ namespace OpenMetaverse | |||
70 | /// </summary> | 81 | /// </summary> |
71 | /// <param name="bindAddress">Local IP address to bind the server to</param> | 82 | /// <param name="bindAddress">Local IP address to bind the server to</param> |
72 | /// <param name="port">Port to listening for incoming UDP packets on</param> | 83 | /// <param name="port">Port to listening for incoming UDP packets on</param> |
84 | /// /// <param name="usePool">Are we to use an object pool to get objects for handing inbound data?</param> | ||
73 | public OpenSimUDPBase(IPAddress bindAddress, int port) | 85 | public OpenSimUDPBase(IPAddress bindAddress, int port) |
74 | { | 86 | { |
75 | m_localBindAddress = bindAddress; | 87 | m_localBindAddress = bindAddress; |
@@ -94,6 +106,11 @@ namespace OpenMetaverse | |||
94 | /// necessary</remarks> | 106 | /// necessary</remarks> |
95 | public void StartInbound(int recvBufferSize, bool asyncPacketHandling) | 107 | public void StartInbound(int recvBufferSize, bool asyncPacketHandling) |
96 | { | 108 | { |
109 | if (UsePools) | ||
110 | m_pool = new Pool<UDPPacketBuffer>(() => new UDPPacketBuffer(), 500); | ||
111 | else | ||
112 | m_pool = null; | ||
113 | |||
97 | m_asyncPacketHandling = asyncPacketHandling; | 114 | m_asyncPacketHandling = asyncPacketHandling; |
98 | 115 | ||
99 | if (!IsRunningInbound) | 116 | if (!IsRunningInbound) |
@@ -165,9 +182,12 @@ namespace OpenMetaverse | |||
165 | 182 | ||
166 | private void AsyncBeginReceive() | 183 | private void AsyncBeginReceive() |
167 | { | 184 | { |
168 | // allocate a packet buffer | 185 | UDPPacketBuffer buf; |
169 | //WrappedObject<UDPPacketBuffer> wrappedBuffer = Pool.CheckOut(); | 186 | |
170 | UDPPacketBuffer buf = new UDPPacketBuffer(); | 187 | if (UsePools) |
188 | buf = m_pool.GetObject(); | ||
189 | else | ||
190 | buf = new UDPPacketBuffer(); | ||
171 | 191 | ||
172 | if (IsRunningInbound) | 192 | if (IsRunningInbound) |
173 | { | 193 | { |
@@ -231,8 +251,6 @@ namespace OpenMetaverse | |||
231 | 251 | ||
232 | // get the buffer that was created in AsyncBeginReceive | 252 | // get the buffer that was created in AsyncBeginReceive |
233 | // this is the received data | 253 | // this is the received data |
234 | //WrappedObject<UDPPacketBuffer> wrappedBuffer = (WrappedObject<UDPPacketBuffer>)iar.AsyncState; | ||
235 | //UDPPacketBuffer buffer = wrappedBuffer.Instance; | ||
236 | UDPPacketBuffer buffer = (UDPPacketBuffer)iar.AsyncState; | 254 | UDPPacketBuffer buffer = (UDPPacketBuffer)iar.AsyncState; |
237 | 255 | ||
238 | try | 256 | try |
@@ -249,7 +267,8 @@ namespace OpenMetaverse | |||
249 | catch (ObjectDisposedException) { } | 267 | catch (ObjectDisposedException) { } |
250 | finally | 268 | finally |
251 | { | 269 | { |
252 | //wrappedBuffer.Dispose(); | 270 | if (UsePools) |
271 | m_pool.ReturnObject(buffer); | ||
253 | 272 | ||
254 | // Synchronous mode waits until the packet callback completes | 273 | // Synchronous mode waits until the packet callback completes |
255 | // before starting the receive to fetch another packet | 274 | // before starting the receive to fetch another packet |