Issue Details (XML | Word | Printable)

Key: LIBOMV-338
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: John Hurliman
Reporter: Jim Radford
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
libopenmetaverse

UDPBufferPool not releasing pool resources on simulator change

Created: 30/Jul/08 12:19 PM   Updated: 30/Jul/08 02:46 PM
Component/s: None
Affects Version/s: None
Fix Version/s: 0.6.0

File Attachments: 1. Text File Fix Memoryleak.patch (7 kB)

Issue Links:
Related
 

Environment: All


 Description  « Hide
http://spreadsheets.google.com/pub?key=pyEqx74GpYgjLwz5i8CFpLw

The UDPBufferPool class appears to need some work on its resource handling, still working on the exact details.

This came to light by profiling some code.



 All   Comments   Change History   Subversion Commits   Patches      Sort Order: Ascending order - Click to sort in descending order
John Hurliman added a comment - 30/Jul/08 12:25 PM
Fixed this in r2034 by changing over to a singleton pattern for the packet buffer pool. I also reduced the number of buffers per segment from 64 to 16 which will cut default memory usage for the object pool to a quarter.

div0 added a comment - 30/Jul/08 02:04 PM
I debugged that issue on the weekend also. The main cause is that the timer of the ObjectPoolBase never gets stopped because a pool never gets disposed! So the ObjectPoolBase, its segments and buffers are never removed from the memory when a new simulator is created.

I came across a slightly other solution. I just dispose the pool on stop of the UDPBuffer. That works perfect for me. I'm not sure if 16 is really a good choice I think I saw about 25 used buffers per pool when I traced the problem. But not sure on that. Who gives a damn about memory anyway those days - at least if it isn't a leak?

Does the singleton handle multiple clients well? I could imagine it leads to some locking overhead? But I must say a singleton is a clever workaround or did you also realize, that the timer is the root cause? Always free unmanaged resources

I attached my patch. Feel free to do whatever you want with it. Bases on rev 2009 of ObjectPoolBase.cs and UDPBase.cs.


John Hurliman added a comment - 30/Jul/08 02:46 PM
The 16 value is the segment size, the pool will allocate new segments as needed. Lots of small applications can easily get by with a single segment of 16. If it gets into more heavy lifting it might allocate one additional segment, which will be held on to for about five minutes before determining if that segment should be destroyed.

Thank you for spotting that it was the timer, I figured it was something in the pool keeping things alive but never dived in to see exactly what. I switched to the singleton because the pool is designed to be used with as many packet buffers as the application has. Splitting it up into multiple pools doesn't help since that is already done at the pool level with the concept of segments. Before this patch a pool had a default segment size of 64, each packet buffer was 2048 + 4096 bytes, and one pool was allocated per simulator (by default you connect to the simulator you are in and four around you). That meant something like 1,920KB of memory used just for the packet buffer pool when a client would log in. Now that's been scaled down to 96KB at login, and even very active clients should not use more than 192KB for the pools.

Thank you for tracking this down!