How to minimize memory allocation of mod_perl script?

自闭症网瘾萝莉.ら 提交于 2019-12-12 05:36:31

问题


I have created a simple perl script. The only thing it does is waiting for 5 seconds.

When I spawn the script on the server through mod_perl, it takes a lot of memory. The instance takes 36 megabytes.

Why there is so much memory is allocated? How can I minimize the memory taken from the system by the running script?

This is the output of "top" utility when running 2 scripts.

 5162 www-data  25   0 36732 8124 2868 S  1.3  3.1   0:00.05 apache2
 5161 www-data  25   0 36732 8124 2868 S  0.7  3.1   0:00.04 apache2

The script.

#!/usr/bin/perl
use CGI;

my $query= new CGI;
my $content = "5 second delay...\n";

$query->header(
    '-Content-type' => "text/plain",
    '-Content-Length' => length($content)
);

print $content;

sleep(5);

回答1:


No, it doesn't take 36 megabytes.

That's the amount of address space allocated in the process. It includes space that is mapped from executables, mmap()'d from files, and crucially space which is shared with other processes.

The vast majority of it will be shared with other processes (particularly other Apache worker processes).

To find out how much memory it's really using, get some Perl memory profiler on the job.



来源:https://stackoverflow.com/questions/1547590/how-to-minimize-memory-allocation-of-mod-perl-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!