[ZBX-5876] Used query for history suboptimal and slow Created: 2012 Nov 20 Updated: 2017 May 30 Resolved: 2013 Jan 24 |
|
Status: | Closed |
Project: | ZABBIX BUGS AND ISSUES |
Component/s: | Server (S) |
Affects Version/s: | 2.0.3 |
Fix Version/s: | None |
Type: | Incident report | Priority: | Major |
Reporter: | Frank | Assignee: | Unassigned |
Resolution: | Cannot Reproduce | Votes: | 1 |
Labels: | performance, sql | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified |
Description |
It appears that the used query: is extremely slow. Its hitting the MySQL "slow query" limit (it takes 80+ seconds to execute) and causing our Zabbix server to have a high load and become generally unresponsive. Its probably a good idea to update this query in Zabbix by-default? |
Comments |
Comment by Alexei Vladishev [ 2012 Nov 21 ] | ||||||||||||||||||||
Are you sure you have correct index for table history_uint? Please check. Also execute: explain select value from history_uint where itemid=16617 and clock>1353413817 and clock<=1353417417 order by clock desc limit 2 and post result here. BTW The optimization is absolutely wrong. | ||||||||||||||||||||
Comment by Frank [ 2012 Nov 21 ] | ||||||||||||||||||||
The table has an index/key: KEY `history_uint_1` (`itemid`,`clock`) Explain select returns:
1 row in set (0.05 sec) | ||||||||||||||||||||
Comment by Frank [ 2012 Nov 21 ] | ||||||||||||||||||||
For the record, our history_uint table is quite big and contains 25179305 entries. | ||||||||||||||||||||
Comment by Alexei Vladishev [ 2012 Nov 22 ] | ||||||||||||||||||||
The query cannot take more than 1-2 seconds to execute unless the table is locked or IO is very saturated. Try to execute it from command line to see what I mean. The query is absolutely perfect. | ||||||||||||||||||||
Comment by Frank [ 2012 Nov 22 ] | ||||||||||||||||||||
First run: Second run: Third run: Fourth run: The MySQL data files run from an SSD so it should be all nice & fast. Table structure: | ||||||||||||||||||||
Comment by Lucian Atody [ 2012 Nov 26 ] | ||||||||||||||||||||
With the LogSlowQueries=3000 active in zabbix_server.conf we had 16248 slow query reports during a 15 hours period. That also makes mysqld use ~ 700% CPU as seen in atop history. The server uses Intel Core i7 @ 2.67GHz with 8GB RAM. Want to remind you that the mysql database is on SSD. The patched version of zabbix_server doesn't show any slow queries and works like a charm! From unpatched zabbix_server log: Size of zabbix database: === | ||||||||||||||||||||
Comment by Alexey Pustovalov [ 2012 Dec 02 ] | ||||||||||||||||||||
You have some problems with your database: mysql> select value from history_uint where itemid=7755304 and clock>unix_timestamp(now() - INTERVAL 2 DAY) and clock<=unix_timestamp(now()) order by clock desc limit 2 ; +-------+ | value | +-------+ | 0 | | 0 | +-------+ 2 rows in set (0.00 sec) mysql> explain select value from history_uint where itemid=7755304 and clock>unix_timestamp(now() - INTERVAL 2 DAY) and clock<=unix_timestamp(now()) order by clock desc limit 2 ; +----+-------------+--------------+-------+----------------+----------------+---------+------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+--------------+-------+----------------+----------------+---------+------+------+-------------+ | 1 | SIMPLE | history_uint | range | history_uint_1 | history_uint_1 | 12 | NULL | 126 | Using where | +----+-------------+--------------+-------+----------------+----------------+---------+------+------+-------------+ 1 row in set (0.01 sec) mysql> select table_rows from tables where table_name = 'history_uint'; +------------+ | table_rows | +------------+ | 626679856 | +------------+ 1 row in set (0.02 sec) Please check MySQL configuration. Your suggested query maybe not work on other supported by Zabbix databases. | ||||||||||||||||||||
Comment by Alexei Vladishev [ 2012 Dec 23 ] | ||||||||||||||||||||
Any news on this issue? | ||||||||||||||||||||
Comment by Lucian Atody [ 2013 Jan 23 ] | ||||||||||||||||||||
After upgrading the memory to 24GB and tweaking some mysql options we got it running smoothly. Thanks! | ||||||||||||||||||||
Comment by Alexei Vladishev [ 2013 Jan 24 ] | ||||||||||||||||||||
Thanks, I'm closing it then. |