On Free Tier t2.micro usually CPU Utilization reach to 99% and the deployed Website give error: "504 Gateway Time-out"

0

I am using free tier with t2.micro ec2 instance and usually within 10-20 days it becomes in such state that it gives the error : "504 Gateway Time-out" on browser and at that moment when i try to login in ec2 Instance console it keep processing but unable to login, obviously because of maximum use of CPU. At this state of instance it is showing Instance state: running and Status check: 2/2 checks passed. But when I see Monitoring tab it is showing CPU utilization (99%).

No background process, No Cron Jobs. It is a Ruby on Rails app with database and s3 bucket where we occasionally feed data and mostly people use it for browsing. When it comes in this state i have to always restart the instance manually, then again it start working well.

Questions:

How CPU utilization goes this much up?

When it goes up to 99% or comes to this state, how I can restart the instance automatically? OR How I can reject those requests to handle this situation?

My Setup configuration:

  • AMI : Canonical, Ubuntu, 22.04 LTS, free tier
  • Type : t2.micro
  • Application Developed: Ruby on Rails
  • Load Balancer: Yes
  • HTTPS: Yes
  • VPC and Subnets: Yes
  • Web server: Nginx
Shanu
已提問 2 個月前檢視次數 160 次
1 個回答
0

Hello.

How CPU utilization goes this much up?

"t2.micro" is an instance type with very low specifications, so if you run a database or other applications permanently, the CPU usage will increase quickly.
https://aws.amazon.com/ec2/instance-types/t2/?nc1=h_ls

Also, "t2.micro" can temporarily increase performance by consuming CPU credits, but once the CPU credits are consumed, the performance will drop to the baseline throughput.
As a result, the application is overwhelmed and a 504 error is occurring.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/burstable-credits-baseline-concepts.html

When it goes up to 99% or comes to this state, how I can restart the instance automatically? OR How I can reject those requests to handle this situation?

You can set EC2 actions when creating a CloudWatch alarm for CPU usage by following the steps in the document below.
EC2 actions include restart, so if you select restart when configuring, you can restart when the CPU usage exceeds the threshold set in the CloudWatch alarm.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/UsingAlarmActions.html

profile picture
專家
已回答 2 個月前
profile picture
專家
已審閱 2 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南