简体   繁体   English

Perl脚本的运行时内存

[英]Run time memory of perl script

I am having a perl script which is killed by a automated job whenever a high priority process comes as my script is running ~ 300 parallel jobs for downloading data and is consuming lot of memory. 我有一个Perl脚本,每当有高优先级的进程来运行时,该脚本就会被自动化作业杀死,因为我的脚本正在运行〜300个并行作业,用于下载数据并占用大量内存。 I want to figure out how much is the memory it takes during run time so that I can ask for more memory before scheduling the script or if I get to know using some tool the portion in my code which takes up more memory, I can optimize the code for it. 我想弄清楚运行期间需要多少内存,以便可以在计划脚本之前请求更多内存,或者是否可以使用某种工具来了解代码中占用更多内存的部分,我可以对其进行优化它的代码。

Regarding OP's comment on the question, if you want to minimize memory use, definitely collect and append the data one row/line at a time. 关于OP对这个问题的评论,如果要最大程度地减少内存使用,请务必一次收集并追加一行或一行数据。 If you collect all of it into a variable at once, that means you need to have all of it in memory at once. 如果您一次将所有内容收集到一个变量中,则意味着您需要一次将所有内容存储在内存中。

Regarding the question itself, you may want to look into whether it's possible to have the Perl code just run once (rather than running 300 separate instances) and then fork to create your individual worker processes. 关于问题本身,您可能想研究一下是否有可能让Perl代码只运行一次(而不是运行300个单独的实例),然后fork来创建您的单个工作进程。 When you fork , the child processes will share memory with the parent much more efficiently than is possible for unrelated processes, so you will, eg, only need to have one copy of the Perl binary in memory rather than 300 copies. 当您进行fork ,子进程将与父进程共享内存的效率要比不相关的进程更高,因此,例如,您只需要在内存中拥有一个Perl二进制副本,而不是300个副本。

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

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