Answer the question
In order to leave comments, you need to log in
Why is there no performance difference between fork mode and cluster mode in PM2?
Hello!
There is a dual-core server with 2GB of RAM. It runs a NodeJS application in conjunction with PM2 in fork mode, i.e. uses one thread. Decided to check the performance through JMeter:
- Number of user - 100
- Power up period - 5 seconds
- Cycle - 10
The application consumes 80-100MB of memory.
Single-threaded mode, issued:
- no load 50-70ms
- at peak load (100 requests per second) gives Latency 650-750ms.
Now I switch to cluster mode. In pm2, two instances respectively work. I run the same test:
- no load 50-70ms
- peak 550-650ms.
Tell me please, shouldn't the second core almost double the performance or am I doing something wrong?
Answer the question
In order to leave comments, you need to log in
Firstly, the cluster mod differs from fork only in that it can fumble listening tcp ports between processes. And there and there there will be exactly as many processes as you configure, and the default value is the number of physical threads (logical cores) of the system.
Secondly, a "dual-core server with 2GB of RAM" looks like a virtual machine on a large server, where you have been allocated some resources. And your 2 cores may well be logical, but physically - 1 core or even half of it (if 4 threads per core), due to hyperthreading. That's just hyperthreading, a thing aimed at better utilization of processor resources during downtime, but under heavy load it can quite slow down the system, especially based on cooperative multitasking (asynchronous execution) like in a node.
As far as I understand, fork also uses all the CPU. You can check by looking at the load on the CPU - top, etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question