{"action":"created","issue":{"url":"https://api.github.com/repos/websockets/ws/issues/667","repository_url":"https://api.github.com/repos/websockets/ws","labels_url":"https://api.github.com/repos/websockets/ws/issues/667/labels{/name}","comments_url":"https://api.github.com/repos/websockets/ws/issues/667/comments","events_url":"https://api.github.com/repos/websockets/ws/issues/667/events","html_url":"https://github.com/websockets/ws/issues/667","id":126872985,"number":667,"title":"Node seems slow to reclaim RSS (sometimes partially or never) on slow clients","user":{"login":"zz85","id":314997,"avatar_url":"https://avatars.githubusercontent.com/u/314997?v=3","gravatar_id":"","url":"https://api.github.com/users/zz85","html_url":"https://github.com/zz85","followers_url":"https://api.github.com/users/zz85/followers","following_url":"https://api.github.com/users/zz85/following{/other_user}","gists_url":"https://api.github.com/users/zz85/gists{/gist_id}","starred_url":"https://api.github.com/users/zz85/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zz85/subscriptions","organizations_url":"https://api.github.com/users/zz85/orgs","repos_url":"https://api.github.com/users/zz85/repos","events_url":"https://api.github.com/users/zz85/events{/privacy}","received_events_url":"https://api.github.com/users/zz85/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-01-15T13:30:24Z","updated_at":"2016-11-09T23:54:59Z","closed_at":"2016-11-09T23:54:59Z","body":"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.\n\nThe 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.\n\nMy 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.\n\nbefore killing clients.\n![image](https://cloud.githubusercontent.com/assets/314997/12353695/02a51920-bbcc-11e5-8a9d-daefa5da038f.png)\n\nafter killing clients at 30s (200MB of RSS not cleanup here).\n![image](https://cloud.githubusercontent.com/assets/314997/12353706/15d5ac3a-bbcc-11e5-911d-4cdc7bc38e21.png)\n\nI'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.\n\nOne 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.\n\nI'll try to put up my code in a repo for testing this if anyone's interested to investigate this.\n"},"comment":{"url":"https://api.github.com/repos/websockets/ws/issues/comments/259561405","html_url":"https://github.com/websockets/ws/issues/667#issuecomment-259561405","issue_url":"https://api.github.com/repos/websockets/ws/issues/667","id":259561405,"user":{"login":"zz85","id":314997,"avatar_url":"https://avatars.githubusercontent.com/u/314997?v=3","gravatar_id":"","url":"https://api.github.com/users/zz85","html_url":"https://github.com/zz85","followers_url":"https://api.github.com/users/zz85/followers","following_url":"https://api.github.com/users/zz85/following{/other_user}","gists_url":"https://api.github.com/users/zz85/gists{/gist_id}","starred_url":"https://api.github.com/users/zz85/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zz85/subscriptions","organizations_url":"https://api.github.com/users/zz85/orgs","repos_url":"https://api.github.com/users/zz85/repos","events_url":"https://api.github.com/users/zz85/events{/privacy}","received_events_url":"https://api.github.com/users/zz85/received_events","type":"User","site_admin":false},"created_at":"2016-11-09T23:54:59Z","updated_at":"2016-11-09T23:54:59Z","body":"Yes, this issue was discovered many node versions ago, so I think this can be closed. "}}
{"actor":{"display_login":"zz85"}}