This is killing me. Please help me. My production server freeze once a week. There were queries that lock rows, and block other queries, consuming 100% CPU all the time. I need to manually kill those frozen queries before the server coming back working.
I have a system that will show the highest CTR banners on the website based on any given slot. This is my table structure.
CREATE TABLE IF NOT EXISTS `banners` (
`banner_id` int(5) NOT NULL AUTO_INCREMENT,
`banner_slot` varchar(15) NOT NULL,
`banner_img_path` varchar(200) NOT NULL,
`banner_link` varchar(200) NOT NULL,
`banner_views` int(8) NOT NULL DEFAULT '1',
`banner_clicks` int(8) NOT NULL DEFAULT '0',
`banner_ctr` double(5,3) NOT NULL DEFAULT '0',
PRIMARY KEY (`banner_id`),
KEY `banner_slot` (`banner_slot`,`banner_views`,`banner_ctr`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4231;
This runs on production server (CentOS6.3/MySQL 5.5.28/Apache2/Quad core CPU/8GB RAM). Pretty old, I know.
The server also runs a few more wordpress sites, which I already use the WP super cache plugin. There are some queries from wordpress appears in slow query log file, but they are all under 5 seconds.
Recently, I've got approx 20K page views daily. With about 2-3K UIPs at peak hours (all domains combined).
This is my my.cnf settings:
innodb_file_per_table=1
open_files_limit=10192
skip-external-locking
key_buffer_size=800M
max_allowed_packet=100M
table_open_cache=512
table_cache=500
sort_buffer_size=2M
read_buffer_size=4M
read_rnd_buffer_size=8M
thread_cache_size=4
query_cache_type=0
query_cache_size=4M
join_buffer_size=8M
tmp_table_size=512M
max_heap_table_size=256M
max_connections=200
This is my slow query log file. You'll see that there is high lock time on such a basic query here.
# Query_time: 84.554967 Lock_time: 37.070954 Rows_sent: 0 Rows_examined: 1
use db_name;
SET timestamp=1537010708;
UPDATE banners SET banner_views=banner_views+1 WHERE banner_id=6;
# Query_time: 84.614748 Lock_time: 37.130587 Rows_sent: 0 Rows_examined: 1
use db_name;
SET timestamp=1537010708;
UPDATE banners SET banner_views=banner_views+1 WHERE banner_id=60;
# Query_time: 54.288041 Lock_time: 0.000018 Rows_sent: 0 Rows_examined: 1
SET timestamp=1537010708;
UPDATE banners SET banner_views=banner_views+1 WHERE banner_id=884;
# Query_time: 104.154232 Lock_time: 34.661097 Rows_sent: 0 Rows_examined: 1
use db_name;
SET timestamp=1537010744;
UPDATE banners SET banner_views=banner_views+1 WHERE banner_id=60;
# Query_time: 107.847145 Lock_time: 38.354068 Rows_sent: 0 Rows_examined: 1
SET timestamp=1537010744;
UPDATE banners SET banner_views=banner_views+1 WHERE banner_id=6;
# Query_time: 81.974780 Lock_time: 26.446288 Rows_sent: 0 Rows_examined: 1
SET timestamp=1537010771;
UPDATE banners SET banner_views=banner_views+1 WHERE banner_id=6;
# Query_time: 102.331612 Lock_time: 46.507686 Rows_sent: 0 Rows_examined: 1
use db_name;
SET timestamp=1537010772;
UPDATE banners SET banner_views=banner_views+1 WHERE banner_id=60;
# Query_time: 81.808158 Lock_time: 36.196089 Rows_sent: 0 Rows_examined: 1
SET timestamp=1537010772;
UPDATE banners SET banner_views=banner_views+1 WHERE banner_id=7;
I've gone through mysql-tuner.pl and almost all settings are green based on the recommendations.
I'm also EXPLAINING all the SELECT queries, and those are all using indexes. I couldn't EXPLAIN on any other queries since I'm running on MySQL 5.5.
Any recommendations on my issue? Thanks in advance! Any help are appreciated!