What can I do to find out what's causing my program to consume lots of memory over time?

StackOverflow https://stackoverflow.com/questions/4395296

  •  10-10-2019
  •  | 
  •  

Question

I have an application using POE which has about 10 sessions doing various tasks. Over time, the app starts consuming more and more RAM and this usage doesn't go down even though the app is idle 80% of the time. My only solution at present is to restart the process often.

I'm not allowed to post my code here so I realize it is difficult to get help but maybe someone can tell me what I can do find out myself?

Was it helpful?

Solution

Don't expect the process size to decrease. Memory isn't released back to the OS until the process terminates.

That said, might you have reference loops in data structures somewhere? AFAIK, the perl garbage collector can't sort out reference loops.

Are you using any XS modules anywhere? There could be leaks hidden inside those.

OTHER TIPS

A guess: your program executes a loop for as long as it is running; in this loop it may be that you allocate memory for a buffer (or more) each time some condition occurs; since the scope is never exited, the memory remains and will never be cleaned up. I suggest you check for something like this. If it is the case, place the allocating code in a sub that you call from the loop and where it will go out of scope, and get cleaned up, on return to the loop.

Looks like Test::Valgrind is a tool for searching for memory leaks. I've never used it myself though (but I used plain valgrind with C source).

One technique is to periodically dump the contents of $POE::Kernel::poe_kernel to a time- or sequence-named file. $poe_kernel is the root of a tree spanning all known sessions and the contents of their heaps. The snapshots should monotonically grow if the leaked memory is referenced. You'll be able to find out what's leaking by diff'ing an early snapshot with a later one.

You can export POE_ASSERT_DATA=1 to enable POE's internal data consistency checks. I don't expect it to surface problems, but if it does I'd be very happy to receive a bug report.

Perl can not resolve reference rings. Either you have zombies (which you can detect via ps axl) or you have a memory leak (reference rings/circle)

There are a ton of programs to detect memory leaks. strace, mtrace, Devel::LeakTrace::Fast, Devel::Cycle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top