Master Linux Kernel Tuning: Boost Network, File Limits & Disk Scheduling for High‑Performance Servers
This guide walks you through optimizing Linux kernel parameters—including sysctl network settings, local port ranges, and file descriptor limits—shows a real‑world Nginx high‑traffic case, and explains disk scheduler choices, providing concrete commands and recommended values for robust server performance.
1. Optimize Kernel Parameters
Key kernel settings are adjusted via /etc/sysctl.conf. Add each parameter on a separate line and apply changes with sysctl -p.
sysctl -a # view current settings
sysctl -p # reload and check for errorsNetwork‑Related Parameters
net.core.somaxconn=65535– maximum TCP listen queue length per port. net.core.netdev_max_backlog=65535 – upper bound of packets queued when arrival rate exceeds kernel processing speed. net.ipv4.tcp_max_syn_backlog=65535 – max SYN queue length; larger values help mitigate SYN‑flood attacks. net.ipv4.tcp_fin_timeout=10 – timeout for sockets in FIN‑WAIT‑2 state. net.ipv4.tcp_tw_reuse=1 – allow TIME‑WAIT sockets to be reused for new connections. net.ipv4.tcp_tw_recycle=1 – enable fast recycling of TIME‑WAIT sockets (disabled by default).
These values are suitable for hosts with 8 GB–16 GB RAM; adjust as needed.
Local Port Range
When the system runs out of local ports, errors like "Can’t assign requested address" appear because each socket needs a unique local port.
# View current range
cat /proc/sys/net/ipv4/ip_local_port_range
# Default example
32768 61000
# Change range
vim /etc/sysctl.conf
net.ipv4.ip_local_port_range = 1024 65000
sysctl -pNote: the minimum must be ≥1024; raise it if your services use ports above 1024.
2. Increase Resource Limits
Configuration file: /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535* – applies to all users.
soft – current effective limit.
hard – maximum enforceable limit.
nofile – maximum number of open files.
65535 – new limit value (requires reboot).
Case Study : Nginx experienced "Too many open files" errors during peak traffic. The ulimit -a output showed a low open‑file limit. Updating /etc/security/limits.conf and restarting Nginx resolved the issue.
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535In Nginx configuration add: worker_rlimit_nofile 65535; Verification shows the new limit applied:
3. Disk Scheduling Strategies
Parameter path: /sys/block/<em>devname</em>/queue/scheduler
noop – FIFO queue, favors writes, ideal for SSDs and embedded systems.
deadline – guarantees service within a deadline; default read deadline is shorter than write, best for database workloads.
anticipatory – similar to deadline but adds a short wait after reads to batch writes; good for write‑heavy environments but poor for databases.
cfq – Completely Fair Queuing algorithm.
Relevant kernel parameter directories: /proc/sys/abi/* – binary compatibility support. /proc/sys/fs/* – file system limits and quotas. /proc/sys/kernel/* – PID limits, shared memory, debug levels. /proc/sys/net/* – network optimizations for IPv4/IPv6. /proc/sys/vm/* – cache and buffer management.
Signed-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.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
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.
