3

Hi I have a silly question, but couldn't find any answers.

NodeJS runs on a single thread - if I deploy my express API to elastic beanstalk, does it make any sense to use instance types with multiple vcpus? Does the nodejs environment for elastic beanstalk employ nodejs clustering?

If my app is a straightforward express API, won't it just start one process that will end up utilizing just one cpu? If yes, I feel like its better to rely on single vcpu-instances and have the ASG do the work instead of clustering?

boy
  • 405
  • 4
  • 12

2 Answers2

2

You can take advantage of clusters.

I deployed an express app to elastic beanstalk using cluster. It uses all the cores. First, application load balancer on AWS side distributes the load to the instances. Inside instance NodeJS Cluster API distributes requests to the workers based on round-robin by default.

AWS beanstalk nodejs multicore

Its a good use case if you can't find an ideal instance for your needs.

After a few months, I noticed an issue with the logs. Since the thread count increased inside instance, the log count is multiplied by thread count. I learned that Journal service inside Amazon Linux instances has a burst limit of 1000 logs per 30 seconds. Apart from that, it works smoothly.

1

No.

I ran into this just recently with an app that had to scale up - and I noticed moving from m5a.large to m5a.xlarge (or even m5a.2xlarge) made NO difference to perf at all. NodeJS was only using 1 vCPU - so adding more just wasted money.

My app used very little memory, so for me the best instance was c5a.large (the smallest compute-optimized instance), then I just scale out more.

Sadly all the instances with 1 vCPU were too weak for my use-case.

But, if you want to test this for your own app - set an EC2 Key Pair up for your instances (in EB 'security' config), SSH in, and check how things are actually running on your instances under load.

KingJackaL
  • 780
  • 4
  • 17