我是perl的新手。但我发现线程实现中发生了内存泄漏。 版本比较 Perl的5.8.8-38 VS Perl的5.10.1-136.el6.x86_64
我执行的代码是
#!/usr/bin/perl -w
my $pid = "$$";
my $profileCommand = "/export/user_share/builder/cyborgtools/process_profiler/bin/process_profiler $pid";
print "$profileCommand\n";
system("$profileCommand 2>&1 >> /var/log/processProfiler_exec.log &");
#use threads('stack_size' => 5242880);
use threads;
use threads::shared;
my $curr_size = threads->get_stack_size();
my @threads;
my @cmds = ( "Anugraha", "Rinky", "Pratyush", "Shubham" );
for my $cmd (@cmds) {
my $thread = threads->new( \&execCmd, $cmd );
push( @threads, $thread );
my $size = $thread->get_stack_size();
print "Invoked stack for $cmd with stack size $size\n";
}
foreach (@threads) {
$_->join;
}
print "Thread main entering into sleep mode (10 secs) after thread join\n";
sleep(10);
exit;
sub execCmd {
my ($threadCmd) = @_;
print "In execCmd for thread $threadCmd\n";
print "Entering sleep mode (5secs) for thread with cmd $threadCmd\n";
sleep(5);
}
输出上述代码的执行 Perl版本:perl-5.8.8-38
[root@my-machine ~]# ./temp.pl
/tmp/process_profiler 7216
Invoked stack for Anugraha with stack size 10485760
In execCmd for thread Anugraha
Entering sleep mode (5secs) for thread with cmd Anugraha
Invoked stack for Rinky with stack size 10485760
In execCmd for thread Rinky
Entering sleep mode (5secs) for thread with cmd Rinky
Invoked stack for Pratyush with stack size 10485760
Invoked stack for Shubham with stack size 10485760
In execCmd for thread Pratyush
Entering sleep mode (5secs) for thread with cmd Pratyush
In execCmd for thread Shubham
Entering sleep mode (5secs) for thread with cmd Shubham
Thread main entering into sleep mode (10 secs) after thread join
[root@my-machine ~]#
输出上述代码的执行 Perl版本:perl-5.10.1-136.el6.x86_64
[asinha@hydra-cyborgmother perl_thread_testing]$ ./temp.pl
/export/user_share/builder/cyborgtools/process_profiler/bin/process_profiler 9566
Invoked stack for Anugraha with stack size 10485760
In execCmd for thread Anugraha
Entering sleep mode (5secs) for thread with cmd Anugraha
Invoked stack for Rinky with stack size 10485760
In execCmd for thread Rinky
Entering sleep mode (5secs) for thread with cmd Rinky
Invoked stack for Pratyush with stack size 10485760
In execCmd for thread Pratyush
Entering sleep mode (5secs) for thread with cmd Pratyush
Invoked stack for Shubham with stack size 10485760
In execCmd for thread Shubham
Entering sleep mode (5secs) for thread with cmd Shubham
Thread main entering into sleep mode (10 secs) after thread join
[asinha@hydra-cyborgmother perl_thread_testing]$
我有一个独立的内存分析实用程序 process_profiler 它基本上遍历proc文件系统任务目录中的PID以查看线程 并带出记忆信息。
在PERL版本perl-5.8.8-38
上为上述代码输出此探查器---------------------------------------------------------------------------------------------
Date PID VmPeak VmSize VmHWM VmRSS VmData VmStk CmdLine Parent
---------------------------------------------------------------------------------------------
2014-09-26 05:02:33 7216 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl *
2014-09-26 05:02:34 7216 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl *
2014-09-26 05:02:34 7220 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl
2014-09-26 05:02:34 7225 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl
2014-09-26 05:02:34 7227 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl
2014-09-26 05:02:34 7231 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl
2014-09-26 05:02:35 7216 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl *
2014-09-26 05:02:35 7220 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl
2014-09-26 05:02:35 7225 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl
2014-09-26 05:02:35 7227 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl
2014-09-26 05:02:35 7231 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl
2014-09-26 05:02:36 7216 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl *
2014-09-26 05:02:36 7220 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl
2014-09-26 05:02:36 7225 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl
2014-09-26 05:02:36 7227 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl
2014-09-26 05:02:36 7231 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl
2014-09-26 05:02:37 7216 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl *
2014-09-26 05:02:37 7220 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl
2014-09-26 05:02:37 7225 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl
2014-09-26 05:02:37 7227 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl
2014-09-26 05:02:37 7231 225088KB 192136KB 5040KB 5040KB 110780KB 88KB /usr/bin/perl
2014-09-26 05:02:38 7216 225088KB 181220KB 5040KB 4948KB 99864KB 88KB /usr/bin/perl *
2014-09-26 05:02:39 7216 225088KB 181220KB 5040KB 4948KB 99864KB 88KB /usr/bin/perl *
2014-09-26 05:02:40 7216 225088KB 181220KB 5040KB 4948KB 99864KB 88KB /usr/bin/perl *
2014-09-26 05:02:41 7216 225088KB 181220KB 5040KB 4948KB 99864KB 88KB /usr/bin/perl *
2014-09-26 05:02:42 7216 225088KB 181220KB 5040KB 4948KB 99864KB 88KB /usr/bin/perl *
2014-09-26 05:02:43 7216 225088KB 181220KB 5040KB 4948KB 99864KB 88KB /usr/bin/perl *
2014-09-26 05:02:44 7216 225088KB 181220KB 5040KB 4948KB 99864KB 88KB /usr/bin/perl *
2014-09-26 05:02:45 7216 225088KB 181220KB 5040KB 4948KB 99864KB 88KB /usr/bin/perl *
2014-09-26 05:02:46 7216 225088KB 181220KB 5040KB 4948KB 99864KB 88KB /usr/bin/perl *
2014-09-26 05:02:47 7216 225088KB 181220KB 5040KB 4948KB 99864KB 88KB /usr/bin/perl *
在PERL版本perl-5.10.1-136.el6.x86_64上为上述代码输出此探查器
---------------------------------------------------------------------------------------------
Date PID VmPeak VmSize VmHWM VmRSS VmData VmStk CmdLine Parent
---------------------------------------------------------------------------------------------
2014-09-26 10:01:28 9566 129820KB 282600KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl *
2014-09-26 10:01:29 9566 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl *
2014-09-26 10:01:29 9574 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl
2014-09-26 10:01:29 9577 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl
2014-09-26 10:01:29 9581 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl
2014-09-26 10:01:29 9583 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl
2014-09-26 10:01:30 9566 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl *
2014-09-26 10:01:30 9574 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl
2014-09-26 10:01:30 9577 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl
2014-09-26 10:01:30 9581 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl
2014-09-26 10:01:30 9583 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl
2014-09-26 10:01:31 9566 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl *
2014-09-26 10:01:31 9574 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl
2014-09-26 10:01:31 9577 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl
2014-09-26 10:01:31 9581 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl
2014-09-26 10:01:31 9583 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl
2014-09-26 10:01:33 9566 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl *
2014-09-26 10:01:33 9574 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl
2014-09-26 10:01:33 9577 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl
2014-09-26 10:01:33 9581 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl
2014-09-26 10:01:33 9583 500636KB 435100KB 5540KB 5540KB 306888KB 88KB /usr/bin/perl
2014-09-26 10:01:34 9566 500636KB 424808KB 5540KB 5532KB 296596KB 88KB /usr/bin/perl *
2014-09-26 10:01:35 9566 500636KB 424808KB 5540KB 5532KB 296596KB 88KB /usr/bin/perl *
2014-09-26 10:01:36 9566 500636KB 424808KB 5540KB 5532KB 296596KB 88KB /usr/bin/perl *
2014-09-26 10:01:37 9566 500636KB 424808KB 5540KB 5532KB 296596KB 88KB /usr/bin/perl *
2014-09-26 10:01:38 9566 500636KB 424808KB 5540KB 5532KB 296596KB 88KB /usr/bin/perl *
2014-09-26 10:01:39 9566 500636KB 424808KB 5540KB 5532KB 296596KB 88KB /usr/bin/perl *
2014-09-26 10:01:40 9566 500636KB 424808KB 5540KB 5532KB 296596KB 88KB /usr/bin/perl *
2014-09-26 10:01:41 9566 500636KB 424808KB 5540KB 5532KB 296596KB 88KB /usr/bin/perl *
2014-09-26 10:01:42 9566 500636KB 424808KB 5540KB 5532KB 296596KB 88KB /usr/bin/perl *
2014-09-26 10:01:43 9566 500636KB 424808KB 5540KB 5532KB 296596KB 88KB /usr/bin/perl *
我认为在perl-5.10.1-136.el6.x86_64上会发生内存导致。 我在这里错过了什么吗?
修改
两种情况下最大堆栈大小的ulimit为10240KB。两者都是具有8GB RAM和16GB交换的linux(x86_64)机器。 perl版本的内核perl-5.8.8-38 = 2.6.18-308.11.1.el5.x86_64 perl版本的内核perl-5.10.1-136.el6.x86_64 = 2.6.32-431.el6.x86_64
答案 0 :(得分:0)
使用perl捕获人员的一个方面是内存使用。 Perl做它自己的内存分配和垃圾收集,所以如果你从操作系统的角度来看它......你会得到一个扭曲的图片。通常你不需要担心“整理”,但你需要小心谨慎,以确保适当的范围。例如,Globals是内存泄漏的经典来源,因为您可以继续向数组添加元素。
但从根本上说 - 如评论中所述 - 您的RSS随着时间的推移不会有太大变化。无论如何,很难在几秒钟内发现内存泄漏。因此它看起来不像一个 - 但是对于更长的循环和循环,它可能会更明显。
即使你在perl 5.8或5.10中发现了一个错误...你也不太可能发现有人急于分析你的错误,因为它们分别在2008年和2009年结束了。 (是的,我知道这是一个较旧的帖子,它仍然是EOL的5年)。
最新的perl(撰写本文时为5.20)可在此处找到:http://www.cpan.org/src/README.html