Although I am sure this is a perennial topic in this group, I would like to start (yet another) discussion on optimization of my.cnf. I really don't understand mysql at all, and I have found even the slightest change to the my.cnf settings has a massive impact on my server performance.
I could really use some advice on settings from the group. Hopefully this threat can grow and be useful to others in the future.
Site is planned to be used as a social network, expectation is that logged in members can add a variety of content types. Various views on panel pages display content. Some views have exposed filter criteria, others are more "static" and perhaps candidates for views caching.
Focus is on serving user generated content to logged in members, limited exposure of content to anon web surfers.
A VPS from Godaddy. Centos 6 server running Apache/mysql 5.1x, PHP, etc.
APC running, set to 384MB. Seems to be using around half of that on any given day.
Limited use for server other than the one D7 site.
D7 with over 150+ modules. Just started enabling selective Views caching.
I really don't have a clue what I am doing with the db. I don't know if/how Innodb should be enabled?
I have tried the tuning-primer.sh script a few times. Load on server is still very light as it is barely into beta testing. I don't know if these stats are usable as the server load grows? In any case, output of recent tuning-primer.sh is included here for your viewing enjoyment...
-- MYSQL PERFORMANCE TUNING PRIMER -- - By: Matthew Montgomery -
MySQL Version 5.1.61 x86_64
Uptime = 2 days 15 hrs 34 min 33 sec
Avg. qps = 53
Total Questions = 12312015
Threads Connected = 1
Server has been running for over 48hrs.
It should be safe to follow these recommendations
To find out more information on how each of these
runtime variables effects performance visit:
for info about MySQL's Enterprise Monitoring and Advisory Service
The slow query log is NOT enabled.
Current long_query_time = 10.000000 sec.
You have 0 out of 12312036 that take longer than 10.000000 sec. to complete
Your long_query_time seems to be fine
BINARY UPDATE LOG
The binary update log is NOT enabled.
You will not be able to do point in time recovery
Current thread_cache_size = 8
Current threads_cached = 7
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine
Current max_connections = 151
Current threads_connected = 1
Historic max_used_connections = 18
The number of used connections is 11% of the configured maximum.
Your max_connections variable seems to be fine.
No InnoDB Support Enabled!
Max Memory Ever Allocated : 650 M
Configured Max Per-thread Buffers : 2.70 G
Configured Max Global Buffers : 320 M
Configured Max Memory Limit : 3.02 G
Physical Memory : 2.00 G
Max memory limit exceeds 90% of physical memory
Current MyISAM index space = 52 M
Current key_buffer_size = 256 M
Key cache miss rate is 1 : 1710
Key buffer free ratio = 74 %
Your key_buffer_size seems to be fine
Query cache is enabled
Current query_cache_size = 64 M
Current query_cache_used = 29 M
Current query_cache_limit = 1 M
Current Query cache Memory fill ratio = 45.79 %
Current query_cache_min_res_unit = 4 K
MySQL won't cache query results that are larger than query_cache_limit in size
Current sort_buffer_size = 2 M
Current read_rnd_buffer_size = 12 M
Sort buffer seems to be fine
Current join_buffer_size = 132.00 K
You have had 225 queries where a join could not use an index properly
You should enable "log-queries-not-using-indexes"
Then look for non indexed joins in the slow query log.
If you are unable to optimize your queries you may want to increase your
join_buffer_size to accommodate larger joins in one pass.
Note! This script will still suggest raising the join_buffer_size when
ANY joins not using indexes are found.
OPEN FILES LIMIT
Current open_files_limit = 1561 files
The open_files_limit should typically be set to at least 2x-3x
that of table_cache if you have heavy MyISAM usage.
You currently have open more than 75% of your open_files_limit
You should set a higher value for open_files_limit in my.cnf
Current table_open_cache = 700 tables
Current table_definition_cache = 512 tables
You have a total of 808 tables
You have 700 open tables.
Current table_cache hit rate is 6%
, while 100% of your table cache is in use
You should probably increase your table_cache
You should probably increase your table_definition_cache value.
Current max_heap_table_size = 16 M
Current tmp_table_size = 16 M
Of 17728 temp tables, 22% were created on disk
Created disk tmp tables ratio seems fine
Current read_buffer_size = 4 M
Current table scan ratio = 13 : 1
read_buffer_size seems to be fine
Current Lock Wait ratio = 1 : 86
You may benefit from selective use of InnoDB.
If you have long running SELECT's against MyISAM tables and perform
frequent updates consider setting 'low_priority_updates=1'
If you have a high concurrency of inserts on Dynamic row-length tables
consider setting 'concurrent_insert=2'.
And finally, the my.cnf file I am currently using:
Example MySQL config file for large systems.
This is for a large system with memory = 512M where the system runs mainly
MySQL programs look for option files in a set of
locations which depend on the deployment platform.
You can copy this option file to one of those
locations. For information about these locations, see:
In this file, you can use all long options that a program supports.
If you want to know which options a program supports, run the program
with the "--help" option.
The following options will be passed to all MySQL clients
password = your_password
port = 3306
socket = /var/lib/mysql/mysql.sock
Here follows entries for some specific programs
The MySQL server
port = 3306
socket = /var/lib/mysql/mysql.sock
key_buffer_size = 256M
max_allowed_packet = 16M
table_open_cache = 700
table_definition_cache = 512
sort_buffer_size = 2M
read_buffer_size = 4M
read_rnd_buffer_size = 12M
myisam_sort_buffer_size = 128M
thread_cache_size = 8
Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
Don't listen on a TCP/IP port at all. This can be a security enhancement,
if all processes that need to connect to mysqld run on the same host.
All interaction with mysqld must be made via Unix sockets or named pipes.
Note that using this option without enabling named pipes on Windows
(via the "enable-named-pipe" option) will render mysqld useless!
Replication Master Server (default)
binary logging is required for replication
binary logging format - mixed recommended
required unique id between 1 and 2^32 - 1
defaults to 1 if master-host is not set
but will not function as a master if omitted
server-id = 1
Replication Slave (comment out master section to use this)
To configure this host as a replication slave, you can choose between
two methods :
1) Use the CHANGE MASTER TO command (fully described in our manual) -
the syntax is:
CHANGE MASTER TO MASTER_HOST=, MASTER_PORT=,
MASTER_USER=, MASTER_PASSWORD= ;
where you replace , , by quoted strings and
by the master's port number (3306 by default).
CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
2) Set the variables below. However, in case you choose this method, then
start replication for the first time (even unsuccessfully, for example
if you mistyped the password in master-password and the slave fails to
connect), the slave will create a master.info file, and any later
change in this file to the variables' values below will be ignored and
overridden by the content of the master.info file, unless you shutdown
the slave server, delete master.info and restart the slaver server.
For that reason, you may want to leave the lines below untouched
(commented) and instead use CHANGE MASTER TO (see above)
required unique id between 2 and 2^32 - 1
(and different from the master)
defaults to 2 if master-host is set
but will not function as a slave if omitted
server-id = 2
The replication master for this slave - required
The username the slave will use for authentication when connecting
to the master - required
The password the slave will authenticate with when connecting to
the master - required
The port the master is listening on.
optional - defaults to 3306
binary logging - not required for slaves, but recommended
Uncomment the following if you are using InnoDB tables
innodb_data_home_dir = /var/lib/mysql
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /var/lib/mysql
You can set .._buffer_pool_size up to 50 - 80 %
of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 256M
innodb_additional_mem_pool_size = 20M
Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 64M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
max_allowed_packet = 16M
Remove the next comment character if you are not familiar with SQL
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
Thanks in advance!