Re: Perl - release memory
by Joost (Canon) on Dec 14, 2008 at 12:32 UTC
|
| [reply] |
Re: Perl - release memory
by ysth (Canon) on Dec 14, 2008 at 12:33 UTC
|
After the few minutes are up, the extra 250Mb won't be actively in use, so it will be paged out when other applications need to use the memory. In other words, don't worry about it.
| [reply] |
|
|
Are you sure? Other applications exit with an "Out of memory error" after exhausting the swap partition. The perl process doesn't release it.
| [reply] |
|
|
The obvious solution to that is "increase your swap." Why worry about memory issues when disk space is so cheap? (I get the same problem at $work, too, and it frustrates me to no end - they don't realise that for about 1 day of my pay, they could get a TB of disk space, and practically never worry about swap space again, whereas NOT doing so will cost me weeks in debugging and reorganisation.)
Now, assuming your IT management is about as sensical as mine, the solution is (probably - we don't really have enough info to be sure) to fork prior to doing the heavy work, and then exit the subprocess when it's done. The subprocess' memory will be freed, but the parent will continue to live and monitor. It's probably the cheapest approach to the problem.
| [reply] |
|
|
|
|
|
|
Re: Perl - release memory
by zentara (Cardinal) on Dec 14, 2008 at 14:52 UTC
|
One thing to try is to put your memory intensive code into a thread. The memory should be released back to the system (not just to Perl), when the thread terminates. Try to use the latest version of threads from cpan.
| [reply] |
Re: Perl - release memory
by ysth (Canon) on Dec 14, 2008 at 19:06 UTC
|
If increasing your swap space is impossible for political reasons, the next easiest solution is to fork just before the memory intensive part and do it in the child, saving the results to a file for the parent to read if necessary, then exit. (threads, while a possible solution, would be much messier to implement.)
| [reply] |
Re: Perl - release memory
by matze77 (Friar) on Dec 14, 2008 at 13:23 UTC
|
Maybe your "unix toolbox" (i assume you use a *nix system?) could help, to figure out what components of your program use how much memory (pmap -q processid), lsof e.g. You could also tune the "swapiness" of your system to free some memory, Watch how much memory is allocated through shared libraries e.g. a google search should help to find the right parameters), eventually your programm could be optimised too, but thats beyond my experience ...
hth
MH
| [reply] |
Re: Perl - release memory
by Bloodnok (Vicar) on Dec 15, 2008 at 10:12 UTC
|
You don't say if the perl application is modifiable by you ... or if you have to manage the memory resources from a sysadmin POV.
If the former is true, as well as the excellent, predominantly thread orientated, suggestions thus far, it might be worth while checking that, assuming OO perl techniques are used in the application, there aren't a mass of otherwise unwanted objects being unnecessarily 'kept alive', thus consuming memory.
A user level that continues to overstate my experience :-))
| [reply] |