简体   繁体   English

每个请求都会增加节点/快速内存

[英]Node/Express memory increase on every request

I have a simple express 3.2 app that returns a 200 when posted to. 我有一个简单的快递3.2应用程序,发布时返回200。 I watch the memory RSS of the node (v0.10.5) process and every request increases the memory by 4kb or so. 我观察节点(v0.10.5)进程的内存RSS,每个请求都将内存增加4kb左右。

The server code is quite simple: 服务器代码非常简单:

var express = require('express');

var app = module.exports = express();

app.set('port', process.env.PORT || 3000);
app.use(express.favicon());
app.use(express.bodyParser());

require('./apps/events/index')(app);

app.listen(app.get('port'), function(){
  console.log("Express server starting...");
});

and the corresponding controller code is : 相应的控制器代码是:

// ./apps/events/index.js
var events = function(app) {

  app.post('/events', function(req, res) {
    res.writeHead(200);
    res.end();
  });

}    
module.exports = events;

Is there something in my code that is causing this? 我的代码中是否有引起这种情况的内容? Is this normal (hopefully not). 这是正常的(希望不是)。 Or am I measuring the wrong thing? 还是我在测量错误的东西? I put a version of this script into production and the node process started at 16mb memory use, and after some load testing (20,000 hits) it increased to 32mb. 我将这个脚本的一个版本投入生产,节点进程在16mb内存使用时启动,经过一些负载测试(20,000次点击)后,它增加到32mb。

Keep profiling your server. 继续分析您的服务器。 You will probably find that memory usage levels off over time. 您可能会发现内存使用率随着时间的推移而下降。 Try 200,000 requests and see if things change 尝试200,000个请求,看看是否有变化

Also if there is memory available the operating system will try to use it. 此外,如果有可用内存,操作系统将尝试使用它。 32mb of ram is not enough to be concerned about. 32mb的ram还不足以引起关注。

This talk is worth watching. 这个讲话值得一看。 It is about python but the concepts are the same for node.js 它是关于python但是node.js的概念是相同的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM