Hello.
Currently, I am building a server for real-time communication using Node.js×socket.io.
Node.js and socket.io are both beginners.
We use pm2 for Node.js process management.
Node.js v0.12.2
socket.io v0.9.17
pm2 v0.14.2
The other day, we conducted a load test on the completed server.
During the load, the memory usage continued to rise, and even though the load was finished, the memory usage did not change.
When I looked it up, I found that I could run GC from the source code, so I tried it.
global.gc();
I was able to confirm that the above code was executed properly, but the memory usage did not change.
About 40MB boot time
After the load test, about 80MB
About 75MB after GC runs
Actually, I wish I could show you the source code, but I can't because of the circumstances.
Is this a bad source code (some are not recovered by GC) or something like this?
I don't have much information, but I would appreciate it if you could let me know.
Thank you for your cooperation.
The most likely cause is that there are variables that keep being referenced when registering an event handler in the closure.
If it continues to be referenced, it will not be GCed, so memory usage will not decrease.
If the warning below appears, it is highly likely.
warning: Possible EventEmitter memory leak detected.11 listeners added.Useemitter.setMaxListeners() to increase limit.
The above should be noted when coding JavaScript, which can occur not only on node.js but also on the front side.
© 2024 OneMinuteCode. All rights reserved.