Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
My server very slow and the is very loaded. How can I fix this problem? My server specialities and loaded softwares which are below. And sometimes there is "mysql connect failed", "Lost connection to MySQL server during query" errors. Thanks for kinds...
I'm thinking there's a bottleneck with hard drive O/I since the RAM and CPU aren't 100%, so it's not too much for the CPU, and it's not having to swap out.
How are the hard drive's configured? RAID? If so, Hardware or Software? What level?
I've found SATA to be very bad in servers, although I haven't tried SATAII. Are you getting any "random" lockups / freezes etc?
I'm thinking there's a bottleneck with hard drive O/I since the RAM and CPU aren't 100%, so it's not too much for the CPU, and it's not having to swap out.
How are the hard drive's configured? RAID? If so, Hardware or Software? What level?
I've found SATA to be very bad in servers, although I haven't tried SATAII. Are you getting any "random" lockups / freezes etc?
Hi. Thanks for your reply. There was no freezes. My server didn't locked. Only when it have been %100 (cpu or ram) mysql is get problem and giving the problem which is my said above... I don't know hardware much How can I get info about your asked question with One or sevaral commands ? Hardware infos, SATA, RAID configirations? (on shell) thanks.
For troubleshooting Mysql Problem :
1. Add following line to /etc/my.cnf for generating slow query log.
[mysqld]
...
log-slow-queries=/var/log/mysql-slow.log
...
2. Download script for parsing slow query log.
3. Check time in executing queries and optimize slow queries.
For Getting Hardware info :
1. Through Plesk 8.1.1 Web interface, Go to Server in left panel.
Click on System statistics under System Section.
2. For Getting Hardware info and system info, you can try following commands.
top, sar, vmstat, uptime, hdparam etc. Check manual of each command for understanding its output.
For troubleshooting Mysql Problem :
1. Add following line to /etc/my.cnf for generating slow query log.
[mysqld]
...
log-slow-queries=/var/log/mysql-slow.log
...
2. Download script for parsing slow query log.
3. Check time in executing queries and optimize slow queries.
For Getting Hardware info :
1. Through Plesk 8.1.1 Web interface, Go to Server in left panel.
Click on System statistics under System Section.
2. For Getting Hardware info and system info, you can try following commands.
top, sar, vmstat, uptime, hdparam etc. Check manual of each command for understanding its output.
Update us with your findings.
Million thanks for reply.
ok. I added this line in my.cnf
log-slow-queries=/var/log/mysql-slow.log
after
cd /usr/bin
tuning-primer.sh
output:
PHP Code:
[root@lavinya bin]# tuning-primer.sh
-- MYSQL PERFORMANCE TUNING PRIMER -- - By: Matthew Montgomery -
MySQL Version 5.0.41 i686
Uptime = 2 days 18 hrs 46 min 55 sec Avg. qps = 92 Total Questions = 22295630 Threads Connected = 2
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: http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html
SLOW QUERIES Current long_query_time = 10 sec. You have 59 out of 22295676 that take longer than 10 sec. to complete The slow query log is NOT enabled. Your long_query_time may be too high, I typically set this under 5 sec.
WORKER THREADS Current thread_cache_size = 8 Current threads_cached = 5 Current threads_per_sec = 0 Historic threads_per_sec = 0 Your thread_cache_size is fine
MAX CONNECTIONS Current max_connections = 500 Current threads_connected = 2 Historic max_used_connections = 182 The number of used connections is 36% of the configured maximum. Your max_connections variable seems to be fine.
MEMORY USAGE Max Memory Ever Allocated : 1 G Configured Max Per-thread Buffers : 3 G Configured Max Global Buffers : 46 M Configured Max Memory Limit : 3 G Total System Memory : 3.96 G
Max memory limit exceeds 85% of total system memory
KEY BUFFER Current MyISAM index space = 34 M Current key_buffer_size = 32 M Key cache miss rate is 1 : 48684 Key buffer fill ratio = 26.00 % 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 = 679 K Current query_cach_limit = 1 M Current Query cache fill ratio = 16.59 % Your query_cache_size seems to be too high. Perhaps you can use these resources elsewhere MySQL wont cache query results that are larger than query_cache_limit in size
SORT OPERATIONS Current sort_buffer_size = 2 M Current record/read_rnd_buffer_size = 1 M Sort buffer seems to be fine
JOINS Current join_buffer_size = 1.00 M You have had 12415 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 = 2500 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_cache value = 256 tables You have a total of 636 tables You have 256 open tables. Current table_cache hit rate is 0%, while 100% of your table cache is in use You should probably increase your table_cache
TEMP TABLES Current max_heap_table_size = 16 M Current tmp_table_size = 32 M Of 1934081 temp tables, 4% were created on disk Effective in-memory tmp_table_size is limited to max_heap_table_size. Created disk tmp tables ratio seems fine
TABLE SCANS Current read_buffer_size = 1 M Current table scan ratio = 404 : 1 read_buffer_size seems to be fine
TABLE LOCKING Current Lock Wait ratio = 1 : 65 You may benefit from selective use of InnoDB. If you have long running SELECTs against MyISAM tables and perform frequent updates consider setting 'low_priority_updates=1' If you have a high concurrentcy of inserts on Dynamic row-length tables consider setting 'concurrent_insert=2'.
[root@lavinya bin]# /etc/init.d/psa stopall /usr/local/psa/admin/bin/httpsdctl stop: httpd stopped Stopping Plesk: [ OK ] Stopping named: [ OK ] Stopping MySQL: [ OK ] Stopping : Stopping Courier-IMAP server: Stopping imap [ OK ] Stopping imap-ssl [ OK ] Stopping pop3 [ OK ] Stopping pop3-ssl [ OK ]
Shutting down psa-spamassassin service: [ OK ] Stopping httpd: [ OK ] [root@lavinya bin]# /etc/init.d/psa start Starting named: [ OK ] Starting MySQL: [ OK ] Starting qmail: [ OK ] Starting Courier-IMAP server: Starting imapd [ OK ] Starting imap-ssl [ OK ] Starting pop3 [ OK ] Starting pop3-ssl [ OK ]
Starting psa-spamassassin service: [ OK ] Processing config directory: /usr/local/psa/admin/conf/httpsd.*.include /usr/local/psa/admin/bin/httpsdctl start: httpd started Starting Plesk: [ OK ] [root@lavinya bin]#
[root@lavinya bin]# vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
3 0 128 301880 124720 865768 0 0 4 123 5 6 40 7 54 0
[root@lavinya bin]#
I asked you to download script for parsing slow query log, which is different from tuning-primer.sh. It will parse your mysql slow log file and provide you stats like which query, table, user etc. took how much time to execute. So, try to optimize those slow queries.
#######################################################################
Check for all parameters which are printed in red on http://www.lavinya.net/tuningprimer.html like
Code:
MAX CONNECTIONS
Current max_connections = 500
Current threads_connected = 1
Historic max_used_connections = 9
The number of used connections is 1% of the configured maximum.
You are using less than 10% of your configured max_connections.
Lowering max_connections could help to avoid an over-allocation of memory
See "MEMORY USAGE" section to make sure you are not over-allocating
Reduce Current max_connections = 500 to Current max_connections = 300
Optimize them according to your need.
And run tuning-primer.sh again to check if everything is working fine or not.
but I can’t understand this code:
I don’t know. How to set values, example?
NOTE: Red value
Code:
[root@lavinya bin]# tuning-primer.sh
-- MYSQL PERFORMANCE TUNING PRIMER --
- By: Matthew Montgomery -
MySQL Version 5.0.41-log i686
Uptime = 3 days 4 hrs 34 min 17 sec
Avg. qps = 92
Total Questions = 25406284
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:
http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html
SLOW QUERIES
Current long_query_time = 5 sec.
You have 115 out of 25406302 that take longer than 5 sec. to complete
The slow query log is enabled.
Your long_query_time seems to be fine
WORKER THREADS
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
MAX CONNECTIONS
Current max_connections = 500
Current threads_connected = 2
Historic max_used_connections = 110
The number of used connections is 22% of the configured maximum.
Your max_connections variable seems to be fine.
MEMORY USAGE
Max Memory Ever Allocated : 835 M
Configured Max Per-thread Buffers : 3 G
Configured Max Global Buffers : 46 M
Configured Max Memory Limit : 3 G
Total System Memory : 3.96 G
Max memory limit exceeds 85% of total system memory
KEY BUFFER
Current MyISAM index space = 35 M
Current key_buffer_size = 32 M
Key cache miss rate is 1 : 73658
Key buffer fill ratio = 34.00 %
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 = 1 M
Current query_cach_limit = 1 M
Current Query cache fill ratio = 29.83 %
MySQL won't cache query results that are larger than query_cache_limit in size
SORT OPERATIONS
Current sort_buffer_size = 2 M
Current record/read_rnd_buffer_size = 1 M
Sort buffer seems to be fine
JOINS
Current join_buffer_size = 1.00 M
You have had 14127 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 = 2500 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_cache value = 256 tables
You have a total of 636 tables
You have 256 open tables.
Current table_cache hit rate is 1%, while 100% of your table cache is in use
You should probably increase your table_cache
TEMP TABLES
Current max_heap_table_size = 16 M
Current tmp_table_size = 32 M
Of 2271787 temp tables, 3% were created on disk
Effective in-memory tmp_table_size is limited to max_heap_table_size.
Created disk tmp tables ratio seems fine
TABLE SCANS
Current read_buffer_size = 1 M
Current table scan ratio = 28 : 1
read_buffer_size seems to be fine
TABLE LOCKING
Current Lock Wait ratio = 1 : 112
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 concurrentcy of inserts on Dynamic row-length tables
consider setting 'concurrent_insert=2'.
[root@lavinya bin]#
You can modify these variables by adding them to /etc/my.cnf.
Code:
[mysqld]
key_buffer_size=24M [Reduce it from 32M to 24M]
table_cache=512 [Increase it from 256 tables to 512 tables]
concurrent_insert=2 [Please read its description before setting it]
...
After that run tuning-primer.sh again. If everything looks good, monitor your server load for a time period. Also check if I/O is taking too much time. Run the script again after a week before restarting server, so that you have better statistics.
[mysqld]
key_buffer_size=24M [Reduce it from 32M to 24M]
table_cache=512 [Increase it from 256 tables to 512 tables]
concurrent_insert=2 [Please read its description before setting it]
...
after run tuning-primer.sh.
same problem.
red value:
Code:
KEY BUFFER
Current MyISAM index space = 35 M
Current key_buffer_size = 24 M
Key cache miss rate is 1 : 6176
Key buffer fill ratio = 17.00 %
Your key_buffer_size seems to be too high.
Perhaps you can use these resources elsewhere
TABLE CACHE
Current table_cache value = 512 tables
You have a total of 636 tables
You have 512 open tables.
Current table_cache hit rate is 26%, while 100% of your table cache is in use
You should probably increase your table_cache
TABLE LOCKING
Current Lock Wait ratio = 1 : 225
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'
Follow the instructions provided in red. If you have long running SELECT's against MyISAM tables and perform
frequent updates consider setting 'low_priority_updates=1'
Reduce key_buffer_size and increase table_cache.
Code:
[mysqld]
key_buffer_size=16M [Reduce it from 24M to 16M]
table_cache=800 [Increase it from 512 tables to 800 tables]
concurrent_insert=2 [Please read its description before setting it]
...
Tell us if you find any improvement in server performance or not.
Hello again. After 13 days running script.
How to optimization? Thanks.
Code:
[root@lavinya bin]# tuning-primer.sh
-- MYSQL PERFORMANCE TUNING PRIMER --
- By: Matthew Montgomery -
MySQL Version 5.0.41-log i686
Uptime = 13 days 1 hrs 42 min 11 sec
Avg. qps = 95
Total Questions = 108336450
Threads Connected = 2
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:
http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html
SLOW QUERIES
Current long_query_time = 5 sec.
You have 2877 out of 108336722 that take longer than 5 sec. to complete
The slow query log is enabled.
Your long_query_time seems to be fine
WORKER THREADS
ERROR 2013 (HY000): Lost connection to MySQL server at 'sending authentication information', system error: 32
Current thread_cache_size = 8
Current threads_cached = 4
Current threads_per_sec = -242613
Historic threads_per_sec = 0
Your thread_cache_size is fine
MAX CONNECTIONS
Current max_connections = 500
Current threads_connected = 3
Historic max_used_connections = 241
The number of used connections is 48% of the configured maximum.
Your max_connections variable seems to be fine.
MEMORY USAGE
Max Memory Ever Allocated : 1 G
Configured Max Per-thread Buffers : 3 G
Configured Max Global Buffers : 30 M
Configured Max Memory Limit : 3 G
Total System Memory : 3.96 G
Max memory limit exceeds 85% of total system memory
KEY BUFFER
Current MyISAM index space = 38 M
Current key_buffer_size = 16 M
Key cache miss rate is 1 : 817117
Key buffer fill ratio = 100.00 %
You could increase key_buffer_size
It is safe to raise this up to 1/4 of total system memory;
assuming this is a dedicated database server.
QUERY CACHE
Query cache is enabled
Current query_cache_size = 4 M
Current query_cache_used = 1 M
Current query_cach_limit = 1 M
Current Query cache fill ratio = 45.23 %
MySQL won't cache query results that are larger than query_cache_limit in size
SORT OPERATIONS
Current sort_buffer_size = 2 M
Current record/read_rnd_buffer_size = 1 M
Sort buffer seems to be fine
JOINS
Current join_buffer_size = 1.00 M
You have had 60292 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 = 3510 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_cache value = 1500 tables
You have a total of 636 tables
You have 1500 open tables.
Current table_cache hit rate is 7%, while 100% of your table cache is in use
You should probably increase your table_cache
TEMP TABLES
Current max_heap_table_size = 16 M
Current tmp_table_size = 32 M
Of 9541878 temp tables, 4% were created on disk
Effective in-memory tmp_table_size is limited to max_heap_table_size.
Created disk tmp tables ratio seems fine
TABLE SCANS
Current read_buffer_size = 1 M
Current table scan ratio = 33 : 1
read_buffer_size seems to be fine
TABLE LOCKING
Current Lock Wait ratio = 1 : 42
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'
[root@lavinya bin]#
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.