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
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ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ