微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我正在尝试学习如何配置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?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐