您可能遇到的唯一现实世界限制是节点可用的内存量。使用以下代码进行测试。我使用 oneMillion 和 int32Max 成功运行了下面的示例。使用 int64Max 时,我从 node.js 收到以下错误。我正在使用具有 4GB RAM 的 64 位 Windows。
FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory
要测试的节点代码:
var util = require('util');
var int64Max = 9007199254740992;
var int32Max = 2147483647;
var oneMillion = 1000000;
var tenThousand = 10000;
var counter = 0;
//Exchange the limiter with one of the above vars to test.
for (var i = 0; i < oneMillion; i++){
setTimeout(log, 1);
//Required as the timeout/callback method will not be called until the loop ends due
//to node/js being single threaded.
util.log('loop:' + i);
}
function log(){
util.log('callback: ' + counter++);
}