开发者

Node.js high virtual memory usage

We are trying to setup Node.js + Socket.io. Our last concern is memory usage. We are starting our simple server (code below) and virtual memory usage of this process is ~600 mb.

1000      6463  0.0  0.4 635816 19260 pts/1    Sl+  12:51   0:00 node /home/data/server.js

server.js:

var express = require('express');
var app = express.createServer(), io = require('socket.io').listen(app);

app.listen(8000);

io.set('flash policy port', 8001);
io.enable('browser client minification');  // send minified client
io.enable('browser client etag');          // apply etag caching logic based on version number
io.set('log level', 1);
io.set('transports', [
    'websocket'
  , 'flashsocket'
  , 'htmlfile'
  , 'xhr-polling'
  , 'jsonp-polling'
  ]);

io.sockets.on('connection', function (socket) {
  socket.on('distribute', function (data) {
        if(typeof data.key == 'undefined' || (typeof data.key != 'undefined' && data.key != 'randomstringforsecurityreason')){
                return false;
        }
        delete data.key;
        socket.broadcast.to(data.channel).emit('eat', data);
  });

  socket.on('pukpuk', function(data) {
        if(typeof data == "string"){
                socket.join(data);
        } else {
                for(var i in data)
                {
                    socket.join(data[i]);
                }
        }
  });
});

It is normal? So big virtual memory usage?

Edit:

开发者_开发技巧

Ok, I found that it's pretty normal. http://comments.gmane.org/gmane.comp.lang.javascript.nodejs/17482


Yes, it is very normal. Node does not often free it's buffers well. IIRC: They have to be freed from v8, then from node's heap, then finally back to the OS, something here is very slow.

Try downloading a module which allows you to call the garbage collector explicitly. I suspect node isn't reporting the size of buffers to v8, and v8 is assuming they are tiny and not freeing them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜