【发布时间】:2014-06-16 05:06:06
【问题描述】:
我有一个 perl 例程导致我在系统中经常出现“内存不足”问题。
脚本做了三件事
1> get the output of a command to an array (@arr = `$command` --> array will hold about 13mb of data after the command)
2> Use a large regex to match the contents of individual array elements -->
The regex is something like this
if($new_element =~ m|([A-Z0-9\-\._\$]+);\d+\s+([0-9]+)-([A-Z][A-Z][A-Z])-([0-9][0-9][0-9][0-9]([0-9]+)\:([0-9]+)\:([0-9]+)|io)
<put to hash>
3> Put the array in a persistent hash map.
$hash_var{arr[0]} = "Some value"
编辑: 正则表达式处理的样本数据是
Z4:[newuser.newdir]TESTOPEN_ERROR.COM;4
8-APR-2014 11:14:12.58
Z4:[newuser.newdir]TEST_BOC.CFG;5
5-APR-2014 10:43:11.70
Z4:[newuser.newdir]TEST_BOC.COM;20
5-APR-2014 10:41:01.63
Z4:[newuser.newdir]TEST_NEWRT.COM;17
4-APR-2014 10:30:56.11
大约 10000 行这样的
我首先怀疑数组和哈希一起可能会消耗太多内存。 但是我开始认为这个正则表达式也可能与内存不足有关。
perl 正则表达式(带有 'io' 选项!)真的是导致内存不足的罪魁祸首吗?
【问题讨论】:
-
您是否尝试过使用调试器来查看在内存不足错误之前您能走多远?您能否提供示例数据以及您尝试过的方法?
-
我正在使用带有 32 位 perl 映像的 openvms 系统。我不知道除 Devel:size 之外的任何调试器。打开以获取建议。相关问题:stackoverflow.com/questions/23354220/…
-
我怀疑它是正则表达式,而不是你的 3>。 10000 个唯一行作为哈希键,加上“某些值”可能很昂贵。如果你的线条不是唯一的,你就会有重叠。不知道你真正想要什么
-
您使用该正则表达式的目的是什么?提取信息?验证输入数据?或者是其他东西?为什么你认为正则表达式是你的问题的原因?
-
我对数组和散列的大小进行了一些测试。结果数组的最大大小为 13 MB,散列小于 7 MB(即使散列的范围在函数之外)。正则表达式的目的是仅将有效信息输入到散列中。 “Some value”实际上是处理成posix格式的输入数据中的日期。哈希的输入大多是唯一的,因为键是文件名
标签: regex perl memory-management out-of-memory