Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Troubleshooting and Fixing 100% CPU Utilization for Apache on CentOS

Tech 1

Apache Initial Configuration

Navigate to /usr/local/apache/conf/extra/httpd-default.conf and ensure KeepAlive is toggled to On to reduce repeated TCP handshakes for persistent connections.

Linux Kernel Network and Resource Tuning

Append the following entries to /etc/sysctl.conf to adjust TCP handling and system-level limits. After saving, apply changes with sysctl -p:

net.ipv4.tcp_max_tw_buckets = 22000
net.core.somaxconn = 65536
net.ipv4.tcp_max_syn_backlog = 270000
net.core.netdev_max_backlog = 32000
net.ipv4.tcp_tw_recycle = 0
fs.file-max = 7000000
net.netfilter.nf_conntrack_max = 2700000

Note that the netfilter parameter may throw an error if iptables/nftables connection tracking is disabled; this can be ignored safely.

Persistent File Descriptor Limits

Elevate the maximum open file handles per process and system-wide to resolve high-concurrency too many open files errors, which often spike Apache CPU usage as it struggles to manage connection overhead.

Temporary fix (current terminal only):

ulimit -HSn 1048576

User-session persistent fix (append to /etc/profile):

ulimit -HSn 1048576

System-wide permanent fix (requires reboot; add to /etc/security/limits.conf):

* soft nofile 1048576
* hard nofile 1048576
root soft nofile 1048576
root hard nofile 1048576

Basic MySQL Connection Tuning

High CPU can also stem from MySQL bottlenecks limiting Apache worker release. First check current connection limits:

SHOW VARIABLES LIKE 'max_conn%';

Dynamically adjust limits without restarting MySQL (values reset on reboot):

SET GLOBAL max_connections = 11000;
SET GLOBAL max_connect_errors = 5500;

For persistence, add these to my.cnf or my.ini under the [mysqld] section.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.