-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
I've been looking for an explanation to why node's RSS seems slow or never to reclaim itself when after slow clients connected to the ws server gets disconnected.
The observation is that RSS builds up when the server attempts to send data faster than clients can consume. This seems logically, however when clients disconnect, the RSS stays around for a longer period. Sometimes, the memory compacts, but sometimes it doesn't free up every after a long while. v8's heap memory do not seem to be a problem.
My steps to reproduce is this. Run a ws server on a remote server. Connect 200 clients to it locally (to simulate some latency and causing buffering on the server). The server sends 512K of data every 2 seconds. v8 Heap's will remain constant but RSS will grow. Run for 30 seconds and kill clients. I'm testing this with node v4.2.1 and ws 1.0.1.
after killing clients at 30s (200MB of RSS not cleanup here).

I'm not sure if this is a behaviour coming from ws implementation, nodejs itself or a combination or both. I tested this with pure tcp sockets but the node process cleanup its RSS really quickly when I kill my clients almost immediately, while the behaviour ws doesn't clean up as fast. I can somewhat replicate that with TCP sockets, if I disconnect a portion of the total clients connecting to the server.
One hypothesis is that portion of memory buffers still active is causing chunks of buffers within nodejs not to be freed. If that is true, it seems that this memory fragmentation may cause memory issues on a long lived node process.
I'll try to put up my code in a repo for testing this if anyone's interested to investigate this.
