High CPU Usage Issue on Magento Website hosted in EC2 with MySQL Aurora RDS Instance

Abstract: Resolve high CPU usage on Magento EC2 by optimizing Aurora RDS queries, configuring Varnish caching, and tuning PHP-FPM settings.

Created: 2026-10-07 by

High CPU usage on a Magento EC2 instance connected to Aurora RDS usually stems from inefficient database queries, missing cache layers, or insufficient server resources. By optimizing MySQL indexing, configuring Varnish caching, and tuning PHP-FPM settings, you can significantly reduce load times and stabilize performance for your e-commerce platform.

Diagnosing the Root Cause of High CPU

Before applying fixes, it is crucial to identify whether the bottleneck lies within the application server (EC2) or the database layer (Aurora RDS). High CPU utilization on EC2 often indicates that the web server is struggling to process requests, while high CPU on Aurora suggests complex queries are taxing the database engine. Start by monitoring the AWS CloudWatch metrics for both instances. Look at the CPUUtilization metric for the EC2 instance and the CPUUtilization for the Aurora DB cluster. If the EC2 CPU spikes during traffic surges but the database remains stable, the issue is likely application-side. Conversely, if the database shows high read/write IOPS and CPU usage, the problem originates from slow SQL queries. For Magento specifically, common culprits include full table scans due to missing indexes, unoptimized product listings, or excessive logging. Use the Magento profiler to identify which modules or controllers are consuming the most time. Enable the profiler in app/etc/local.xml or via the admin panel to get detailed breakdowns of execution times per request. This data helps pinpoint whether specific actions, such as checkout processes or search queries, are causing the spike.

Optimizing Database Performance on Aurora

Since Magento relies heavily on MySQL-compatible databases, optimizing Aurora is often the most effective way to reduce overall system load. Inefficient queries force the database to work harder, which indirectly increases CPU usage on the EC2 instance as it waits for responses. First, analyze the slow query log in Aurora. Configure the slow_query_log parameter to capture queries taking longer than a specified threshold, typically 1 second. Review these logs to identify repetitive patterns, such as searches on non-indexed columns like sku or name. Adding appropriate indexes to frequently queried tables can drastically reduce execution time. Next, ensure that the Magento indexer is running correctly. Full-text search features in Magento can be resource-intensive. Consider migrating from MySQL full-text search to Elasticsearch, which offloads search operations from the primary database. This separation allows Aurora to focus on transactional data while Elasticsearch handles complex search queries efficiently. Additionally, review the connection pool settings. Too many open connections can lead to contention. Adjust the max_connections setting in Aurora to match your expected concurrency levels without overwhelming the system. Regularly run ANALYZE TABLE to keep statistics up-to-date, ensuring the query optimizer chooses the most efficient execution plans.

Tuning PHP-FPM and Web Server Settings

The EC2 instance serves as the front-end for your Magento store. If PHP-FPM is misconfigured, it can lead to high CPU usage even with moderate traffic. Start by reviewing the php-fpm.conf file. Ensure that the pm.max_children directive is set appropriately for your available memory. A common mistake is setting this value too high, causing the server to swap memory to disk, which severely degrades performance. Use tools like nproc to determine the number of CPU cores and calculate an optimal child process count. For example, if you have 4 cores and each PHP process uses approximately 100MB of RAM, you might set pm.max_children to around 16-20 depending on total RAM. Also, enable OPCache in PHP. OPCache stores precompiled script bytecode in shared memory, reducing the need for PHP to parse and load scripts on every request. Configure Nginx or Apache to serve static files directly. Magento generates significant amounts of static content, including CSS, JavaScript, and images. By offloading these assets to the web server rather than passing them through PHP, you reduce the processing load on the application layer. Set appropriate expiration headers for static resources to leverage browser caching, further decreasing repeat visits' server load.

Implementing Caching Strategies

Caching is perhaps the most powerful tool for reducing CPU usage in Magento. Without proper caching, every page view requires a full round-trip to the database and PHP execution. Implementing Varnish Cache as a reverse proxy in front of your EC2 instance can absorb a large portion of incoming traffic. Varnish stores rendered HTML pages in memory, serving them directly to users without hitting the backend server. This reduces the number of PHP-FPM processes needed simultaneously. Configure Varnish to handle cache invalidation correctly, especially for dynamic content like shopping carts and user sessions. Use Magento's built-in Varnish configuration profiles to ensure compatibility. If Varnish is not feasible, consider using Redis for session storage and full-page caching. Redis provides fast, in-memory data storage that integrates seamlessly with Magento. It handles session management more efficiently than traditional file-based sessions, reducing disk I/O and CPU overhead associated with reading and writing session data. Furthermore, optimize your CDN strategy. Use a Content Delivery Network to distribute static assets globally. This reduces latency for end-users and decreases the bandwidth requirements on your EC2 instance. While CDNs do not directly lower EC2 CPU usage, they improve overall responsiveness and reduce the strain on your origin server during peak traffic periods.

Scaling and Resource Management

Sometimes, optimization alone is not enough. If your traffic grows beyond the capacity of a single EC2 instance, scaling becomes necessary. AWS Auto Scaling groups can automatically adjust the number of EC2 instances based on predefined metrics, such as CPU utilization or network traffic. Set up scaling policies that trigger when average CPU usage exceeds a certain threshold, for example, 70%. This ensures that additional instances are launched to handle increased load, preventing service degradation. Pair this with an Application Load Balancer (ALB) to distribute traffic evenly across all healthy instances. Consider using AWS Lambda for specific tasks, such as image processing or email notifications. Offloading these asynchronous tasks to serverless functions can free up EC2 resources for handling core web requests. For more information on architectural decisions, see AWS Lambda vs EC2: Which is Better for Microservices vs Monolith Architecture?. This comparison helps in determining when to shift workloads to serverless environments. Regularly review your infrastructure costs and performance. Use AWS Cost Explorer and Trusted Advisor to identify underutilized resources or opportunities for optimization. Ensuring that your Magento environment is right-sized prevents over-provisioning and keeps operational expenses manageable while maintaining high availability.

Frequently Asked Questions

How do I check if my Magento database has missing indexes?

You can identify missing indexes by analyzing the slow query log in Aurora and looking for queries performing full table scans. Run the EXPLAIN statement before your problematic SQL queries to see if "Using index" appears in the type column; if it says "ALL," you likely need an index.

Is Varnish Cache compatible with all Magento versions?

Varnish is compatible with Magento 2.x, but configuration varies by version. Magento provides built-in Varnish configuration files that must be placed in the correct directory and enabled via the command line interface to ensure proper cache tagging and invalidation.

What causes high CPU usage during Magento indexer reindexing?

Reindexing requires significant computational power to rebuild search indexes and update catalog rules. To mitigate this, schedule reindexing during low-traffic periods and use asynchronous indexing options available in Magento 2 to prevent blocking frontend requests.

Can I use Redis for both session storage and full-page caching?

Yes, Redis supports multiple data structures and can be configured to handle both session storage and full-page caching simultaneously. However, ensure sufficient memory allocation in your Redis cluster to prevent eviction policies from removing cached pages prematurely.

Why is my EC2 CPU high even with low traffic?

Low traffic with high CPU often indicates background processes, such as cron jobs, logging, or failed health checks, are consuming resources. Check the Magento cron schedule and server logs for errors or runaway processes that may be stuck in loops.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More