40.7 Common Performance Tuning Parameters for Databases and Web Servers

Right, let’s get our hands dirty with the knobs and levers that actually matter. Forget the hundreds of esoteric sysctl values you’ll never touch. We’re here to talk about the ones that, when tuned correctly, can make your database stop whimpering and your web server feel like it’s been shot out of a cannon. This isn’t magic; it’s about understanding how the kernel manages resources and telling it to stop being so conservative for a modern workload.

40.6 File Descriptor Limits: fs.file-max and nofile ulimit

Right, file descriptors. The humble, unassuming integer that the kernel hands out every time you open a file, a socket, or just about anything else. Think of them as tickets. The kernel is the bouncer at an exclusive club (your system resources), and every process needs a ticket to get in. Now, what happens when the bouncer runs out of tickets? Chaos. Connection refusals. Crashes. A logging daemon that suddenly can’t write to its log file. It’s a bad night.

40.5 VM Tuning: vm.dirty_ratio, vm.overcommit_memory

Right, let’s talk about the kernel’s virtual memory (VM) subsystem. This is where we go from userspace tourists to kernel-level operators. The kernel’s VM is a brilliant, complex, and occasionally slightly unhinged piece of engineering. It’s trying to juggle a thousand things at once: making your applications feel fast, using your RAM efficiently, and preventing the whole house of cards from collapsing. The sysctl knobs we’re about to tweak are how we whisper suggestions into the juggler’s ear. Use this power wisely.

40.4 Network Tuning: net.core, net.ipv4, TCP Buffer Sizes

Right, let’s talk about tuning the network stack. This is where we stop politely asking the kernel to move data and start telling it. The /proc/sys/net/ directory is our control panel, and sysctl is the button-laden, slightly confusing remote. We’re going to focus on the big ones: net.core, net.ipv4, and the glorious, often-misunderstood world of TCP buffers. First, a reality check. The kernel’s default settings are designed for a hypothetical, perfectly average machine from roughly a decade ago. They are comically conservative for a modern server with 10GbE or 40GbE NICs. If you just plug in a fast network card and do nothing, it’s like putting a Formula 1 engine in a golf cart—you’re not going to see any benefit. The cart’s frame (your kernel parameters) can’t handle the power.

40.3 /etc/sysctl.conf and /etc/sysctl.d: Persistent Parameter Files

Right, so you’ve been playing with sysctl on the live kernel, making your system do tricks on the fly. That’s all well and good until you reboot and all your brilliant, finely-tuned parameters vanish into the ether. Poof. Gone. Like you never even cared. That’s where persistent configuration files come in. They’re your way of telling the system, “Look, these aren’t just suggestions for this boot cycle. I want these settings every time we do this.” The main character in this story is /etc/sysctl.conf, an old warhorse that gets the job done but is starting to show its age. The more modern, organized approach is using drop-in files in /etc/sysctl.d/. You should use the latter for pretty much everything new, but you need to understand both because you’ll inevitably encounter systems that still rely on the old way.

40.2 /proc/sys: The Filesystem Interface for sysctl

Alright, let’s get our hands dirty. Forget fancy GUI tools for a second; the real, raw interface to your kernel’s settings is right there in the /proc/sys directory. Think of it not as a folder full of normal files, but as a live, readout-and-control panel directly wired into the brain of your running Linux kernel. Every “file” you see in there isn’t taking up space on your disk; it’s a magical portal that either reflects the current value of a kernel parameter or lets you change it on the fly. Reading from one of these pseudo-files asks the kernel, “Hey, what’s your setting for this?” and writing to it says, “Hey kernel, change this setting to that.” It’s brilliantly simple and incredibly powerful.

40.1 sysctl: Reading and Writing Kernel Parameters at Runtime

Right, let’s talk about sysctl. Forget the dusty manuals for a second. Think of the Linux kernel not as a monolithic block of code, but as a living, breathing, slightly obsessive-compulsive entity with thousands of knobs and dials controlling its behavior. sysctl is how you, the mere mortal, reach into its brain and start tweaking those dials while it’s still running. No reboot required. It’s black magic, and I’m here to give you the incantations.

— joke —

...