Tag: 确定

Node.js – 大量的发送请求到另一台服务器导致内存泄漏

我有一个节点的应用程序,使用restify大量的请求到另一台服务器。 随着请求数量的增加,内存不断增长,最终导致应用程序崩溃。 以下是我的代码的片段。 var restify = require('restify'); var client = restify.createStringClient({ url: "https://api-3t.sandbox.paypal.com/nvp" }); function makeRequest(cb) { counter++; client.post({ headers: null }, null, function(err, req, res, data) { if(err) { cb(err, req, res, data); } else { cb(null, req, res, data); } }); } function makeRequestCb(error,request,response,data){ counter++; console.log("result",counter); } setInterval(function(){ makeRequest(makeRequestCb) }, 1000); 在chrome中检查堆快照时,我发现“缓冲区”占用了大部分空间。 我也尝试使用'请求'模块而不是'restify'我在这里做错了什么。 […]