我在当前正在生产的nodeJS应用程序中有一些内存问题(S3多部分上传服务器的代理)所以我正在尝试搜索一种检测和阻止它的方法..我遇到了这个教程但是当我打开配置文件选项卡未显示的
(我正在按照本教程 https://github.com/felixge/node-memory-leak-tutorial)
如果它有帮助,这是我的代码中可能导致泄漏的一部分:
IngestionClient.prototype.multipartUpload = function(params, req, res, aReqLength) { var self = this; var client = this.client[params.profile]; var dest = params.file; logger.debug('PART ' + params.query.partNumber + '/' + params.query.totalSize +': BEGIN : '+req.headers['content-length']+' bytes : [' + params.file_id + ']'); var amazonRequest = client.request('PUT', '/' + dest + '?partNumber=' + params.query.partNumber + '&uploadId=' + params.query.uploadId, { 'Content-Length' : req.headers['content-length'] }); var partLength = 0; req.on('data', function(data) { partLength += data.length; amazonRequest.write(data, 'binary'); }); req.on('end', function() { if(partLength == req.headers['content-length']) { logger.debug('PART ' + params.query.partNumber + '/' + params.query.totalSize +': CLIENT_RECEIVED_COMPLETE : [' + params.file_id + ']'); }else { logger.error('PART ' + params.query.partNumber + '/' + params.query.totalSize +': CLIENT_RECEIVED_INCOMPLETE : Esperado '+req.headers['content-length'] +' bytes / Recebido ' + partLength + ' : [' + params.file_id + ']'); amazonRequest.abort(); self.sendError(params, res); } }); amazonRequest.on('response', function(amazonResponse) { var responseText; if (amazonResponse.statusCode == 200 && amazonResponse.headers.etag.length > 0) { self.queryDB( 'INSERT INTO SAMBAFILES_UPLOAD_CONTROL_PARTS SET FILE_ID="' + params.file_id + '", ETAG=' + amazonResponse.headers.etag + ', PART_NUMBER="' + params.query.partNumber + '"', function(err, results) { logger.debug('PART ' + params.query.partNumber + '/' + params.query.totalSize +': S3_PUT_COMPLETE : [' + params.file_id + ']'); responseText = '{"success": true}'; res.end(responseText); self.checkComplete(params, dest); }); } else { var responseBody = ""; amazonResponse.on('data', function(dataRes) { responseBody += dataRes; }); amazonResponse.on("end", function(){ if(responseBody.indexOf("<Code>RequestTimeout</Code>") > 0) { //Erro de lentidao do envio ( + de 20 segundos ). Browser fará um retry logger.error('PART ' + params.query.partNumber + '/' + params.query.totalSize +': S3_PUT_ERROR_TIMEOUT : Response Code ' + amazonResponse.statusCode + ' : [' + params.file_id + ']'); }else { logger.error('PART ' + params.query.partNumber + '/' + params.query.totalSize +': S3_PUT_ERROR : Response Code ' + amazonResponse.statusCode + ': ' + responseBody + ' : [' + params.file_id + ']'); } amazonRequest.abort(); self.sendError(params, res); }); } console.log(util.inspect(process.memoryUsage())); }).end(); };
基本上,在我从浏览器收到的每个部分中,我使用params和收到的请求向Amazon发出请求.节点版本为0.6.7
谢谢!
Mozilla团队发布了node-memwatch,一个用于跟踪内存泄漏的nodejs模块.官方mozilla帖子:https://hacks.mozilla.org/2012/11/tracking-down-memory-leaks-in-node-js-a-node-js-holiday-season/
该项目的Github:https://github.com/lloyd/node-memwatch
它看起来非常有趣,非常有前景.