我正在尝试学习如何配置perl内存.
我有一个非常简单的Perl hello-world脚本,我想知道它在内存中的大小.
我使用GTop实用程序来测量内存(Stas Beckman为recommended in mod_perl book).
GTop提供的结果令我感到困惑.
当我从命令行运行脚本时,GTop说:7M.
当我在mod_perl下运行时,GTop说:54M.
为什么这么多?!
为什么脚本内存在mod_perl下增长如此之多?
或者我可能以错误的方式测量内存?
你如何描述perl脚本内存?
>从命令行运行
> perl simple.pl size: 7,282688 share: 2,027520 diff: 5,255168
>在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";
解决方法
我想当你在mod_perl下运行你的脚本时,你得到你的脚本的内存使用量,加上mod_perl的,加上apache的.
另见这些问题的答案:
> How can I programmatically determine my Perl program’s memory usage under Windows?
> Perl memory usage profiling and leak detection?