搜索 Apache httpd 和模块中的内存泄漏
查找 Apache httpd 和 httpd 模块中内存泄漏的最佳方法是什么?
有什么方法吗?
我尝试了一下 valgrind,但出现了一些障碍:
- Valgrind 期望二进制文件正常退出。我已经设法使用 MaxRequestsPerChild 和 -X 参数来做到这一点。
- Valgrind 报告了很多东西,可能与 apr 池有关,但没有什么用处。
操作系统:Linux
P.S.:Valgrind
命令:$ valgrind --leak-check=full --leak-resolution=med --log-file=/tmp/valgrind.log ./bin/httpd -X
Valgrind 输出示例: http://paste-it.net/public/x5b6e8b/
What is the best way for finding memory leaks in Apache httpd and httpd modules?
Are there any howtos?
I'v tried valgrind a little, but few obstacles appeared:
- Valgrind expects for binary to exit normally. I have managed to do that with MaxRequestsPerChild and -X parameter.
- Valgrind reports about lots of stuff, probably connected with apr pools, but nothing useful.
OS: Linux
P.S.:
Valgrind command: $ valgrind --leak-check=full --leak-resolution=med --log-file=/tmp/valgrind.log ./bin/httpd -X
Valgrind output example: http://paste-it.net/public/x5b6e8b/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道有什么灵丹妙药,但是你可以看看 valgrind/valgrind.h ,它有一些有用的宏,可以让 Valgrind 意识到并改变它们在 Valgrind 下运行时的行为。
例如,
您还可以使用 NDEBUG 封装整个混乱,以使其远离生产版本。
这应该可以让您不必在每次调试时摆弄服务器,如果检测到 Valgrind,它就会“直接执行”。 RUNNING_ON_VALGRIND 将扩展到 valgrind 实例,或者如果不适用则保留为 0。
对于其余部分(我想象您会收到大量噪音,最有可能从
大小 xx 的无效读取
开始),您可以系统地应用抑制。如果您发布一些输出,则可以更轻松地为可以粘贴在文件中的抑制提出建议。顺便说一句,Valgrind 用户的邮件列表非常有帮助并且非常宽容。您还可以在那里发布您最烦人且不相关的噪音,您会得到有关如何快速抑制它的回复。
如果您想要的只是泄漏的摘要以及导致泄漏的入口点,那么关闭几乎所有其他内容应该不会太困难。
I don't know of a magic bullet, but you can have a look at valgrind/valgrind.h , it has some useful macros to make things Valgrind aware and alter their behavior if running under Valgrind.
For instance
You can also encase that whole mess with
NDEBUG
to keep it out of production builds.That should save you from having to fiddle with the server each time you debug, it will 'just do it' if Valgrind is detected. RUNNING_ON_VALGRIND will expand to the valgrind instance, or remain 0 if not applicable.
For the rest (and I'm imagining you are getting a ton of noise, most likely starting with
invalid read of size xx
), you can systematically apply suppressions. If you post some of the output, it might be easier to make suggestions for the suppressions you can stick in a file.Incidentally, the Valgrind user's mailing list is extremely helpful and very tolerant. You can also post your most annoying and irrelevant noise there, you'll get replies with how to suppress it rather quickly.
If all you want is a summary of leaks and the entry points that led to them, it should not be too difficult to shut almost everything else up.
您可以尝试集成 Bohem GC,并让垃圾收集来检测内存泄漏。
请参阅此处的操作方法:
http://www.hpl.hp.com/personal/Hans_Boehm/ gc/leak.html
You might give it a try for integrating Bohem GC and let garbage collection to detect memory leaks.
Just see here for howto:
http://www.hpl.hp.com/personal/Hans_Boehm/gc/leak.html
也许是时候重构代码以便可以在 apache 之外运行测试了?
如果添加单元测试来检查分配内存的代码路径,则可以通过在 valgrind 下运行单元测试来验证所有内存是否已释放。这样您就不必担心在 apache 下运行的完整代码只能处理少量事务。此外,通过单元测试测试所有代码路径也会更容易。
Maybe it's time to refactor the code so that you can run tests outside apache?
If you add unit tests that check code paths that allocate memory, you can verify that all the memory is freed, by running the unit tests under valgrind. That way you don't have to worry about making the full code running under apache handle only small numbers of transactions. Also it'll be easier to test all code paths with unit tests.