Long connections with Node.js, how to reduce memory usage and prevent memory leak? Also related with V8 and webkit-devtools

前端 未结 2 1143
情话喂你
情话喂你 2021-01-29 19:08

Here is what I\'m trying to do: I\'m developing a Node.js http server, which will hold long connections for pushing purpose(collaborate with redis) from tens of thousands of mob

2条回答
  •  没有蜡笔的小新
    2021-01-29 19:43

    Just a few notes:

    Do you need to wrap res in an object {res: res} can you just assign it directly

    pendingClinets[req.clientId] = res;
    

    EDIT another ~micro optimization that might help

    server.emit('request', req, res);
    

    passes two arguments to 'request', but your request handler really only needs the response 'res'.

    res['clientId'] = 'whatever';
    server.emit('request', res);
    

    while your amount of actual data remains the same, having 1 less argument in the 'request' handlers arguments list will save you a reference pointer (a few bytes). But a few bytes when you are processing hundreds of thousands of connections can add up. You'll also save the minor cpu overhead of processing the extra argument on the emit call.

提交回复
热议问题