2

If i run simple node.js server, how jelastic automatic vertical scaling affects it? Is it scale only resources like CPU, RAM and so on, or creates new node containers that work in parralell?

If it's scale only resources, than how should i use pm2 cluster mode correctly to spawn new process on new CPU core?

ZiiMakc
  • 31,187
  • 24
  • 65
  • 105

1 Answers1

4

Generally, as for the Jelastic certified NodeJS template - only the --max_old_space_size is set accordingly to the amount of available memory and it is calculated as the amount of system memory * 0.9 This automatic configuration can be turned off by setting the value of AUTO_OLD_HEAP environment variable to "false"

As for the CPU - PM2 can automatically count the number of launched processes depending on the number of available CPUs just by adding the

instances : "max"

to the ecosystem file, as described here https://pm2.keymetrics.io/docs/usage/cluster-mode/

  • but will pm2 add instances when node scales? – ZiiMakc Aug 27 '20 at 12:57
  • 1
    I've done some tests and, unfortunately, PM2 applies the number of CPUs as number of workers only on startup and do not watch the number of CPUs on runtime. As the workaround - the "pm2 scale" functionality can be used, for example, you can create the crontab for nodejs user which periodically count the number of available CPUs in system and scales your application up/down according to it. Such command can be used: `pm2 scale draw-game $(grep -c ^processor /proc/cpuinfo)` where the "draw-game" (the name of the default demo application) must be replaced with your one. – Dmytro Zubelevych Aug 27 '20 at 15:16
  • 1
    @ZiiMakc, I assume you need to adjust number of pm2 instances after changing number of available cloudlets (CPU & RAM) per container. At the moment it is possible to attach a custom action to onAfterSetCloudletCount event https://docs.cloudscripting.com/creating-manifest/events/#onaftersetcloudletcount and restart server (or container) or adjust number of pm2 instances. There is an example how this event is used at one of the auto-clustering packages https://github.com/jelastic-jps/wildfly/blob/master/addons/auto-clustering/auto-cluster.jps#L53. – Ruslan Aug 27 '20 at 15:33
  • Actually, the number of available CPUs is pre-defined by the upper cloudlets limit (usually it is the number of flexible cloudlets), so it can be changed only by changing the cloudlets limit. The NodeJS process is re-started in case of changing the cloudlets limit in the Environment wizard of Jelastic dashboard, and pm2 process count is re-applied on restart (if the 'instances: max' is specified). CPUs count is not changed on runtime, so the pm2 processes number will always correspond it (if the mentioned setting is present in the ecosystem file). – Dmytro Zubelevych Aug 28 '20 at 14:47