【发布时间】:2019-03-18 21:41:05
【问题描述】:
我的代码可以从数据库中检索数百万行,并通过 api 检索数百万行。
let closedOrdersStartDate;
preparedOrdersPromise = tickApiConnector.obtainToken().then(function () {
return ordersController.getAllTrades(0, [], 0, accountIdsToRun);
}).then(function (trades) {
closedOrdersStartDate = new Date();
return Promise.all([trades, fthsApiConnector.getData('closed_orders', '&sort=id', 10000, 0)]);
}).then(function (tradesAndClosedOrderIds) {
//stuck before getting there
console.log('now processing orders time spent from starting getting closed_orders till now is: ' +
((new Date().getTime() - closedOrdersStartDate.getTime())/ 1000) + ' seconds');
return ordersController.processOrders(tradesAndClosedOrderIds[0], tradesAndClosedOrderIds[1]);
});
应用在调用 getData() 函数后卡住了。
getData: async function (entityName, getParams = '', perRequest = 10000, skip = 0) {
if(getParams.indexOf('&take=') !== -1) {
return fthsApiRequest(entityName, getParams);
}
const totalCount = await fthsApiRequest(entityName, getParams + '&getCount');
let result = [];
let count = 0;
while(count < totalCount) {
result = result.concat(await fthsApiRequest(entityName, getParams + '&take=' + perRequest + '&skip=' + count));
count += perRequest;
}
return result;
}
该函数一直执行到最后一个请求(我在日志中看到它),然后脚本变得不负责任。我认为这可能是内存泄漏,我已经以不同的方式重写了 getData() 函数,但服务器上仍然有足够的内存,脚本甚至不会消耗一点内存.在 getData() 的最后一次迭代被咆哮之后,我仍然会在一段时间内获得 100% 的 CPU 负载。之后,应用程序就永远卡住了。
我已尝试对其进行分析。并且有数千个未知代码的代码移动事件:0x2a5c24bfb4c0,我不确定这意味着什么,但可能有线索。这是V8.log
【问题讨论】:
标签: javascript node.js memory-leaks profiling cpu