gpt4 book ai didi

javascript - 当内存可用时,NodeJS exec 抛出 ENOMEM

转载 作者:行者123 更新时间:2023-12-03 00:25:19 28 4
gpt4 key购买 nike

我正在运行 pdfinfo 命令来获取有关大小为 100KB 的 pdf 的信息。相关代码为

    const pdfInfo = execute(`pdfinfo '${input}' | grep Pages`)
.then(stdout => {
var pdfLength = 0;
pdfLength = stdout.match(/Pages:\s+(\d+)/)[1];
return pdfLength;
})
function execute(command) {
return new Promise(function (res, rej) {
exec(command, function (error, stdout, stderr) {
if (error || stderr) {
rej(error || stderr);
} else {
res(stdout);
}
});
});
}

处理几个文件后,内存使用量不断增加

 PM2 details of the process
Mem: 431 MB CPU: 0 %

如果我看到服务器上的可用内存,那就是

/home/core-server # free -m
total used free shared buffers cached
Mem: 2000 1341 659 20 21 173
-/+ buffers/cache: 1145 854
Swap: 0 0 0

内存可用,但我仍然收到错误

2019-01-10T00:46:42.266Z Error: spawn ENOMEM
at ChildProcess.spawn (internal/child_process.js:358:11)
at spawn (child_process.js:533:9)
at Object.execFile (child_process.js:216:15)
at exec (child_process.js:147:18)
at /home/core-server/helper/ppt2svg.js:42:5
at new Promise (<anonymous>)
at execute (/home/core-server/helper/ppt2svg.js:41:10)
at pdf2svg (/home/core-server/helper/ppt2svg.js:53:18)
at ppt2svg (/home/core-server/helper/ppt2svg.js:93:12)
at uploadPresentation.single.err (/home/core-server/api/sessions/index.js:174:25)

有人可以向我提供任何关于为什么会发生这种情况的想法吗?

编辑:顺便说一句,服务器上的其他一切都工作正常,但 exec 方法遇到了这个问题

最佳答案

据我所知,node.js 有默认的内存限制。比如 32 位系统上为 1G,64 位系统上为 1.7G。但是,幸运的是,您可以通过问题 --max_old_space_size=<size> 来增加它Node.js 命令行中的选项。值<size>以MB为单位。

关于javascript - 当内存可用时,NodeJS exec 抛出 ENOMEM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54120599/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com