简体   繁体   English

Perl perl-5.8.8-38 Vs perl-5.10.1-136.el6.x86_64线程内存泄漏

[英]Perl perl-5.8.8-38 Vs perl-5.10.1-136.el6.x86_64 Thread Memory leak

I am kind of new to perl. 我是perl的新手。 But I see this memory leak happening in thread implementation. 但是我看到在线程实现中发生了这种内存泄漏。 Versions compared perl-5.8.8-38 Vs perl-5.10.1-136.el6.x86_64 版本比较perl-5.8.8-38 Vs perl-5.10.1-136.el6.x86_64

code that I executed is 我执行的代码是

#!/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);
}

Output execution of above code Perl Version : perl-5.8.8-38 上面的代码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 ~]#

Output execution of above code Perl Version : perl-5.10.1-136.el6.x86_64 以上代码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]$

I have a indigeneous memory profiling utility as process_profiler which basically traverses the PID in proc filesystem task directory to see threads and brings out Memory information. 我有一个本地的内存配置实用程序process_profiler,它基本上遍历proc文件系统任务目录中的PID,以查看线程并显示内存信息。

Output of this profiler for code mentioned above on PERL version perl-5.8.8-38 对于上面在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   *

Output of this profiler for code mentioned above on PERL version perl-5.10.1-136.el6.x86_64 对于上面在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   *

I think there is memory lead happening on perl-5.10.1-136.el6.x86_64 . 我认为在perl-5.10.1-136.el6.x86_64上发生了内存问题。 Am I missing something here? 我在这里想念什么吗?


EDIT 编辑

ulimit for max stack size in both the cases is 10240KB. 在这两种情况下,最大堆栈大小的ulimit为10240KB。 Both are linux (x86_64) machines with 8GB RAM and 16GB swap. 两者都是具有8GB RAM和16GB交换空间的linux(x86_64)计算机。 kernel for perl version perl-5.8.8-38 = 2.6.18-308.11.1.el5.x86_64 kernel for perl version perl-5.10.1-136.el6.x86_64 = 2.6.32-431.el6.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

One of the things that catches people out with perl is memory usage. 使用Perl吸引人的原因之一是内存使用率。 Perl does it's own memory allocation and garbage collection, so if you watch it from an OS perspective... you'll get a distorted picture. Perl自己进行内存分配和垃圾回收,因此,如果从OS的角度观看它,则会得到一张失真的图片。 Usually you don't need to worry about 'tidying up' but you do need to be slightly careful to ensure that things are scoped appropriately. 通常,您无需担心“整理”,但需要稍加小心以确保对范围进行适当调整。 Globals are classic sources of memory leaks, for example, because you can keep adding elements to an array. 全局变量是内存泄漏的经典来源,例如,因为您可以继续向数组添加元素。

Pretty fundamentally though - as noted in the comments - your RSS doesn't change much over time. 但是,从根本上来说-如评论中所述-您的RSS不会随着时间的变化而改变。 It'd be hard to spot a memory leak over a matter of seconds anyway. 无论如何,很难在几秒钟内发现内存泄漏。 It therefore doesn't look like one - but it might be a bit more obvious with a much longer loop and cycle. 因此,它看起来不像一个-但在更长的循环和周期中可能会更明显。

Even if you have found a bug in perl 5.8 or 5.10... it's unlikely you'll find someone rush to analyse your bug, as they went end of life in 2008 and 2009 respectively. 即使您在perl 5.8或5.10中发现了一个错误,也不太可能发现有人急于分析您的错误,因为他们分别在2008年和2009年停产。 (And yes, I recognise this is an older post, it's still 5 years past EOL). (是的,我知道这是一篇较旧的文章,距EOL还剩5年了)。

Latest perl (5.20 at time of writing) can be found here: http://www.cpan.org/src/README.html 最新的perl(在撰写本文时为5.20)可以在以下位置找到: http : //www.cpan.org/src/README.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM