This sample script:
#!/usr/bin/perl -w
while (1)
{
sleep(1);
}
takes about 264 kB
grep -A1 heap /proc/9216/smaps
0817b000-081bd000 rw-p 0817b000 00:00 0 [heap]
Size: 264 kB
but when I only add my module:
#!/usr/bin/perl -w
use my_module;
while (1)
{
sleep(1);
}
it takes 18092 kB !
grep -A1 heap /proc/9219maps
0817b000-09326000 rw-p 0817b000 00:00 0 [heap]
Size: 18092 kB
Note: The ‘my_module’ has a lot of ‘use module;’ inside it.
How can I find what takes so much memory ?
How can I reduce it ? (using ‘use module (function)’ ?)
Thanks for your help.
Insert
BEGIN {}blocks to narrow down the culprit as inOn my Linux host, I see
As for what to do about it, you could implement replacement modules with scaled down functionality or ask yourself whether you really need a particular module at all. However, in general, perl’s design prefers to throw memory at problems, and these days it’s common for machines to have multiple gibibytes of main memory.
Is this resource issue causing performance problems?
Below is a program that reads through the list of modules in
perlmodlib.podand for each module forks a child torequireandimportit and check its own heap.The top few offenders for perl-5.8.8: