What is the best way to avoid "out of memory" in node.js?

I am working on a project that should handle many tens of thousands of active parallel socket connections. Now, looking at memory usage and the V8 engine, I use Node.js v0.10.19 (stable)

I can not afford to use the "system from memory . " Thus, it is currently working on launching up to 15 instances of node, each of which is limited to 1 GB of RAM on a single server with a large amount of RAM to work with it and with quad-core xeon processors and a load balancer to organize loading for all instances.

So, is there a way to save socket connections outside the heap of the V8 heap, like in buffers or some other way to reduce the memory usage of Node.js?

+4
source share
1 answer

Naturally, since you keep many thousands or tens of thousands of connections open, you will bear the cost of memory by doing this.

Here is what I would like to ask:

Are you adding things to an array or object that is populating?

Do you create powerful modules for every open connection?

Can you run the profiler to find out what it does? (People rave about this DTrace.)

Is it possible to conduct a survey at intervals for what you want, and not open web sockets?

Something else that you can try, if you cannot start the profiler, it registers the status of the application during its launch so that you can analyze the problem. This is an oldschool method, but you can register every time the function ends and see what the current memory usage is. It can also chew on memory, but if you find the problem this way, great.

The memory usage is checked through the Process module:

http://nodejs.org/api/process.html#process_process_memoryusage

Good luck and please let me know what you find out. I am curious to see how you solve this very difficult problem.

+1
source

All Articles