By Shamoil Khan
I’m deploying a Node.js app on App Platform, and Node.js normally utilises only one CPU core. I want to know if I need to use cluster in my code, or use pm2 to utilise all CPU cores, or DO App Platform automatically handles it? If I had to do it myself, which approach should be recommended?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there,
I think that a standard Node.js server won’t automatically use all cores because Node.js is single-threaded by default, and I would guess that App Platform doesn’t handle clustering automatically.
I think that the App Platform would give your container access to the full 2 vCPUs, but to use both you’ll need to implement multi-core handling in your code with Node’s built-in cluster
or worker_threads
modules.
PM2 might work in some cases using pm2-runtime
, but there are some limitations around pm2
monitoring listed here:
https://docs.digitalocean.com/products/app-platform/details/limits/
So it might be best to use clustering in your code or scale horizontally with multiple App Platform instances instead.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.