Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EC2 Micro Instance CPU spikes to 100% at regular interval every day

enter image description here

I know Amazon throttles micro instance if it uses up certain number of CPU time, but I don't think this is the case. All the spikes appear at around 6:30 to 6:40 UTC. I checked my cron job and there is nothing scheduled for that time:

@reboot ~/path/to/script1.sh >> ~/log/cron.log
0 13 * * * ~/path/to/script2.sh >> ~/log/cron.log

What else could it be?

PS: Notice the CPU Utilization dropdown is set at "Maximum". The graph looks similar for "Average". PPS: This instance is part of a 2-instance load-balanced setup.

Here's what's inside my /etc/cron.daily (the other crons are empty):

apport, apt, aptitude, bsdmainutils, dpkg, logrotate, man-db, mlocate, passwd, popularity-contest, standard, update-notifier-common

like image 701
pixelfreak Avatar asked Dec 21 '12 02:12

pixelfreak


People also ask

What is the best EC2 instance for heavy CPU load?

M3 instances are the newest generation of general-purpose instances, and give you the option of a larger number of virtual CPUs (vCPUs) that provide higher performance. M3 instances are recommended if you are seeking general-purpose instances with demanding CPU requirements.

Why is AWS CPU utilization high?

The CPU utilization is a metric associated with usage of EC2 instances and varies depending upon the workload assigned to an instance. If AWS EC2 CPU utilization is high, it means that there is an effective utilization of instances and ensures smooth operations as well.

How do I diagnose high CPU utilization on my EC2 Linux?

Connect to your instance using Remote Desktop Protocol (RDP). Open Task Manager, and then select the CPU column to sort by CPU. Research any processes with high CPU utilization to determine whether they are using the expected amount of CPU. Troubleshoot any applications that are using more CPU than expected.


1 Answers

Usually, Ubuntu AMIs on Amazon have their daily cron jobs under /etc/cron.daily scheduled for morning hours. This schedule is managed using /etc/crontab. Here's how a sample /etc/crontab looks like:

$ cat /etc/crontab 
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

Clearly, daily tasks run at 6:25am. You may want to tweak these settings to move daily tasks to some other time if this is impacting direct delivery of your server(s). Further, you could investigate items under /etc/cron.daily. For me, it looks like:

$ ls /etc/cron.daily/
apport  apt  aptitude  bsdmainutils  dpkg  logrotate  man-db  mlocate  popularity-contest  standard

Out of these, typically man-db and logrotate may take up major CPU time for execution. These are standard tasks and can be tweaked for optimum performance. You may want to look into tuning your logrotate and man-db policies.

Hope this helps.

like image 75
rhetonik Avatar answered Nov 15 '22 15:11

rhetonik