Dario Zadro
Dario Zadro

Reputation: 1284

Tuning MySql my.cnf for Many Users

I'm looking for some help tuning our my.cnf file to handle many current users (about 20 orders/minute). This particular site is in WordPress and running Woocommerce.

After a lot of reading online, I've come up with the settings below. The server is Debian 8 with 12 CPUs and 48GB RAM.

query_cache_type = 1
query_cache_limit = 256K
query_cache_min_res_unit = 2k
query_cache_size = 80M

key_buffer      = 2G
max_allowed_packet  = 512M
thread_cache_size   = 256K
tmp_table_size      = 4G
max_heap_table_size = 4G
table_cache     = 1024
table_definition_cache  = 1024
myisam_recover          = FORCE,BACKUP
max_connections         = 300
wait_timeout        = 120
connect_timeout     = 120
interactive_timeout     = 120

innodb_flush_method            = O_DIRECT
innodb_flush_log_at_trx_commit = 2
innodb_file_per_table          = 1
innodb_buffer_pool_size        = 2G
innodb_io_capacity      = 1000
innodb_read_io_threads      = 32
innodb_thread_concurrency   = 0
innodb_write_io_threads     = 32

It seems to be running pretty good for now. Any additional thoughts? Thanks for your input!

Upvotes: 1

Views: 4263

Answers (1)

Bill Karwin
Bill Karwin

Reputation: 563021

query_cache_type = 1
query_cache_limit = 256K
query_cache_min_res_unit = 2k
query_cache_size = 80M

See https://dom.as/tech/query-cache-tuner/

key_buffer      = 2G

Key buffer is only for MyISAM. You shouldn't use MyISAM.

max_allowed_packet  = 512M
thread_cache_size   = 256K
tmp_table_size      = 4G
max_heap_table_size = 4G

4G is probably way too high for the tmp table and heap table sizes. Keep in mind multiple threads can create temp tables concurrently.

table_cache     = 1024
table_definition_cache  = 1024

Probably overkill.

myisam_recover          = FORCE,BACKUP

Also used only for MyISAM.

max_connections         = 300

What does show global status like 'max_used_connections' say? Is it close to max_connections?

wait_timeout        = 120
connect_timeout     = 120
interactive_timeout     = 120

innodb_flush_method            = O_DIRECT
innodb_flush_log_at_trx_commit = 2
innodb_file_per_table          = 1
innodb_buffer_pool_size        = 2G

Fine but with 48G of RAM, you can probably increase the buffer pool size.

Run show engine innodb status and look for these lines:

Buffer pool size        131072
Free buffers            0
Database pages          128000

Is your buffer pool always pegged full? If so, increase its size.

What's the total size of your database? You don't need the buffer pool to be larger than the total size of your data+indexes, but large enough to hold the frequently-accessed pages would be good.

select round(sum(data_length+index_length)/1024/1024, 2) as mb 
from information_schema.tables where engine='InnoDB'
innodb_io_capacity      = 1000
innodb_read_io_threads      = 32
innodb_thread_concurrency   = 0
innodb_write_io_threads     = 32

The io capacity might be greater than the ability of your disks to keep up. You didn't describe what your disk system is.

The io threads is way overkill for a Wordpress site with the traffic you describe. Run show engine innodb status and look for this line:

Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,

If you always see 0's on that line, you don't need more than the default 4 & 4 io threads.

Upvotes: 1

Related Questions