pm2
pm2 copied to clipboard
Set cluster scheduling policy on Windows
What's going wrong?
On Windows, cluster scheduling is disabled and only one worker gets the entire load of requests. This can be fixed by setting cluster.schedulingPolicy = cluster.SCHED_RR;
or the environment variable NODE_CLUSTER_SCHED_POLICY=rr
. I tried the environment variable as a system global variable but it didn't work.
How could we reproduce this issue?
Run clustering on Windows and monitor the workers log.
Supporting information
--- PM2 report ----------------------------------------------------------------
Date : Fri Jan 14 2022 01:52:29 GMT+0000 (Coordinated Universal Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 5.1.2
node version : 16.13.1
node path : not found
argv : C:\Program Files\nodejs\node.exe,C:\ProgramData\pm2\service\index.js
argv0 : C:\Program Files\nodejs\node.exe
user : undefined
uid : N/A
gid : N/A
uptime : 1827min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 5.1.2
node version : 16.13.1
node path : not found
argv : C:\Program Files\nodejs\node.exe,C:\ProgramData\npm\npm\node_modules\pm2\bin\pm2,report
argv0 : node
user : Administrator
===============================================================================
--- System info --------------------------------------------
arch : x64
platform : win32
type : Windows_NT
cpus : AMD EPYC 7571
cpus nb : 8
freemem : 28164399104
totalmem : 34074025984
home : C:\Users\Administrator
===============================================================================
Hi,
Same issue experienced. I realized, the process id will be distributed if concurrent request been made for e.g.
loadtest -n 4 -c 4 --rps 4 http://localhost:3000
if I created node with clustering then cluster.schedulingPolicy = cluster.SCHED_RR;
works nice for windows. So PM2 with execution mode as clustering with environment variable as NODE_CLUSTER_SCHED_POLICY=rr
should also work!
- Thanks, Somnath