我正在使用 node.js (v0.10.22) 和 express 模块并向用户提供下载文件功能。每个请求我们平均下载 50 个文件,平均大小约为 700 MB。我们有自己的 C 程序,它在运行时写入这些文件,而子进程将这些文件同步发送给用户。
我们使用 FFI 模块来调用 C 函数。我面临的问题是 node.js 增加了虚拟内存,它也不会释放大量使用的内存,并且在一些下载ENOMEM
出错和崩溃之后。我的 PC H/W 配置是 1 GHZ 单核 proc 和 512 MB RAM。这里的问题是为什么 V8 在每次请求后不释放内存,或者 node / V8 是否需要任何特殊类型的编译。我们已经用 Valgrind 测试了我们的 c 程序,它没有显示任何内存泄漏。
async.series([
function DecryptFile(cb) {
logger.debug("call decrypting Function for========="+param);
var childProc = cp.fork(__dirname + '/child.js');
childProc.on('message', function(m) {
logger.debug('PARENT got message:', m.timestamp);
decFile=m.timestamp;
if(decFile){
if(bluetoothReq){
res.send(conf.get('contentTempFile')+decFile+"/"+ fName);
return;
}else{
logger.debug("downloading for device : "+param);
var folderPath=conf.get('contentTempFile')+decFile;
var downloadPath = path.join(folderPath, fName);
stats = fs.lstatSync(downloadPath);
if(stats.isFile()) {
res.download(downloadPath,fName, function(err){
if (err) {
// handle error, keep in mind the response may be partially-sent
// so check res.headerSent
logger.debug("res Error :");
console.log("res Error :");
} else {
// decrement a download credit etc
logger.debug("res Successfull :");
console.log("res Successfull :");
}
logger.debug("res on End :");
rmdir(folderPath, function(error){
logger.debug("content download Succefully :"+downloadPath);
console.log("delete Folder Successfull :"+downloadPath);
if(error){
logger.debug('rm -rf '+folderPath);
exec('rm -rf '+folderPath);
}
});
});
}
}
}else{
statsLogger.addStats(req,statsCode.TYPE_ERROR_DOWNLOAD,contentId,content.title+"-"+fileName);
res.send("1,Problem while Downloading ");
}
childProc.kill();
});
childProc.send({ filePath : folderName+ fileName,
temp : conf.get('contentTempFile'),
timestamp : timestamp,
fName : fName });