How to Optimize Server Performance: Config, Load Analysis & Kernel Tuning
This guide explains how to choose appropriate server hardware, analyze CPU, memory, disk I/O and network load, and fine‑tune kernel parameters such as file limits and TCP settings to achieve reliable high‑concurrency performance.
Server Configuration Selection
Servers consist of CPU, memory, disk and network interfaces, so selecting a configuration means choosing CPU cores, RAM size, disk capacity/type, and bandwidth. Because performance depends heavily on the application implementation, there is no one‑size‑fits‑all configuration; testing is essential.
Start with a modest server, run load tests, and use the results to guide the final hardware choice. For example, an order‑processing service tested on a 4‑core CPU, 16 GB RAM, 10 Mbps bandwidth, 50 GB HDD server handled 50 concurrent requests and 300 TPS, with CPU at ~75% and memory, bandwidth, and disk usage below 50%.
From this you can infer that a server with 4‑core CPU (CPU usage < 75%), 8 GB RAM (memory usage up to 100%), and 5 Mbps bandwidth can support the same load. Scaling to 200 concurrent users and 2400 TPS would require either eight such servers or a single 32‑core, 64 GB RAM, 40 Mbps server, subject to verification by testing.
Note: Backend servers and databases must be tuned together to avoid mismatched capacities. The method described may not suit every scenario.
Server Load Analysis
Performance tuning begins with load analysis, focusing on CPU usage, memory usage, disk I/O, and network bandwidth.
CPU Usage
CPU usage reflects how busy the processor is; at 100% some processes wait. In practice, keep CPU usage below 75% to handle traffic spikes; sustained usage above this threshold suggests adding more servers.
Use htop to monitor CPU, memory, and load.
Install and Use htop
yum install htop -yRun htop to view per‑core usage. When all cores exceed 75%, the server is overloaded.
The screenshot shows a 4‑core server with three cores above 75% and all cores around 85%, indicating high load.
Memory Usage
Memory usage shows how much RAM is occupied. When physical memory reaches 100%, the system swaps to virtual memory, which is much slower. Keep physical memory usage below 80% and avoid using swap.
Use htop to view memory usage.
The example shows 16 GB total memory with ~10 GB used (62% usage) and swap disabled.
Disk I/O
Disk I/O represents read/write activity, often dominated by database operations under high concurrency. Use iostat to monitor.
Install and Use iostat
yum install sysstat -y # View overall disk read/write every second
iostat -x 1Key disk metrics are %idle (desired > 70%) and %util (desired < 70%).
Average Load
Average load is the number of active processes over time; it should be less than the number of CPU cores. htop also shows the load average (1‑min, 5‑min, 15‑min). Values above 75% of core count indicate overload.
Network Usage
Network bandwidth must stay below 80% utilization to avoid latency spikes. Use nload to monitor inbound and outbound traffic.
Install and Use nload
yum install nload -y nloadWhen current bandwidth approaches the maximum, the link is saturated.
Server Kernel Parameter Tuning
Beyond hardware, kernel parameters must be tuned for high‑concurrency workloads, especially on front‑end, back‑end, and database servers.
Two main groups of parameters are the maximum open files per process and TCP settings.
Maximum Open Files
Edit /etc/security/limits.conf and add:
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535The asterisk applies to all users; the values take effect after reboot.
TCP Settings
Edit /etc/sysctl.conf and include the following (example values):
# Disable SYN flood protection for high‑concurrency
net.ipv4.tcp_syncookies = 0
# Enable reuse of TIME‑WAIT sockets
net.ipv4.tcp_tw_reuse = 1
# Enable fast recycling of TIME‑WAIT sockets
net.ipv4.tcp_tw_recycle = 1
# Reduce FIN‑WAIT‑2 timeout
tcp_fin_timeout = 30
# Keepalive interval (seconds)
tcp_keepalive_time = 1200
# Local port range for outbound connections
ip_local_port_range = 10246 5535
# SYN backlog size
tcp_max_syn_backlog = 65535
# Max TIME_WAIT sockets
tcp_max_tw_buckets = 5000
# Max packets queued per network interface
net.core.netdev_max_backlog = 65535
# Max TCP connections
net.core.somaxconn = 65535
# Receive buffer defaults
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
# Send buffer defaults
net.core.wmem_default = 8388608
net.core.wmem_max = 16777216
# Disable TCP timestamps
net.ipv4.tcp_timestamps = 0
# Limit orphaned sockets to mitigate DoS
net.ipv4.tcp_max_orphans = 3276800Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Su San Talks Tech
Su San, former staff at several leading tech companies, is a top creator on Juejin and a premium creator on CSDN, and runs the free coding practice site www.susan.net.cn.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
