如何追踪 mod_perl 内存泄漏?
我正在使用 mod perl 1.3.0 和 apache 1.3.41 perl 版本 5.8.6,并且内存大小似乎每第 3 个或第 4 个请求就会增长约 4k。 我们运行的 Perl 脚本很简单:
print "Content-type: text/html\n\n"; print "baby";
然而,当我们用 apache 基准测试来攻击它时,apache 进程就会不断增长。 我们正在解决这个问题:
ab -n 100000 -c 1 http://localhost/search/search.cgi &> /dev/null
在大约 20000 个请求之后,我们观察到进程大小从大约 4 MB 增长到 24 MB。
回答以下问题: 我们正在 redhat enterprise 4.7 上执行此操作。 它被单独挑出来是因为我们遇到了一个静态文件,或者一个直接的 cgi 请求,并且内存不会增长。 当我们使用 PerlHandler Apache::Registry 或 PerlRun 时,或者只是将 PerlHandler 指向作为处理程序的某些代码时,它们都会泄漏。
有谁见过这样的事情,或者知道这是怎么回事吗?
编辑:
谢谢你们的回答。 我使用了 Devel::Cycle 并发现了泄漏,但这里的问题是我们已经精简了代码以打印标题和语句。 Perl 中的 print 函数不可能泄漏(我希望......)。 我读过 Practical Modperl 中的内存泄漏部分,但它涉及编码问题,并且除非 Perl 的打印功能存在问题,否则它不是代码。
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. The Perl script we are running is simply:
print "Content-type: text/html\n\n"; print "baby";
Yet that apache process just grows and grows when we slam it with apache benchmark. 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.
To answer the question below:
We are doing this on 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. 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.
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. There is no way the print function in Perl leaks (I hope....). 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否看过优秀的 实用 mod_perl 及其 关于内存泄漏的章节?
Have you taken a look at the excellent Practial mod_perl and its chapter on memory leaks?
由于您只需要打印语句,您确定没有加载任何其他模块吗? 您正在加载的其他人的代码中可能存在泄漏。
当你运行这个时你会得到什么:
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:
如果可能,请使用 Devel::Cycle 运行代码。 内存泄漏很可能发生在代码的某个地方,而不是专门在 mod_perl 中。
一旦找到内存泄漏(可能有多个),请修复它们。
If possible, run your code with Devel::Cycle. Chances are you have a memory leak someplace in your code, not in mod_perl specifically.
Once you've located the memory leak(s) - there may be several - fix them.
在我看来这些东西都是由apache加载的。
Looks like to me these things are all loaded by apache.