pm2 slow
What's going wrong?
Sometimes pm2 is really slow. It takes, for example, 26 seconds to do pm2 status. Other operations are like list, logs, etc are also very slow. I've installed and uninstalled pm2 several times on my development computer.
How could we reproduce this issue?
I'm not able to reproduce this issue in a fresh installation (on a new virtual machine). But on my development computer, I get this often.
$ time pm2 status
┌─────┬──────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼──────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 1 │ idea │ default │ 3.0.0 │ fork │ 555371 │ 97s │ 0 │ online │ 0.1% │ 79.7mb │ jgr │ enabled │
│ 0 │ proxy │ default │ 1.0.0 │ fork │ 555364 │ 97s │ 0 │ online │ 0.1% │ 58.5mb │ jgr │ enabled │
└─────┴──────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
real 0m26,291s
user 0m0,256s
sys 0m0,035s
I would like to know what can I do on my side to know where the delay is. Is it network related? File system related? Am I able to enable more verbose output from pm2?
Both application used in this example starts immediately without pm2.
Supporting information
--- PM2 report ----------------------------------------------------------------
Date : Tue May 31 2022 11:24:43 GMT+0100 (Western European Summer Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 5.2.0
node version : 12.13.1
node path : not found
argv : /home/jgr/.nvm/versions/node/v12.13.1/bin/node,/home/jgr/.nvm/versions/node/v12.13.1/lib/node_modules/pm2/lib/Daemon.js
argv0 : node
user : jgr
uid : 1000
gid : 1000
uptime : 0min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 5.2.0
node version : 12.13.1
node path : /home/jgr/.nvm/versions/node/v12.13.1/bin/pm2
argv : /home/jgr/.nvm/versions/node/v12.13.1/bin/node,/home/jgr/.nvm/versions/node/v12.13.1/bin/pm2,report
argv0 : node
user : jgr
uid : 1000
gid : 1000
===============================================================================
--- System info --------------------------------------------
arch : x64
platform : linux
type : Linux
cpus : Intel(R) Core(TM) i7-10870H CPU @ 2.20GHz
cpus nb : 16
freemem : 1213796352
totalmem : 33472036864
home : /home/jgr
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬──────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼──────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 1 │ idea │ default │ 3.0.0 │ fork │ 557157 │ 60s │ 0 │ online │ 0.1% │ 82.0mb │ jgr │ enabled │
│ 0 │ proxy │ default │ 1.0.0 │ fork │ 557150 │ 60s │ 0 │ online │ 0.1% │ 58.6mb │ jgr │ enabled │
└─────┴──────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/home/jgr/.pm2/pm2.log last 20 lines:
PM2 | 2022-05-31T11:23:53: PM2 log: Time : Tue May 31 2022 11:23:53 GMT+0100 (Western European Summer Time)
PM2 | 2022-05-31T11:23:53: PM2 log: PM2 version : 5.2.0
PM2 | 2022-05-31T11:23:53: PM2 log: Node.js version : 12.13.1
PM2 | 2022-05-31T11:23:53: PM2 log: Current arch : x64
PM2 | 2022-05-31T11:23:53: PM2 log: PM2 home : /home/jgr/.pm2
PM2 | 2022-05-31T11:23:53: PM2 log: PM2 PID file : /home/jgr/.pm2/pm2.pid
PM2 | 2022-05-31T11:23:53: PM2 log: RPC socket file : /home/jgr/.pm2/rpc.sock
PM2 | 2022-05-31T11:23:53: PM2 log: BUS socket file : /home/jgr/.pm2/pub.sock
PM2 | 2022-05-31T11:23:53: PM2 log: Application log path : /home/jgr/.pm2/logs
PM2 | 2022-05-31T11:23:53: PM2 log: Worker Interval : 30000
PM2 | 2022-05-31T11:23:53: PM2 log: Process dump file : /home/jgr/.pm2/dump.pm2
PM2 | 2022-05-31T11:23:53: PM2 log: Concurrent actions : 2
PM2 | 2022-05-31T11:23:53: PM2 log: SIGTERM timeout : 1600
PM2 | 2022-05-31T11:23:53: PM2 log: ===============================================================================
PM2 | 2022-05-31T11:23:53: PM2 log: [Watch] Start watching proxy
PM2 | 2022-05-31T11:23:53: PM2 log: App [proxy:0] starting in -fork mode-
PM2 | 2022-05-31T11:23:53: PM2 log: [Watch] Start watching idea
PM2 | 2022-05-31T11:23:53: PM2 log: App [idea:1] starting in -fork mode-
PM2 | 2022-05-31T11:23:53: PM2 log: App [proxy:0] online
PM2 | 2022-05-31T11:23:53: PM2 log: App [idea:1] online
I have the exactly same problem after updating a Raspberry Pi to the latest pm2 version. This device is still running Stretch and previously was using init.d (linux) for pm2 autostart. After the pm2 task did not start after boot we switched to systemd but this made no difference. It seems this issue is related to pm2 and not the init system.
The issue is reproducible without autostart too: "pm2 list" blocks for a long time until the pm2 daemon gets started.
The problem is pm2:
systemd-analyze blame
1min 13.100s pm2-pi.service
8.316s dhcpcd.service
4.603s hciuart.service
1.925s exim4.service
Will try next to downgrade to an older version.
After upgrading from Jessy to Buster this issue was gone. Downgrading pm2 did not change anything on Jessy.