Perl 和进程管理
我正在使用 Perl 开发一个相当大的企业应用程序,有数十个模块等,主要用于在网络上抓取一些东西。
我编写的子例程之一是进行图像检索和图像检索。分析。对于我发送给它的每个参数,通常需要几秒钟才能完成。所以我将其发送到不同的进程(分叉......)。问题是,一段时间后系统变得非常不稳定,内存已满。
问题:
- 是否因为创建的每个进程都会在单独的内存位置中创建父数据的副本?如果是这样,是否意味着每个孩子都有所有模块的副本? (有数十个......)
- 释放内存/管理这些进程的最佳方法是什么?
I'm working on a pretty big enterprise application using Perl, has tens of modules, etc, which mainly used to crawl some stuff over the web.
One of the subroutines I wrote, is doing an image retrieval & analysis. Usually it takes couple of seconds to accomplish, for each parameter I sent to it. So I'm sending it to a different process (forking...). The issue is, after some time the system becomes very unstable, memory filled up.
Questions:
- Is it because each process created, creates a copy of the parent data in a separate memory location? if so, does it mean each child has a copy of ALL the modules? (and there are tens...)
- What is the best approach to free this memory / manage these processes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
分叉使用写时复制,因此分叉进程不应占用太多内存,除非它们特别重要长寿。
听起来您的系统中存在内存泄漏。您是否有任何相互递归依赖关系或循环数据结构?如果是这样,您可能需要考虑使用 Scalar::Util::weaken 来调整数据的引用计数结构。
Forking uses copy-on-write, so forked processes shouldn't grab too much memory unless they are especially long-lived.
It sounds like you've got a memory leak in your system. Do you have any mutually-recursive dependencies or circular data structures? If so, you may want to look into using Scalar::Util::weaken to tweak reference-counts on your data structures.