最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

为什么我的节点OracleDB的稳步执行承诺中的它需要解决的时间量增加?

运维笔记admin9浏览0评论

为什么我的节点OracleDB的稳步执行承诺中的它需要解决的时间量增加?

为什么我的节点OracleDB的稳步执行承诺中的它需要解决的时间量增加?

我正在写一个ETL工具,它使用的也使用Oracle node-oracledb1.10处理所有的各种异步数据的RxJS数据库交互流说我折腾周围。我运行到那里的不再是我的应用程序运行的时间越长,以node-oracledb.execute()通话需要的问题,似乎在运行时间线性增加。希望你能发现在下面的代码错误并纠正它。

首先让我告诉我如何运行Oracle查询。我创建了作为围绕.execute()node-oracledb的包装我自己.execute()功能。

import oracledb from 'oracledb';
var oraConnPool;

export function execute(sql, bind, opts) {
  if (!oraConnPool) {
    createOraPool();
  }
  return oraConnPool
    .then(pool => pool.getConnection())
    .then(conn => conn.execute(sql, bind, opts));
}

function createOraPool() {
  let oraPool = oracledb.createPool(config.database.oracle);
  oraConnPool = oraPool;
  return oraPool;
}

而我config.database.oracle(无凭据):

{
  "poolTimeout": 60,
  "poolMin": 10,
  "poolMax": 25,
  "queueRequests": true,
  "queueTimeout": 600000,
  "_enableStats": true
}

下面是我的调用我.execute()函数的一个例子。正如你所看到的,有很多在这里发生的事情,所以让我尝试注释该位为清晰。 rnd被用于创建console.time()一个唯一的ID,这样我就可以跟踪它花费的.execute() Promise解决的时间。让我知道如果有一个在这个时候一个缺陷测量技术。传递给SELECT声明绑定输入变量是SSID标识符的CSV字符串,将返回匹配的列表。这使我能够批量处理的记录,而不是为每个单排创建一个查询,希望节省一些执行时间。第一.then()使得所得小写对象的阵列中的每个键。第二.then(),很明显,结束console.time()跟踪。

const rnd = Math.random() * 100;
console.time(rnd);
return execute(`
  SELECT
    ssid_input.ssid AS ssid,
    students.id AS student_id,
    students.student_number AS student_number
  FROM (
         SELECT REGEXP_SUBSTR(
                    :ssids,
                    '[^,]+', 1, level) AS ssid
         FROM dual
         CONNECT BY REGEXP_SUBSTR(
                        :ssids,
                        '[^,]+', 1, level) IS NOT NULL
  ) ssid_input
  LEFT JOIN students ON students.state_studentnumber = ssid_input.ssid`, {
    ssids: {
      val: ssids.join(','),
      dir: orawrap.BIND_IN,
      type: orawrap.STRING
    }
  }, {
    outFormat: orawrap.OBJECT,
    maxRows: ssids.length
  })
  .then(results => {
    return results.rows.map(result => {
      let newObj = {};
      Object.keys(result).forEach(key => {
        newObj[key.toLowerCase()] = result[key];
      });
      return newObj;
    });
  })
  .then(result => {
    console.timeEnd(rnd);
    return result;
  });

下面是console.time()输出,这增加了稳步,直至碰到60000毫秒queueTimeout限制。

97.24179652744425: 12226.930ms
38.14057213652584: 14583.518ms
46.19793585774834: 16024.785ms
16.12600313565251: 17820.694ms
87.73720584788988: 20809.461ms
54.711100085462604: 22652.638ms
42.474404414891744: 24037.868ms
49.09845121453702: 26521.596ms
87.70258724764568: 29461.480ms
1.0731996619882223: 31210.875ms
90.33430329792829: 32259.944ms
37.4829457960367: 34076.824ms
9.731832830291932: 35292.281ms
/home/nathanjones/Projects/test-forge/node_modules/@reactivex/rxjs/dist/cjs/util/subscribeToResult.js:41
            root_1.root.setTimeout(function () { throw err; });
                                                 ^

Error: NJS-040: connection request timeout

我一直在努力,包括大部分的相关代码,请让我知道如果你需要更多的上下文。

编辑:

我加了console.log(pool._logStats())声明每次.execute()函数被调用时。我已经包括了它的NJS-040错误之前打印的最后一次输出:

Pool statistics:
...total up time (milliseconds): 62823
...total connection requests: 1794
...total requests enqueued: 1769
...total requests dequeued: 0
...total requests failed: 0
...total request timeouts: 0
...max queue length: 1769
...sum of time in queue (milliseconds): 0
...min time in queue (milliseconds): 0
...max time in queue (milliseconds): 0
...avg time in queue (milliseconds): 0
...pool connections in use: 25
...pool connections open: 25
Related pool attributes:
...queueRequests: true
...queueTimeout (milliseconds): 60000
...poolMin: 10
...poolMax: 25
...poolIncrement: 1
...poolTimeout (seconds): 60
...stmtCacheSize: 30
Related environment variables:
...process.env.UV_THREADPOOL_SIZE: undefined
undefined
回答如下:

(这是node-oracledb Issue 474的副本)。

你需要确保你有密切联系。

你可能需要增加UV_THREADPOOL_SIZE,看到Connections and Number of Threads的节点OracleDB的文档。

发布评论

评论列表(0)

  1. 暂无评论