每个请求的节点/Express内存增加 [英] Node/Express memory increase on every request

查看:79
本文介绍了每个请求的节点/Express内存增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Express 3.2应用程序,发布到该应用程序时返回200.我观看了节点(v0.10.5)进程的内存RSS,每个请求将内存增加了4kb左右.

I have a simple express 3.2 app that returns a 200 when posted to. I watch the memory RSS of the node (v0.10.5) process and every request increases the memory by 4kb or so.

服务器代码非常简单:

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;

我的代码中是否有某些原因导致这种情况?这是正常现象吗(希望不是).还是我测量错误的东西?我将这个脚本的一个版本投入生产,节点进程在内存使用16mb时开始,经过一些负载测试(命中20,000次)后,它增加到了32mb.

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.

推荐答案

继续对服务器进行性能分析.您可能会发现内存使用率随着时间的流逝而下降.尝试200,000个请求,看看情况是否有所改变

Keep profiling your server. You will probably find that memory usage levels off over time. Try 200,000 requests and see if things change

此外,如果有可用的内存,操作系统将尝试使用它. 32mb的内存不足以引起人们的关注.

Also if there is memory available the operating system will try to use it. 32mb of ram is not enough to be concerned about.

这个话题值得一看.它是关于python的,但对node.js的概念是相同的

This talk is worth watching. It is about python but the concepts are the same for node.js

这篇关于每个请求的节点/Express内存增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆