为什么我的脚本在使用mod_perl运行时会占用更多内存?

Pav*_*vel 4 perl memory-management mod-perl

我正在尝试学习如何配置perl内存.

我有一个非常简单的Perl hello-world脚本,我想知道它在内存中的大小.

我使用GTop实用程序来测量内存(Stas Beckman 在mod_perl中推荐).GTop提供的结果令我感到困惑.

当我从命令行运行脚本时,GTop说:7M.

当我运行它时mod_perl,GTop说:54M.

为什么这么多?!

为什么脚本内存增长如此之多mod_perl?或者我可能以错误的方式测量内存?你如何描述perl脚本内存?

这是脚本及其输出(我手动添加了逗号以轻松读取数字)

  1. 从命令行运行

    > perl simple.pl 
    
    size: 7,282688
    share: 2,027520
    diff: 5,255168
    
  2. 在mod_perl下运行

    size: 54,878208
    share: 4,661248
    diff: 50,216960
    

脚本simple.pl

#!/usr/bin/perl

use strict;
use warnings;
use CGI ();

my $cgi = CGI->new;

print $cgi->header('text/plain');

use GTop;

print "Hello, world!\n";
my $m = GTop->new->proc_mem($$);
print "size: ".$m->size."\n";
print "share: ".$m->share."\n";
my $diff = $m->size - $m->share;
print "diff: $diff\n";
Run Code Online (Sandbox Code Playgroud)

inn*_*naM 7

我想当你在mod_perl下运行你的脚本时,你得到你的脚本的内存使用量,加上mod_perl的,加上apache的.

另见这些问题的答案: