How to minimize memory allocation of mod_perl scri

2019-09-05 04:19发布

问题:

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.