InnoDB Variables Flashcards
What variable is this?
Scope: global
Dynamic
most important variable for memory optimization:
a cache for read data, indexes, and modified (dirty, data that hasn’t been flushed) data
want it big enough to avoid swapping (causes queries to lock), but not too big that the OS doesn’t have room for caching and memory structures
innodb_buffer_pool_size
Best practice for setting innodb_buffer_pool_size on a server running all tables with innodb storage engine
set the innodb buffer pool size to 75-80% of total MySQL memory
you want to leave room for OS cache (binary logs, relay logs, innodb transaction logs) and OS memory structures
Best practice for setting innodb_buffer_pool_size on a shared server
check the total size of tables using innodb and if it fits in 50% of total OS RAM
–> if it fits, you can set innodb_buffer_pool_size to the total size
→ if not, consider increasing it
What variable is this?
This sets the size of the InnoDB’s redo log files which, in MySQL world, are often called simply transaction logs.
making room for MySQL redo log
Default: 50331648 (48M)
global
not dynamic
innodb_log_file_size
Two reasons why the undo and redo functions are important database system
Rolling back a transaction (that’s the Undo)
Replaying committed transactions in case of a database crash (and that’s Redo)
What does it mean to have a small redo log size?
Small Log files = small buffer
small log files makes writes slower and crash recovery faster
small buffer and flushing needs to happen often
What does it mean to have a large redo log size?
Large log files = big buffer
large log files make writes faster and crash recovery slower
a lot more work needs to be done to restore the database to the consistent state (redo operation)
big buffer, flushing can be more streamlined
Best practice for setting innodb_log_file_size
If innodb_dedicated_server is enabled, the innodb_log_file_size value is automatically configured if it is not explicitly defined.
If not, check that the total size of your redo logs fit in 1-2 hours worth of writes during your busy period. If it doesn’t it needs to be adjusted to do so.
What variable is this?
Controls the balance between strict ACID compliance for commit operations and higher performance that is possible when commit-related I/O operations are rearranged and done in batches. You can achieve better performance by changing the default value but then you can lose transactions in a crash.
global, dynamic
Default: 1 (required for ACID compliance)- durability over performance
Instructs InnoDB to flush AND sync after EVERY transaction commit.
innodb_flush_log_at_trx_commit
innodb_flush_log_at_trx_commit option settings
Default: 1 (required for ACID compliance)- durability over performance
If you have it set to 0 or 2, sync is performed once a second instead. Not ideal for financial institutions like banks.
0 (flush, no sync) – the faster than 1, least reliable.
Means FLUSH to disk, but DO NOT SYNC (no actual IO is performed on commit)
- performance difference b/t 0 and 2 so 0 is a better choice than 2
2 (neither flush or syncing) – better performance than 1, worse reliability than 1
- means DON’T FLUSH and DON’T SYNC (again no actual IO is performed on commit)
What variable is this?
Controls how often the MySQL server synchronizes the binary log to disk.
global, dynamic
Default: 1 (should be 1 if innodb_flush_log_at_trx_commit = 1)
sync_binlog
sync_binlog variable options
Default: 1 (should be 1 if innodb_flush_log_at_trx_commit = 1)
- Enables synchronization of the binary log to disk before transactions are committed.
- Safest setting but can have a negative impact on performance due to the increased number of disk writes
0 (no slaves/backups or don’t mind losing events in the binary logs)- better performance
- Disables synchronization of the binary log to disk by the MySQL server.
N (N is another value than 0 or 1) - better performance than 1
- The binary log is synchronized to disk after N binary log commit groups have been collected.
What variable is this?
global, not dynamic
default: fsync or 0 (Unix), unbuffered (Windows)
chance to avoid double buffering
innodb_flush_method
True or False:
Setting innodb_flush_method to 0_DIRECT increases performance?
True
For increase performance, set to O_DIRECT to enable direct IO
InnoDB uses O_DIRECT or 4 (or directio() on Solaris) to open the data files, and uses fsync() to flush both the data and log files. This option is available on some GNU/Linux versions, FreeBSD, and Solaris.
Without direct IO, double-buffering happens because all database changes are first written to OS cache and then they are synced to disk – end up with the same data in InnoDB buffer pool AND in OS cache.
means in a write-intensive environment you could be losing up to almost 50% of memory, especially if your buffer pool is capped at 50% of total memory
server could end up swapping due to high pressure on the OS cache.
Options for innodb_flush_method: O_DIRECT or 4
O_DIRECT or 4 –> opens the data files, and uses fsync() to flush both the data and log files. This option is available on some GNU/Linux versions, FreeBSD, and Solaris.
Options for innodb_flush_method: O_DSYNC or 1
O_DSYNC or 1: InnoDB uses O_SYNC to open and flush the log files, and fsync() to flush the data files. InnoDB does not use O_DSYNC directly because there have been problems with it on many varieties of Unix.
Options for innodb_flush_method: littlesync or 2
littlesync or 2: This option is used for internal performance testing and is currently unsupported. Use at your own risk.