In doing simple stress test Firebird on nodejs I got FATAL ERROR: Allocation failed - JavaScript heap out of memory

In doing simple stress test Firebird on nodejs I got FATAL ERROR: Allocation failed - JavaScript heap out of memory

此代码有效。但是如果我取消无限循环的注释,就没有结果。结束内存增加2G,报错停止

致命错误:CALL_AND_RETRY_LAST 分配失败 - JavaScript 堆内存不足

我做错了什么?

var Firebird = require('firebirdsql'); // or require('node-firebird');

var options = {};

options.host = '127.0.0.1';
options.port = 3050;
options.database = 'D:\test\test.FDB';
// ...

Firebird.attach(options, function(err, db) {

    if (err)
        throw err;

// while (1)    { // endless loop BEGIN
    db.query('SELECT first 1000 a.* FROM EVENTS a ORDER BY a.DATETIME', function(err, result) {
        if (err) throw err;

                for(r of result) {
                    console.log(r.datetime, ""+r.event_text);
                    // console.log(r.DATETIME, ""+r.EVENT_TEXT);  // for require('node-firebird');
                };
        // IMPORTANT: close the connection 
        db.detach();
    });

// } // endless loop END

});

我认为这不是那么重要,但我在 windows 10.

上使用节点的 v6.3.1

使用函数 setInterval 而不是 while 循环,并且不要使用 throw,因为它会导致您退出程序。

Firebird.attach(options, function(err, db) {

    setInterval(
        function() {
            db.query('SELECT first 1000 a.* FROM EVENTS a ORDER BY a.DATETIME', function(err, result) {
                if (err) {
                    console.log("Error");
                }
                else {
                    for(r of result) {
                        console.log(r.datetime, ""+r.event_text);
                    };
                }
        // IMPORTANT: close the connection 
       //db.detach();
            });

        }, 1);
});