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
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.