0
我在使用异步循环的Node中编写程序。我们的目标是让这个程序在Heroku上运行很长一段时间。如预期的那样,它在记忆中增长。但是一旦内存使用量达到57MiB,它就会回落到22MiB(它开始的地方)。是什么原因导致内存使用情况从此消失?节点异步循环 - 为什么内存会突然增大并突然下降?
这是我的代码,如果它有帮助的话。 database.read
只是http.request
的简化。
var http = require("http");
var util = require('util');
var fnstraj = require("./predictors/fnstraj.js");
var database = require("./library/database.js");
var COUNT = 0;
////////////////
// Queue Loop //
////////////////
var worker = function() {
setTimeout(function() {
COUNT++;
console.log("Worker Clock: " + COUNT + ".");
console.log(util.inspect(process.memoryUsage()));
database.read('/queue/', function(results, error) {
if (typeof error !== "undefined" && error) {
process.nextTick(worker);
} else {
var queue = results;
database.read('/flights/', function (results, error) {
if (typeof error !== "undefined" && error) {
process.nextTick(worker);
} else {
var flights = results;
if (!flights.error && typeof queue.rows[0] !== "undefined") {
for (flight in flights.rows) {
if (flights.rows[flight].doc._id === queue.rows[0].doc._id) {
var thisFlight = flights.rows[flight].doc;
console.log("Flight " + thisFlight._id + " started");
thisFlight.duration = fnstraj.vertPred(thisFlight.launch.altitude, thisFlight.balloon.burst, thisFlight.balloon.radius, thisFlight.balloon.lift);
fnstraj.predict(thisFlight, function() {
database.remove('/queue/' + thisFlight._id);
console.log("Flight " + thisFlight._id + " completed");
process.nextTick(worker);
});
var found = true;
}
}
if (!found) {
process.nextTick(worker);
}
}
}
});
}
});
}, 25);
};
V8垃圾回收? – 2012-07-13 14:26:09
也许 - 任何方式来从节点内控制一切? – 2012-07-13 14:29:22