Not the answer you need?
Register and ask your own question!

Very slow database response. I suspect InnoDB .

AbadonAbadon EntrantCurrent User Role Beginner
Hello,

I have two database servers with almost the same hardware and software configurations. The load of the servers is almost equal. The problem is that the first server works as snail compared with the second server.

For example If I run this query on the problematic server:
mysql> SELECT table_schema "Database Name", SUM(data_length+index_length)/1024/1024 "Database Size (MB)"  FROM information_schema.TABLES GROUP BY table_schema;

Before to see the result like this:
+----------------------------+--------------------+
| Database Name              | Database Size (MB) |
+----------------------------+--------------------+
| activtra_b2fx              |       260.60385895 |
| activtra_coper             |         0.06334019 |
................................................................................
| ziwitrad_wp99              |         4.09765244 |
+----------------------------+--------------------+
127 rows in set (34.59 sec)

mysql> 


I need to wait between 5 and 35 seconds. I don't know why sometimes the server returning the response for 5 seconds and why other time I need to wait more than 30 seconds.

The same query, but executed on the second server returning response with 93 rows for less than 1 second. Usually the responses are returned between 0.1 and 0.3 seconds.

As you can see the difference is colossal and I don't know why?

Before to execute the above query on problematic server I checked the load and everything look good. Below you can see the check results:

mysql> show processlist;
+--------+-----------+-----------+-----------+---------+------+-------+------------------+-----------+---------------+-----------+
| Id     | User      | Host      | db        | Command | Time | State | Info             | Rows_sent | Rows_examined | Rows_read |
+--------+-----------+-----------+-----------+---------+------+-------+------------------+-----------+---------------+-----------+
| 103183 | eximstats | localhost | eximstats | Sleep   |   38 |       | NULL             |         0 |             0 |         0 |
| 103327 | root      | localhost | NULL      | Query   |    0 | NULL  | show processlist |         0 |             0 |         0 |
+--------+-----------+-----------+-----------+---------+------+-------+------------------+-----------+---------------+-----------+
2 rows in set (0.00 sec)

mysql> 
# top
top - 20:54:13 up 259 days,  9:16,  1 user,  load average: 0.50, 2.05, 2.16
Tasks: 309 total,   1 running, 307 sleeping,   0 stopped,   1 zombie
Cpu(s):  2.6%us,  0.6%sy,  0.0%ni, 96.6%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  12191156k total, 10825468k used,  1365688k free,  1277832k buffers
Swap:  5242872k total,   607648k used,  4635224k free,  5509472k cached
# ./tuning-primer.sh 
 
        -- MYSQL PERFORMANCE TUNING PRIMER --
             - By: Matthew Montgomery -

MySQL Version 5.5.45-37.4-log x86_64

Uptime = 2 days 2 hrs 56 min 29 sec
Avg. qps = 11
Total Questions = 2042286
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.5/en/server-system-variables.html
Visit http://www.mysql.com/products/enterprise/advisors.html
for info about MySQL's Enterprise Monitoring and Advisory Service

SLOW QUERIES
The slow query log is enabled.
Current long_query_time = 10.000000 sec.
You have 352 out of 2042307 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
See http://dev.mysql.com/doc/refman/5.5/en/point-in-time-recovery.html

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

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

INNODB STATUS

So far I'm seeing the above output in a split second. Then I wait additional 20-30 seconds before to continue with the below output of the command:
Current InnoDB index space = 324 M
Current InnoDB data space = 999 M
Current InnoDB buffer pool free = 0 %
Current innodb_buffer_pool_size = 512 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.26 G
Configured Max Per-thread Buffers : 3.90 G
Configured Max Global Buffers : 2.64 G
Configured Max Memory Limit : 6.54 G
Physical Memory : 11.62 G
Max memory limit seem to be within acceptable norms

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

QUERY CACHE
Query cache is enabled
Current query_cache_size = 128 M
Current query_cache_used = 125 M
Current query_cache_limit = 16 M
Current Query cache Memory fill ratio = 98.16 %
Current query_cache_min_res_unit = 4 K
However, 2150 queries have been removed from the query cache due to lack of memory
Perhaps you should raise query_cache_size
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 = 16.00 M
You have had 4748 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 = 32930 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 = 16384 tables
Current table_definition_cache = 20480 tables
You have a total of 6569 tables
You have 12470 open tables.
The table_cache value seems to be fine

TEMP TABLES
Current max_heap_table_size = 768 M
Current tmp_table_size = 768 M
Of 206436 temp tables, 30% 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 = 8 M
Current table scan ratio = 1249 : 1
read_buffer_size seems to be fine

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

On the good working server the tuning-primer.sh have need only 2-3 seconds to complete with all output without any delays in InnoDB part.

This is my /etc/my.cnf on problematic server:
[mysqld]
socket=/tmp/mysql.sock
#set-variable = max_connections=500
max_user_connections=16
log_slow_queries=/var/log/mysql-slow.log
#log-slow-queries
#safe-show-database
join_buffer_size=16M
max_allowed_packet=268435456
open_files_limit=32768
# Skip reverse DNS lookup of clients
skip-name-resolve
query_cache_size=128M
query_cache_limit=16M
key_buffer=2048M
table_cache=16384
table_definition_cache=20480
tmp_table_size=768M
max_heap_table_size=768M
read_buffer_size=8M
innodb_buffer_pool_size=512M
innodb_file_per_table=1
thread_cache_size=8
low_priority_updates=1
[client]
socket=/tmp/mysql.sock

Do you have any ideas on what could be the reason for this delay?
Sign In or Register to comment.

MySQL, InnoDB, MariaDB and MongoDB are trademarks of their respective owners.
Copyright ©2005 - 2020 Percona LLC. All rights reserved.