【问题标题】:In doing simple stress test Firebird on nodejs I got FATAL ERROR: Allocation failed - JavaScript heap out of memory在 nodejs 上做简单的压力测试 Firebird 我得到了 FATAL ERROR: Allocation failed - JavaScript heap out of memory
【发布时间】:2017-10-15 14:52:27
【问题描述】:

此代码正在运行。但是,如果我取消注释无限循环,则没有结果。结束内存增加 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 的节点。

【问题讨论】:

  • 我只是想实现打印结果集,一个接一个。
  • 你在循环内 DETACH - 我想知道在你从数据库中分离后你打算与谁一起工作?您也许应该关闭查询游标(结果?)并提交事务,但在您进行 LAST 查询之前,您几乎不应该脱离数据库连接

标签: node.js firebird stress-testing


【解决方案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);
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-18
    • 2018-07-31
    • 1970-01-01
    • 2022-12-12
    • 2019-01-09
    • 1970-01-01
    • 2018-08-01
    • 2019-06-18
    相关资源
    最近更新 更多