webhostnix

Registered
Jul 8, 2012
4
0
51
cPanel Access Level
Root Administrator
Hi,

I am new member in this forum. I hope I can learn a lot from this forum.

I have server with RAM 64 GB with MySQL Version 5.1.63-cll x86_64. I need help how to optimize my.cnf

Here is my.cnf
[mysqld]
local-infile=0
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-locking
#skip-innodb
query_cache_limit=128M
query_cache_size=32K
join_buffer_size=2M
tmp_table_size=64M
max_heap_table_size=64M
query_cache_type=1K
max_user_connections=50
max_connections=50
interactive_timeout=10
wait_timeout=10
connect_timeout=10
thread_cache_size=16M
key_buffer=1024M
join_buffer=128M
max_allowed_packet=16M
table_cache=800000
record_buffer=1M
sort_buffer_size=2M
read_buffer_size=2M
max_connect_errors=10
thread_concurrency=8
myisam_sort_buffer_size=64M
server-id=1
key_buffer_size=2048M
table_definition_cache=100000
innodb_buffer_pool_size=20M
log-slow-queries = /var/lib/mysql/mysql-slow.log
long_query_time = 1

#[mysql.server]
#user=mysql
#basedir=/var/lib

[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/lib/mysql/mysql.pid
open_files_limit=300000

#[mysqldump]
#quick
#max_allowed_packet=16M

[mysql]
no-auto-rehash

[isamchk]
key_buffer=64M
sort_buffer=64M
read_buffer=16M
write_buffer=16M

[myisamchk]
key_buffer=64M
sort_buffer=64M
read_buffer=16M
write_buffer=16M

[mysqlhotcopy]
interactive-timeout
Here is output mysql tuner :
[email protected] [~]# ./mysqlmymonlite.sh mysqltuner

-------------------------------------------------------------
System MySQL monitoring stats
mysqlmymonlite.sh - 0.4.0 mysqlmymon.com
compiled by George Liu (eva2000) vbtechsupport.com
-------------------------------------------------------------

Report Generated:
Sat Jul 7 22:40:49 PDT 2012

-------------------------------------------------
mysqltuner output
-------------------------------------------------
mysqltuner.pl [found]

>> MySQLTuner 1.2.0 - Major Hayden <[email protected]>
>> Bug reports, feature requests, and downloads at http://mysqltuner.com/
>> Run with '--help' for additional options and output filtering
[OK] Logged in using credentials passed on the command line

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.63-cll
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 1017M (Tables: 2949)
[--] Data in InnoDB tables: 10M (Tables: 57)
[!!] Total fragmented tables: 144

-------- Security Recommendations -------------------------------------------
[OK] All database users have passwords assigned

-------- Performance Metrics -------------------------------------------------
[--] Up for: 34m 50s (325K q [155.929 qps], 4K conn, TX: 1B, RX: 54M)
[--] Reads / Writes: 97% / 3%
[--] Total buffers: 2.1G global + 132.5M per thread (50 max threads)
[OK] Maximum possible memory usage: 8.6G (13% of installed RAM)
[OK] Slow queries: 0% (1/325K)
[OK] Highest usage of available connections: 30% (15/50)
[OK] Key buffer size / total MyISAM indexes: 2.0G/391.2M
[OK] Key buffer hit rate: 99.9% (54M cached / 42K reads)
[!!] Query cache efficiency: 0.0% (0 cached / 300K selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (881 temp sorts / 90K sorts)
[!!] Joins performed without indexes: 199
[!!] Temporary tables created on disk: 48% (72K on disk / 148K total)
[OK] Thread cache hit rate: 99% (15 created / 4K connections)
[OK] Table cache hit rate: 96% (1K open / 1K opened)
[OK] Open file limit used: 0% (1K/300K)
[OK] Table locks acquired immediately: 99% (454K immediate / 454K locks)
[OK] InnoDB data size / buffer pool: 10.3M/20.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
Run OPTIMIZE TABLE to defragment tables for better performance
MySQL started within last 24 hours - recommendations may be inaccurate
Adjust your join queries to always utilize indexes
When making adjustments, make tmp_table_size/max_heap_table_size equal
Reduce your SELECT DISTINCT queries without LIMIT clauses
Variables to adjust:
query_cache_limit (> 128M, or use smaller result sets)
join_buffer_size (> 128.0M, or always use indexes with joins)
tmp_table_size (> 64M)
max_heap_table_size (> 64M)


Report Complete:
Sat Jul 7 22:40:50 PDT 2012
Here is output from tuning primer :
[email protected] [~]# ./tuning-primer.sh

-- MYSQL PERFORMANCE TUNING PRIMER --
- By: Matthew Montgomery -

MySQL Version 5.1.63-cll x86_64

Uptime = 0 days 0 hrs 35 min 54 sec
Avg. qps = 154
Total Questions = 332768
Threads Connected = 9

Warning: Server has not been running for at least 48hrs.
It may not be safe to use these recommendations

To find out more information on how each of these
runtime variables effects performance visit:
MySQL :: MySQL 5.1 Reference Manual :: 5.1.3 Server System Variables
Visit MySQL :: MySQL Enterprise Advisors
for info about MySQL's Enterprise Monitoring and Advisory Service

SLOW QUERIES
The slow query log is enabled.
Current long_query_time = 1.000000 sec.
You have 2 out of 332795 that take longer than 1.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
See MySQL :: MySQL 5.1 Reference Manual :: 7.5 Point-in-Time (Incremental) Recovery Using the Binary Log

WORKER THREADS
Current thread_cache_size = 16384
Current threads_cached = 8
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine

MAX CONNECTIONS
Current max_connections = 50
Current threads_connected = 11
Historic max_used_connections = 15
The number of used connections is 30% of the configured maximum.
Your max_connections variable seems to be fine.

INNODB STATUS
Current InnoDB index space = 1 M
Current InnoDB data space = 10 M
Current InnoDB buffer pool free = 46 %
Current innodb_buffer_pool_size = 20 M
Depending on how much space your innodb indexes take up it may be safe
to increase this value to up to 2 / 3 of total system memory

MEMORY USAGE
Max Memory Ever Allocated : 3.96 G
Configured Max Per-thread Buffers : 6.46 G
Configured Max Global Buffers : 2.02 G
Configured Max Memory Limit : 8.49 G
Physical Memory : 62.75 G
Max memory limit seem to be within acceptable norms

KEY BUFFER
Current MyISAM index space = 391 M
Current key_buffer_size = 2.00 G
Key cache miss rate is 1 : 1315
Key buffer free ratio = 79 %
Your key_buffer_size seems to be fine

QUERY CACHE
Query cache is enabled
Current query_cache_size = 32 K
Current query_cache_used = 32 K
Current query_cache_limit = 128 M
Current Query cache Memory fill ratio = 100.00 %
Current query_cache_min_res_unit = 4 K
MySQL won't cache query results that are larger than query_cache_limit in size

SORT OPERATIONS
Current sort_buffer_size = 2 M
Current read_rnd_buffer_size = 256 K
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 128.00 M
You have had 205 queries where a join could not use an index properly
join_buffer_size >= 4 M
This is not advised
You should enable "log-queries-not-using-indexes"
Then look for non indexed joins in the slow query log.

OPEN FILES LIMIT
Current open_files_limit = 300000 files
The open_files_limit should typically be set to at least 2x-3x
that of table_cache if you have heavy MyISAM usage.
Your open_files_limit value seems to be fine

TABLE CACHE
Current table_open_cache = 524288 tables
Current table_definition_cache = 100000 tables
You have a total of 3029 tables
You have 3148 open tables.
The table_cache value seems to be fine

TEMP TABLES
Current max_heap_table_size = 64 M
Current tmp_table_size = 64 M
Of 77112 temp tables, 48% were created on disk
Perhaps you should increase your tmp_table_size and/or max_heap_table_size
to reduce the number of disk-based temporary tables
Note! BLOB and TEXT columns are not allow in memory tables.
If you are using these columns raising these values might not impact your
ratio of on disk temp tables.

TABLE SCANS
Current read_buffer_size = 2 M
Current table scan ratio = 17 : 1
read_buffer_size seems to be fine

TABLE LOCKING
Current Lock Wait ratio = 1 : 27234
Your table locking seems to be fine
Thanks
 

srpurdy

Well-Known Member
Jun 1, 2011
101
0
66
cPanel Access Level
Root Administrator
Basically Primer tells you whats wrong.
These two.
Code:
QUERY CACHE
Query cache is enabled
Current query_cache_size = 32 K
Current query_cache_used = 32 K
Current query_cache_limit = 128 M
Current Query cache Memory fill ratio = 100.00 %
Current query_cache_min_res_unit = 4 K
MySQL won't cache query results that are larger than query_cache_limit in size

JOINS
Current join_buffer_size = 128.00 M
You have had 205 queries where a join could not use an index properly
join_buffer_size >= 4 M
This is not advised
You should enable "log-queries-not-using-indexes"
Then look for non indexed joins in the slow query log.
query_cache_size 32K is really small and basically all your data is bigger than 32K so you'll never use the query cache. I would make it 4M to start.

join_buffer_size of 128M is really crazy high. 256K is what you should set it to, and fix all your tables that don't have indexes. Having a higher join_buffer_size will actually be slower than fixing the tables. I understand it may be some work to fix all the tables, but it's the best option. I think some have also proven in very large sizes that's actually slower to have it higher than to force table scans.
 

webhostnix

Registered
Jul 8, 2012
4
0
51
cPanel Access Level
Root Administrator
Basically Primer tells you whats wrong.

query_cache_size 32K is really small and basically all your data is bigger than 32K so you'll never use the query cache. I would make it 4M to start.

join_buffer_size of 128M is really crazy high. 256K is what you should set it to, and fix all your tables that don't have indexes. Having a higher join_buffer_size will actually be slower than fixing the tables. I understand it may be some work to fix all the tables, but it's the best option. I think some have also proven in very large sizes that's actually slower to have it higher than to force table scans.
I have adjust query_cache_size 4M and join_buffer_size 256K

Btw, mean of fix all tables that don't have indexes are repair and optimize all tables server wide ?

Thanks for advise
 

srpurdy

Well-Known Member
Jun 1, 2011
101
0
66
cPanel Access Level
Root Administrator
Sorry I made an error.

what confused me is query_cache_limit = 128M which is also a strange value.

Change these
Code:
Current query_cache_size = 32 K
Current query_cache_limit = 128 M

to these
Code:
query_cache_size = 128M
query_cache_limit = 8M
Those are more like it. :)

And optimize is not what I mean.

Tables that link together have indexes so mysql knows how to find things when you run queries.

So if tables only have primary keys and no indexes joins without indexes will get created.

best simple example is a simple category + entries.
-> category_table
cat_id
category_name

-> entry_table
entry_id
cat_id
entry_name

in this case cat_id needs an index. on both tables, since the category_table will likely have a primary key for cat_id it's not a problem there, but on entry_table cat_id needs an index. This also goes for any queries that are using order_by, group_by and where clauses. Basically this comes down to proper database design. If you know what queries are being performed you can fix this.
 
Last edited:

webhostnix

Registered
Jul 8, 2012
4
0
51
cPanel Access Level
Root Administrator
I have adjusted

query_cache_size = 128M
query_cache_limit = 8M

and thanks for explanation about index join

Sorry I made an error.

what confused me is query_cache_limit = 128M which is also a strange value.

Change these
Code:
Current query_cache_size = 32 K
Current query_cache_limit = 128 M

to these
Code:
query_cache_size = 128M
query_cache_limit = 8M
Those are more like it. :)

And optimize is not what I mean.

Tables that link together have indexes so mysql knows how to find things when you run queries.

So if tables only have primary keys and no indexes joins without indexes will get created.

best simple example is a simple category + entries.
-> category_table
cat_id
category_name

-> entry_table
entry_id
cat_id
entry_name

in this case cat_id needs an index. on both tables, since the category_table will likely have a primary key for cat_id it's not a problem there, but on entry_table cat_id needs an index. This also goes for any queries that are using order_by, group_by and where clauses. Basically this comes down to proper database design. If you know what queries are being performed you can fix this.
 

lbeachmike

Well-Known Member
Dec 27, 2001
307
4
318
Long Beach, NY
cPanel Access Level
Root Administrator
One thing that's important to note here is that you ran tuning-primer after only 35 minutes of uptime and just a handful of queries, so your data is not going to be very useful for optimizing unless you run it for a bit longer. They recommend 48 hours as in the output your posted, though 24 hours usually provides plenty of data for this purpose -

Uptime = 0 days 0 hrs 35 min 54 sec
Avg. qps = 154
Total Questions = 332768
Threads Connected = 9

Warning: Server has not been running for at least 48hrs.
It may not be safe to use these recommendations
That being said, data from a brief run can at least help get some of the initial bugs dealt with - you can then run for longer periods to fine-tune.
 

webhostnix

Registered
Jul 8, 2012
4
0
51
cPanel Access Level
Root Administrator
Need new recommendation based on tuning-primer. Server has been running for over 48hrs.

[email protected] [~]# ./tuning-primer.sh

-- MYSQL PERFORMANCE TUNING PRIMER --
- By: Matthew Montgomery -

MySQL Version 5.1.63-cll x86_64

Uptime = 11 days 22 hrs 8 min 21 sec
Avg. qps = 254
Total Questions = 261665602
Threads Connected = 21

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:
MySQL :: MySQL 5.1 Reference Manual :: 5.1.3 Server System Variables
Visit MySQL :: MySQL Enterprise Advisors
for info about MySQL's Enterprise Monitoring and Advisory Service

SLOW QUERIES
The slow query log is enabled.
Current long_query_time = 1.000000 sec.
You have 111719 out of 261665630 that take longer than 1.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
See MySQL :: MySQL 5.1 Reference Manual :: 7.5 Point-in-Time (Incremental) Recovery Using the Binary Log

WORKER THREADS
Current thread_cache_size = 16384
Current threads_cached = 133
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine

MAX CONNECTIONS
Current max_connections = 150
Current threads_connected = 18
Historic max_used_connections = 147
The number of used connections is 98% of the configured maximum.
You should raise max_connections

INNODB STATUS
Current InnoDB index space = 4 M
Current InnoDB data space = 16 M
Current InnoDB buffer pool free = 0 %
Current innodb_buffer_pool_size = 20 M
Depending on how much space your innodb indexes take up it may be safe
to increase this value to up to 2 / 3 of total system memory

MEMORY USAGE
Max Memory Ever Allocated : 2.70 G
Configured Max Per-thread Buffers : 712 M
Configured Max Global Buffers : 2.02 G
Configured Max Memory Limit : 2.72 G
Physical Memory : 62.75 G
Max memory limit seem to be within acceptable norms

KEY BUFFER
Current MyISAM index space = 845 M
Current key_buffer_size = 2.00 G
Key cache miss rate is 1 : 16794
Key buffer free ratio = 66 %
Your key_buffer_size seems to be too high.
Perhaps you can use these resources elsewhere

QUERY CACHE
Query cache is enabled
Current query_cache_size = 4 M
Current query_cache_used = 16 K
Current query_cache_limit = 128 M
Current Query cache Memory fill ratio = .41 %
Current query_cache_min_res_unit = 4 K
Your query_cache_size seems to be too high.
Perhaps you can use these resources elsewhere
MySQL won't cache query results that are larger than query_cache_limit in size

SORT OPERATIONS
Current sort_buffer_size = 2 M
Current read_rnd_buffer_size = 256 K
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 260.00 K
You have had 158058 queries where a join could not use an index properly
You have had 1 joins without keys that check for key usage after each row
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 = 300000 files
The open_files_limit should typically be set to at least 2x-3x
that of table_cache if you have heavy MyISAM usage.
Your open_files_limit value seems to be fine

TABLE CACHE
Current table_open_cache = 524288 tables
Current table_definition_cache = 100000 tables
You have a total of 4805 tables
You have 10248 open tables.
The table_cache value seems to be fine

TEMP TABLES
Current max_heap_table_size = 64 M
Current tmp_table_size = 64 M
Of 49627282 temp tables, 47% were created on disk
Perhaps you should increase your tmp_table_size and/or max_heap_table_size
to reduce the number of disk-based temporary tables
Note! BLOB and TEXT columns are not allow in memory tables.
If you are using these columns raising these values might not impact your
ratio of on disk temp tables.

TABLE SCANS
Current read_buffer_size = 2 M
Current table scan ratio = 932 : 1
read_buffer_size seems to be fine

TABLE LOCKING
Current Lock Wait ratio = 1 : 4917
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'.

[email protected] [~]#
[mysqld]
local-infile=0
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-locking
#skip-innodb
query_cache_limit=128M
query_cache_size=4M
join_buffer_size=2M
tmp_table_size=64M
max_heap_table_size=64M
query_cache_type=1K
max_user_connections=150
max_connections=150
interactive_timeout=10
wait_timeout=10
connect_timeout=10
thread_cache_size=16M
key_buffer=1024M
join_buffer=256K
max_allowed_packet=16M
table_cache=800000
record_buffer=1M
sort_buffer_size=2M
read_buffer_size=2M
max_connect_errors=10
#thread_concurrency=8
myisam_sort_buffer_size=64M
server-id=1
key_buffer_size=2048M
table_definition_cache=100000
innodb_buffer_pool_size=20M
log-slow-queries = /var/lib/mysql/mysql-slow.log
long_query_time = 1

#[mysql.server]
#user=mysql
#basedir=/var/lib

[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/lib/mysql/mysql.pid
open_files_limit=300000

#[mysqldump]
#quick
#max_allowed_packet=16M

[mysql]
no-auto-rehash

[isamchk]
key_buffer=64M
sort_buffer=64M
read_buffer=16M
write_buffer=16M

[myisamchk]
key_buffer=64M
sort_buffer=64M
read_buffer=16M
write_buffer=16M

[mysqlhotcopy]
interactive-timeout
Thanks