Node.js + Socket.io + Redis app via PM2 with large memory footprint

你。 提交于 2019-12-01 09:39:24

I have a similar setup although it is not released and have done no stress testing yet... but here is an idea for you:

Use the redis module for socketio (whether it is any better then the redisClient would be interesting to know). It uses a different client for pub'ing and sub'ing. The subClient uses detect_buffers.

var redisModule = require('socket.io-redis');
var redisAdapter= redisModule({
      host: redisClient.options.host
    , port: redisClient.options.port
    , pubClient: redisClient
    //, subClient: ... separate client that uses detect_buffers
});
io.adapter(redisAdapter);

then subscribe/disconnect looks like this:

socket.on('subscribe', function(room) {
    socket.join(room);
});
socket.on('disconnect', function() {
    console.log('user disconnected');
});

I've also read multiple times that at one point socketio was not the best and to instead use sockjs. No idea if that is still the case.

And... since I just realized it's been more than 2 months. Did you find anything to reduce your memory footprint?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!