简体   繁体   English

如何追踪mod_perl内存泄漏?

[英]How do I track down a mod_perl memory leak?

I'm using mod perl 1.3.0 with apache 1.3.41 perl version 5.8.6, and the memory size seems to grow about 4k every 3rd or 4th request. 我正在使用mod perl 1.3.0和apache 1.3.41 perl版本5.8.6,内存大小似乎每3或4次请求增加大约4k。 The Perl script we are running is simply: 我们运行的Perl脚本很简单:

print "Content-type: text/html\n\n";  print "baby";

Yet that apache process just grows and grows when we slam it with apache benchmark. 然而,当我们用apache基准测试时,apache进程只会增长和增长。 We are hitting it with: 我们正在努力:

ab -n 100000 -c 1 http://localhost/search/search.cgi &> /dev/null

and we watch as the process size grows from about 4 megabytes to 24 after about 20000 requests. 我们观察到,在大约20000个请求之后,进程大小从大约4兆字节增长到24小时。

To answer the question below: We are doing this on redhat enterprise 4.7. 要回答以下问题:我们在redhat enterprise 4.7上这样做。 Its been singled out as this because we hit a static file, or a straight up cgi request and the memory does not grow. 因为我们点击了一个静态文件,或一个直接的cgi请求而内存没有增长,所以它被单独列出了。 When we use a PerlHandler Apache::Registry or PerlRun, or just point the PerlHandler to some code that is a handler, then they all leak. 当我们使用PerlHandler Apache :: Registry或PerlRun,或者只是将PerlHandler指向一些处理程序的代码时,它们都会泄漏。

Anyone seen anything like this, or know whats going on? 有人看过这样的事情,或知道发生了什么事吗?

EDIT: 编辑:

Thanks for the answers guys. 谢谢你的回答。 I have used Devel::Cycle and found a leak, but the issue here is we have stripped down our code to printing the header and a statement. 我使用了Devel :: Cycle并发现了泄漏,但问题是我们已经删除了我们的代码来打印标题和声明。 There is no way the print function in Perl leaks (I hope....). Perl中的打印功能无法泄漏(我希望......)。 The memory leak section in Practical Modperl I have read, but it deals with coding issues, and again unless there is an issue with Perl's print function it is not the code. 实际Modperl中的内存泄漏部分已经阅读,但它处理编码问题,并且除非Perl的打印功能存在问题,否则它不是代码。

您是否看过优秀的Practial mod_perl及其关于内存泄漏的章节

Since you're down to a print statement, are you sure that you are not loading any other modules? 由于您需要打印声明,您确定没有加载任何其他模块吗? There might be a leak in someone else's code that you are loading. 您正在加载的其他人的代码中可能存在泄漏。

What do you get when you run this: 你运行这个时得到了什么:

package My::Handler;

use strict;
use warnings 'all';
use Data::Dumper;

sub handler : method {
  my ($class, $r) = @_;

  print "content-type: text/html\n\n<plaintext>";
  print Dumper( \%INC );
}

1;# return true:

If possible, run your code with Devel::Cycle. 如果可能,使用Devel :: Cycle运行代码。 Chances are you have a memory leak someplace in your code , not in mod_perl specifically. 您的代码中某处可能存在内存泄漏,而不是特定于mod_perl。

Once you've located the memory leak(s) - there may be several - fix them. 一旦找到内存泄漏 - 可能有几个 - 修复它们。

$VAR1 = {
    'XSLoader.pm' => '/usr/local/lib/perl5/5.8.6/i686-linux/XSLoader.pm',
    'mod_perl.pm' => '/usr/local/lib/perl5/site_perl/5.8.6/i686-linux/mod_perl.pm', 
    'warnings/register.pm' => '/usr/local/lib/perl5/5.8.6/warnings/register.pm',
    'Apache/DBI.pm' => '/usr/local/lib/perl5/site_perl/5.8.6/Apache/DBI.pm',
    'List/Util.pm' => '/usr/local/lib/perl5/5.8.6/i686-linux/List/Util.pm',
    'Test.pm' => '/home/jodonnell/fashion_2009//Test.pm', 
    'Apache/Server.pm' => '/usr/local/lib/perl5/site_perl/5.8.6/i686-linux/Apache/Server.pm', 
    'warnings.pm' => '/usr/local/lib/perl5/5.8.6/warnings.pm',
    'DBI.pm' => '/usr/local/lib/perl5/site_perl/5.8.6/i686-linux/DBI.pm',
    'Config.pm' => '/usr/local/lib/perl5/5.8.6/i686-linux/Config.pm',
    'bytes.pm' => '/usr/local/lib/perl5/5.8.6/bytes.pm',
    'Carp.pm' => '/usr/local/lib/perl5/5.8.6/Carp.pm',
    'Exporter/Heavy.pm' => '/usr/local/lib/perl5/5.8.6/Exporter/Heavy.pm',
    'Scalar/Util.pm' => '/usr/local/lib/perl5/5.8.6/i686-linux/Scalar/Util.pm',
    'vars.pm' => '/usr/local/lib/perl5/5.8.6/vars.pm',
    'Exporter.pm' => '/usr/local/lib/perl5/5.8.6/Exporter.pm',
    'strict.pm' => '/usr/local/lib/perl5/5.8.6/strict.pm',
    'Apache.pm' => '/usr/local/lib/perl5/site_perl/5.8.6/i686-linux/Apache.pm',
    'constant.pm' => '/usr/local/lib/perl5/5.8.6/constant.pm',
    'overload.pm' => '/usr/local/lib/perl5/5.8.6/overload.pm',
    'AutoLoader.pm' => '/usr/local/lib/perl5/5.8.6/AutoLoader.pm',
    'Apache/Constants.pm' => '/usr/local/lib/perl5/site_perl/5.8.6/i686-linux/Apache/Constants.pm',
    'Apache/Constants/Exports.pm' => '/usr/local/lib/perl5/site_perl/5.8.6/i686-linux/Apache/Constants/Exports.pm',
    'Apache/Connection.pm' => '/usr/local/lib/perl5/site_perl/5.8.6/i686-linux/Apache/Connection.pm',
    'DynaLoader.pm' => '/usr/local/lib/perl5/5.8.6/i686-linux/DynaLoader.pm', 
    'Data/Dumper.pm' => '/usr/local/lib/perl5/5.8.6/i686-linux/Data/Dumper.pm'
}; 

Looks like to me these things are all loaded by apache. 看起来这些东西都是由apache加载的。

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

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