E
E
Evgeny Petrov2021-03-20 19:52:38
JavaScript
Evgeny Petrov, 2021-03-20 19:52:38

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

2 answer(s)
D
Dmitry Belyaev, 2021-03-21
@bingo347

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.

V
Vitaly Karasik, 2021-03-20
@vitaly_il1

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 question

Ask a Question

731 491 924 answers to any question