Skip to content

Lesson 7 of 9 · 27m

Memory, I/O, and InnoDB Tuning Without Cargo Cult

Tune buffer pool, redo, flushing, temporary tables, and connection memory based on workload measurements instead of copied configuration snippets.

Most MySQL tuning advice is archaeology: settings copied from a blog written for a different storage engine, kernel, workload, and decade. I once reviewed a server where innodb_flush_log_at_trx_commit=2 was justified as 'performance tuning' even though the business requirement was no committed-order loss. Tuning begins with durability, workload shape, and measured bottleneck. Everything else is folklore.

Durability settings are business decisions

Two settings dominate write durability:

innodb_flush_log_at_trx_commit = 1
sync_binlog = 1

With innodb_flush_log_at_trx_commit=1, InnoDB flushes redo at commit. With sync_binlog=1, binary logs are synchronized frequently enough to preserve committed transactions through crashes. Relaxing either can improve throughput while widening data-loss or recovery inconsistency windows. That may be acceptable for cache-like data and unacceptable for billing. State the trade explicitly.

The buffer pool is the first memory allocation, not the only one

innodb_buffer_pool_size = 48G
innodb_buffer_pool_instances = 8
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000

Those values are examples, not recommendations. innodb_io_capacity should reflect what storage can actually sustain; copying cloud volume numbers without measuring is how flushing falls behind during write bursts. Use operating-system and MySQL evidence together.

SELECT * FROM sys.memory_global_total\G
SHOW ENGINE INNODB STATUS\G

The BUFFER POOL AND MEMORY and TRANSACTIONS sections in InnoDB status reveal page activity, dirty pages, flush lists, and transaction pressure.

Connections cost memory and scheduler attention

Each connection consumes memory and can consume much more while sorting, joining, buffering, or holding transactions. A giant max_connections value is not capacity planning; it is a queue of mutually interfering work. Prefer application pooling and concurrency limits.

SHOW GLOBAL STATUS LIKE 'Threads_connected';
SHOW GLOBAL STATUS LIKE 'Max_used_connections';
SHOW GLOBAL VARIABLES LIKE 'max_connections';

If the database falls over at 300 active connections, raising the cap to 2,000 does not create extra CPU or storage. It often converts a controlled backlog into a memory and lock storm.

Temporary tables and filesorts are physical events

In-memory temporary tables can spill to disk depending on size and type. Sorting and grouping large intermediate results creates I/O and CPU pressure. Watch for workload evidence rather than banning these operations by slogan.

SELECT * FROM sys.statements_with_temp_tables LIMIT 10;
SELECT * FROM sys.statements_with_sorting LIMIT 10;

sys views aggregate Performance Schema data and are useful triage lenses, but always interpret them in context: total time, rows examined, executions, and whether the query is even part of the user-facing path.

Measure before and after one change

Tune one variable at a time when possible, record baseline and comparison windows, and avoid changing workload at the same moment. A configuration rollback plan matters because many settings require restart. Use identical traffic windows or controlled benchmarks; comparing Tuesday morning to Black Friday proves nothing.

Field notes

  • Query cache is gone in MySQL 8; tuning guides that mention it are not current evidence.
  • innodb_flush_method=O_DIRECT is common but not a universal law; understand filesystem and storage behavior.
  • Swapping database memory is usually catastrophic for latency; provision and monitor to avoid it.
  • Larger redo capacity can help write bursts but increases crash-recovery work.
  • Fast storage does not fix row scans caused by bad indexes.

Was this lesson helpful?

Sign in to rate