Node.js产生EMFILE
我试图在我的节点作业中使用ChildProcess.exec在async.forEach循环内运行命令。 这里是代码
async.forEach( docPaths, function(docPath, callback) { var run = []; // some command using docPath variable here.. run.push(command); debugger; exec(run.join(' '), function(error, stdout, stderr){ callback(); }); }, callback);
这是错误
"stack":"Error: spawn EMFILE\ at errnoException (child_process.js:478:11)\ at ChildProcess.spawn (child_process.js:445:11)\ at child_process.js:343:9\ at Object.execFile (child_process.js:253:15)\ at child_process.js:220:18\
快速谷歌显示我需要设置ulimit值来增加文件描述符的数量可以打开。 有些东西像“ulimit -n 10000”(从下面的链接)
https://groups.google.com/forum/#!topic/nodejs/jeec5pAqhps
我在哪里可以增加这个..? 还是有其他解决scheme来规避这个问题?
感谢您的帮助..非常感谢!
首先它是不可取的,因为它可能有系统的影响。
相反,因为您已经在使用asynchronous,所以您可以使用限制参数来限制并行执行的次数。
async.eachLimit( docPaths, 100, function(docPath, callback) { var run = []; // some command using docPath variable here.. run.push(command); debugger; exec(run.join(' '), function(error, stdout, stderr){ callback(); }); }, callback);
请进行反复试验,并用合适的值replace100。