Recently, I am starting to build a chat room for the company. First, I would like to talk about the current structure.
Nginx is allocated to different node ports via ip_hash
Two servers start 8080-80034 Port monitor with pm2 in cluster mode, with a total of 8 node instances running.
Node is completed with express framework and socket.io
When testing the actual production environment, it was found that because the ip_hash using nginx is actually distributed unevenly to each node instance, there are only about 2w socket.io connections. (Please add why the ip_hash using nginx is because the socket of socket.io must maintain a continuous connection with a process.)
Looking at the pressure of each node through pm2-web, the Central Processor pressure of 6 of the 8 processes is 10% plus, but some 1-2 processes will be 100% full. Then the memory of each node process will automatically restart when it rises to about 1G plus.
I just got in touch with node and don’t know much about the optimization plan. I hope the great gods will support me. Thank you
There is probably a solution.
Nginx cannot use ip_hash. You need to manually compile nginx sticky module and then add pm2 multi-process management. Now the testing machine uses two 3-node processes to test how many people it can support.