Will Increasing AWS Elastic Beanstalk Instance Size or Increasing Load Balancers Help Reduce Random 502 Nginx Errors?

347 views Asked by At

I recently added a CPU-intensive 20MB+ image decoding/parsing function to my Elastic Beanstalk application, and noticed that sometimes (~10% of the time) either calling the function itself, or subsequent, unrelated requests to the app result in a 502 error, from Nginx, not the app itself:

[09/Oct/2020:01:51:06 +0000] "GET /plaid/eoinfoinwfe HTTP/1.1" 502 157 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0_1 like Mac OS X) AppleWebKit

My Elastic Beanstalk instance is a t2.small running a Docker running on 64bit Amazon Linux 2/3.2.0 OS, and my load balancer looks like:

Listeners: 2
Load balancer type: application
Processes: 1

Would either switching to a bigger instance size or increasing processes of my Load Balancer help to mitigate the 502 errors that I'm seeing?

1

There are 1 answers

1
Marcin On BEST ANSWER

The additional info in the comments suggest that CPU utilization is high (80%). This is problematic because t2.small instances are burstable and have only 1 vCPU. So once an EB instance is busy processing the images for long time not only you may consume all CPU so that other processes on the instance can't work efficiently, it may be also depleting its CPU credits, further impacting its performance.

You could try changing to t2.medium which has 2 vCPUs and setting it in unlimited mode to overcome its CPU credit limitations. But since your tasks are CPU intensive, maybe it would be better to switch from t2, which are general purpose instances, into C5 family which are compute optimized. This way you don't have to worry about any CPU credits, but obviously they cost more. For comparison t2.small has 1 CPU with a clock 2.5GHz, while c5.large has 2 CPUs with 3.4 GHz.