Lesson 8 of 9 · 23m
Capacity Planning and Configuration Tuning Without Superstition
Memory allocation, redo sizing, IO settings, connection limits, and operational measurement — tune from evidence, not forum posts.
Most configuration tuning advice ages badly because it treats the database server as a benchmark specimen instead of a process sharing a machine with kernels, disks, firmware, backups, and terrified administrators. The right configuration starts with workload shape: read-heavy or write-heavy, hot set size, transaction size, concurrency, storage latency, and failure tolerance.
Memory: the buffer pool first, but not the whole machine
On a dedicated database host, the InnoDB buffer pool commonly lands around 60-75% of RAM. That is a starting point, not a law. Leave memory for the OS page cache, connections, temporary tables, monitoring agents, backup tools, and the inevitable incident shell sessions.
[mysqld]
innodb_buffer_pool_size = 48G
innodb_flush_method = O_DIRECT
innodb_io_capacity = 2000
innodb_io_capacity_max = 6000O_DIRECT avoids double-buffering InnoDB pages through the OS cache in common Linux deployments. IO capacity should reflect real storage capability; cloud volumes and local NVMe are not interchangeable. Measure latency and throughput before inventing numbers.
Redo capacity shapes write bursts
Too little redo forces aggressive dirty-page flushing and write stalls. Too much redo can lengthen crash recovery. MySQL 8.0.30+ uses innodb_redo_log_capacity; older MySQL and MariaDB use file sizing variables.
-- MySQL 8.0.30+
SELECT VARIABLE_VALUE FROM performance_schema.global_variables
WHERE VARIABLE_NAME = 'innodb_redo_log_capacity';Watch checkpoint activity and redo generation during peak write load. Sudden stalls in an otherwise healthy write workload often trace back to flushing pressure, not application lock contention.
Connections are expensive and queues are invisible
Each connection consumes memory and scheduler attention. A thousand idle clients do not make the server faster; they make exhaustion events more dramatic. Use pooling at the application and set server limits with headroom, not fantasy.
SHOW VARIABLES LIKE 'max_connections';
SHOW STATUS LIKE 'Threads_connected';
SHOW STATUS LIKE 'Threads_running';Threads_running is often more informative than raw connected count. A modest number of active threads doing IO can saturate the server long before the configured maximum is reached.
Temporary tables and sorts spill quietly
Queries that create large in-memory temporary tables can spill to disk. Sorting, grouping, JSON extraction, and bad joins all contribute. Monitor Created_tmp_disk_tables against Created_tmp_tables, but do not raise memory limits blindly; sometimes the correct fix is rewriting the query or adding an index.
Tune one variable with one hypothesis
Production tuning should look like this: state the bottleneck, change one variable, observe a defined metric, roll back if the hypothesis is wrong. Simultaneous changes make improvement impossible to attribute and regressions impossible to reverse confidently.
Hypothesis: redo checkpointing causes 2-second write stalls at minute boundaries.
Change: increase redo capacity from 2G to 8G.
Measure: p95 write latency and Innodb_log_waits during peak for 48 hours.Field notes
- Never copy a config from a larger machine. Memory ratios and IO behavior do not scale linearly.
- Swapping on a database host is poison. Tune memory so MySQL does not oscillate under pressure.
- Monitoring must include filesystem space, disk latency, replication lag, and error logs — not just query throughput.
- Configuration management matters. A hotfix made directly in
/etc/mysql/my.cnfand never committed will vanish exactly when you need it most.
Was this lesson helpful?