0

我正在使用节点 JS 。我是初学者。我使用 OrientJS 从 Node JS 连接 orientdb。我想并行运行几个 db.query() 方法。该查询是通过使用逐行模块读取大型文本文件形成的。

例如,

var queryForGeoUpdate = 'update (' +
    '\nselect  from (' +
    "\n  select expand(outE('GeoAgentSummary')) " +
    '\n  from Agent ' +
    '\n  where name = "' + name + '" and number = \'' + number + "' and type = '" + type + "'" +
    "\n) where in.name  = '" + Geo + "'" +
    '\n)  increment _' + FiscalYear + ' = ' + TMSSalesAllocatedBookingsNet + 'f,  _' +
    FiscalPeriodID + ' = ' + TMSSalesAllocatedBookingsNet +
    'f, _' + FiscalQuarterID + ' = ' + TMSSalesAllocatedBookingsNet + 'f'

  // console.log(queryForGeoUpdate)
  db.query(queryForGeoUpdate) // query and db call for Country ends here

像 db.query(queryForGeoUpdate) 有七个查询像 db.query(queryForRegionUpdate) 等等......

如果我异步运行它“处理内存不足”。如果我同步运行它会花费太多时间。我怎样才能在很短的时间内解决它..

任何帮助表示赞赏..

4

1 回答 1

2

我不熟悉您正在使用的数据库。如果您确定数据库“正确”工作并且您所做的调用是正确的(例如,如果没有办法让您的查询更小),您可以尝试运行:

node --max_old_space_size="内存MB,试试8192这样大的东西" app.js

数据库查询会耗尽内存的想法似乎很奇怪……我一直认为查询通常会占用更多的 CPU 资源并且需要的内存相对较少。

对于这类大型查询,您还可以尝试生成单独的进程:

https://nodejs.org/api/child_process.html

于 2016-09-19T11:22:36.487 回答