I have a MySQL database in production and I am trying to calculate the optimised number to set the MySQL max_connections value to - Am I doing this correctly as my sums seem quite high to me.
As far as I can tell the logic from the link below is as follows using the URLs added at the end of this post :
I have ssh'd into the relevant server and in the MySQL terminal found the relevant variables using a query similar to this SHOW VARIABLES LIKE '%buffer%';
This gives me variable info like this..
Available RAM = Global Buffers + (Thread Buffers x max_connections)
max_connections = (Available RAM – Global Buffers) / Thread Buffers
To find out the available RAM I have simply run free -b
in the terminal which returns this :
To calculate the relevant Globa buffers & Thread buffers I have simply added the values up based on these values
Global Buffers: key_buffer_size, innodb_buffer_pool_size, innodb_log_buffer_size, innodb_additional_mem_pool_size, net_buffer_size, query_cache_size
Thread Buffers: sort_buffer_size, myisam_sort_buffer_size, read_buffer_size, join_buffer_size, read_rnd_buffer_size, thread_stack
This gives me the following numbers :
Global Buffers = (67108864 + 2147483648 + 16777216 + 0 + 0 + 33554432) = 2264924160
Thread Buffers = (1048576 + 67108864 + 1048576 + 1048576 + 8388608 + 262144) = 78905344
So using this logic - max_connections = (Available RAM – Global Buffers) / Thread Buffers
I presume the calculation is correct - this gives me 1680 max_connections.. does this seem correct?
max connections = (134902571008 - 2264924160) / 78905344 = 1680.97165698