简体   繁体   English

Perl脚本奇怪的行为/回收内存

[英]Perl script strange behavior / Reclaim memory

My script does the following 我的脚本执行以下操作

  1. Reads a huge text file and creates a hash from it.(About 24million simple key value-pairs.Takes about 5 minutes and consumes 92% of the 4Gb computer memory) 读取一个巨大的文本文件并从中创建一个哈希值。(大约2400万个简单的键值对。大约需要5分钟,占用4Gb计算机内存的92%)
  2. Runs a simulation using information from hash.(Takes about 30minutes) 使用哈希信息运行模拟。(大约需要30分钟)
  3. Prints the results at the end of the simulation(to a file and stdout) 在模拟结束时打印结果(到文件和标准输出)

Then it waits for 10+ minutes after the last print statement and exits. 然后它在最后一个打印语句后等待10分钟以上并退出。 The wait at the end doesn't happen every time. 最后的等待不会每次都发生。 During the wait top command shows the same 92% memory usage but no cpu usage. 在wait top命令期间显示相同的92%内存使用量但没有cpu使用率。 Why does it wait sometimes after it is done ? 为什么它有时会在完成后等待? If I hit Ctrl C , it exits immediately without any change in outcome(results). 如果我按下Ctrl C ,它会立即退出而不会改变结果(结果)。 How do I debug this or is it expected behavior as the hash is huge ? 我如何调试这个或者它是预期的行为,因为哈希是巨大的?

EDIT 编辑

Is it possible to reclaim some memory on the fly by deleting unwanted key - value pairs from the hash ? 通过从哈希中删除不需要的键值对,可以动态回收一些内存吗?

I assume you know 'delete' function (so removed reference to perldoc -f delete :) 我假设你知道'删除'功能(所以删除了对perldoc -f delete的引用:)

For the memory debugging you could use valgrind Also this hint can be helpful: Does Perl v5.10.1 have memory leaks or how to interpret valgrind It suggests using: 对于内存调试,您可以使用valgrind此提示也很有帮助: Perl v5.10.1是否有内存泄漏或如何解释valgrind它建议使用:

use Perl::Destruct::Level level => 1; 使用Perl :: Destruct :: Level level => 1;

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

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