高Mysql负载 - CPU 360%

时间:2010-11-15 11:22:14

标签: mysql sorting load locked

我的mysql CPU使用率很高,在服务器Intel(R)Xeon(R)CPU E5520 @ 2.27GHz 16核心处理器和16 G.B ram运行在centos 5.4

服务器500-900的负载平均值,这实际上是HIGH NUMBERS

这里有一些信息可以帮助我们

mysql配置文件/etc/my.cnf

[mysqld]
local-infile=0
safe-show-database
skip-locking
skip-innodb
skip-networking
old_passwords
back_log = 50
skip-innodb
max_connections = 40000
key_buffer_size = 640M
myisam_sort_buffer_size = 256M
myisam_max_sort_file_size = 2048M
join_buffer_size = 3M
read_buffer_size = 3M
sort_buffer_size = 3M
table_cache = 8000
thread_cache_size = 1024
wait_timeout = 300
interactive_timeout = 600
connect_timeout = 10
tmp_table_size = 1024M
max_heap_table_size = 1024M
max_allowed_packet = 128M
net_buffer_length = 16384
max_connect_errors = 100000
long_query_time=0
thread_concurrency = 32
concurrent_insert = 2
table_lock_wait_timeout = 30
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 16M
query_cache_limit = 4M
query_cache_size = 128M
query_cache_type = 1
query_prealloc_size = 262144
query_alloc_block_size = 65536
range_alloc_block_size = 4096
transaction_alloc_block_size = 8192
transaction_prealloc_size = 4096
default-storage-engine = MyISAM
max_write_lock_count = 8
tmpdir=/mysqltmp
set-variable=long_query_time=1
log-slow-queries=/var/log/mysql/log-slow-queries.log

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
nice = -10
open_files_limit = 8192

[mysqldump]
quick
max_allowed_packet = 128M

[myisamchk]
key_buffer_size = 640M
sort_buffer_size = 64M
read_buffer_size = 16M
write_buffer_size = 16M

[mysqlhotcopy]
interactive-timeout

===============注意我删除了一些查询,因为我不能在这里发布超过30000个字符=============== ======================

    SHOW FULL PROCESSLIST;
    393786 site_dtl localhost site_dtl Query 1 Locked UPDATE dle_post SET news_read = news_read +1 WHERE id = '3657'
    402437 root localhost None Sleep 496 --- ---
    409374 root localhost None Sleep 180 --- ---
    411150 tgofmovi_home localhost tgofmovi_home Sleep 40 --- ---
    411230 tgofmovi_home localhost tgofmovi_home Sleep 36 --- ---
    411401 site_dtl localhost site_dtl Query 1 Locked SELECT *
    FROM dle_post
    WHERE approve = '1'
    AND category
    IN ( 80 )
    ORDER BY date DESC
    LIMIT 0 , 10
    411410 site_dtl localhost site_dtl Query 0 Locked SELECT *
    FROM dle_post
    WHERE approve = '1'
    AND category
    IN ( 80 )
    ORDER BY date DESC
    LIMIT 0 , 10
    411430 site_dtl localhost site_dtl Query 0 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(1,2,7,6,8) AND id NOT IN (0) AND date >= '
    411433 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
    411439 site_dtl localhost site_dtl Query 0 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
    411443 site_dtl localhost site_dtl Query 0 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
    411444 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(91) AND id NOT IN (0) AND date >= '2010-11
    411490 site_dtl localhost site_dtl Query 2 Sorting result SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
    411491 site_dtl localhost site_dtl Query 2 Sorting result SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
    411498 site_dtl localhost site_dtl Query 0 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
    411509 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(91) AND id NOT IN (0) AND date >= '2010-11
    411511 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
    411512 site_dtl localhost site_dtl Query 0 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
    411513 site_dtl localhost site_dtl Query 0 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
    411514 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
    411515 site_dtl localhost site_dtl Query 0 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
    411526 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
    411527 site_dtl localhost site_dtl Query 0 Locked SELECT * FROM dle_post WHERE 
    411541 site_dtl localhost site_dtl Query 2 Sorting result SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
    411543 site_dtl localhost site_dtl Query 0 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(1,2,7,6,8) AND id NOT IN (0) AND date >= '
    411544 site_dtl localhost site_dtl Query 0 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(1,2,7,6,8) AND id NOT IN (0) AND date >= '
    411545 site_dtl localhost site_dtl Query 2 Sorting result SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
    411547 site_dtl localhost site_dtl Query 0 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(1,2,7,6,8) AND id NOT IN (0) AND date >= '
    411548 site_dtl localhost site_dtl Query 2 Sorting result SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
    411549 site_dtl localhost site_dtl Query 2 Sorting result SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
    411565 site_dtl localhost site_dtl Query 2 Sorting result SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
approve='1' AND category IN(91) AND id NOT IN (0) AND date >= '2010-11
    411618 site_dtl localhost site_dtl Query 0 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(91) AND id NOT IN (0) AND date >= '2010-11
    411619 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(80) ORDER BY date DESC LIMIT 0,10
    411620 site_dtl localhost site_dtl Query 0 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(91) AND id NOT IN (0) AND date >= '2010-11
    411621 site_dtl localhost site_dtl Query 0 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(91) AND id NOT IN (0) AND date >= '2010-11
    411622 site_dtl localhost site_dtl Query 0 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(91) AND id NOT IN (0) AND date >= '2010-11
    411623 site_dtl localhost site_dtl Query 0 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(91) AND id NOT IN (0) AND date >= '2010-11
    411624 site_dtl localhost site_dtl Query 0 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(91) AND id NOT IN (0) AND date >= '2010-11
    411625 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(91) AND id NOT IN (0) AND date >= '2010-11
    411796 site_dtl localhost site_dtl Query 1 Copying to tmp table SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY RAND() LIM
    411797 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(37,43,54,55,56,60,61,62,63,64,69,70,71,46,5
    411798 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(37,43,54,55,56,60,61,62,63,64,69,70,71,46,5
    411800 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(65) AND id NOT IN (0) AND date >= '2010-11
    411801 site_dtl localhost site_dtl Query 1 Copying to tmp table SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY RAND() LIM
    411802 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(65) AND id NOT IN (0) AND date >= '2010-11
    411803 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(44,54,55,56,60,61,62,63,64,69,70,71) AND id
    411804 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411807 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(65) AND id NOT IN (0) AND date >= '2010-11
    411808 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(37) AND id NOT IN (0) AND date >= '2010-11
    411809 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(65) AND id NOT IN (0) AND date >= '2010-11
    411811 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(65) AND id NOT IN (0) AND date >= '2010-11
    411812 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(65) AND id NOT IN (0) AND date >= '2010-11
    411813 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(65) AND id NOT IN (0) AND date >= '2010-11
    411814 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(44,54,55,56,60,61,62,63,64,69,70,71) AND id
    411818 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(44,54,55,56,60,61,62,63,64,69,70,71) AND id
    411819 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411820 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(65) AND id NOT IN (0) AND date >= '2010-11
    411821 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(65) AND id NOT IN (0) AND date >= '2010-11
    411822 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(65) AND id NOT IN (0) AND date >= '2010-11
    411823 site_dtl localhost site_dtl Query 1 Copying to tmp table SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY RAND() LIM
    411825 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(44,54,55,56,60,61,62,63,64,69,70,71) AND id
    411826 site_dtl localhost site_dtl Query 1 Copying to tmp table SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY RAND() LIM
    411827 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(65) AND id NOT IN (0) AND date >= '2010-11
    411828 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(65) AND id NOT IN (0) AND date >= '2010-11
    411829 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(65) AND id NOT IN (0) AND date >= '2010-11
    411830 site_dtl localhost site_dtl Query 1 Copying to tmp table SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY RAND() LIM
    411831 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411833 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411834 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(48) AND id NOT IN (0) AND date >= '2010-11
    411836 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(44,54,55,56,60,61,62,63,64,69,70,71) AND id
    411837 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(44,54,55,56,60,61,62,63,64,69,70,71) AND id
    411838 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(44,54,55,56,60,61,62,63,64,69,70,71) AND id
    411841 site_dtl localhost site_dtl Query 1 Copying to tmp table SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY RAND() LIM
    411842 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(44,54,55,56,60,61,62,63,64,69,70,71) AND id
    411843 site_dtl localhost site_dtl Query 1 Copying to tmp table SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY RAND() LIM
    411845 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411855 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(37) AND id NOT IN (0) AND date >= '2010-11
    411856 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' AND date >= '2010-
    411857 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(37) AND id NOT IN (0) AND date >= '2010-11
    411858 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(37) AND id NOT IN (0) AND date >= '2010-11
    411859 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(37) AND id NOT IN (0) AND date >= '2010-11
    411860 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411861 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(37) AND id NOT IN (0) AND date >= '2010-11
    411862 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(37) AND id NOT IN (0) AND date >= '2010-11
    411863 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(37) AND id NOT IN (0) AND date >= '2010-11
    411864 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411865 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(37) AND id NOT IN (0) AND date >= '2010-11
    411866 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411867 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(37) AND id NOT IN (0) AND date >= '2010-11
    411868 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(37) AND id NOT IN (0) AND date >= '2010-11
    411869 site_dtl localhost site_dtl Query 2 Sorting result SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411870 site_dtl localhost site_dtl Query 1 Sending data SELECT COUNT(*) as count FROM dle_post WHERE category regexp '[[:<:]](81)[[:>:]]' AND approve AND da
    411871 site_dtl localhost site_dtl Query 2 Sorting result SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411872 site_dtl localhost site_dtl Query 2 Sorting result SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411873 site_dtl localhost site_dtl Query 1 Copying to tmp table SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY RAND() LIM
    411874 site_dtl localhost site_dtl Query 1 Copying to tmp table SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY RAND() LIM
    411875 site_dtl localhost site_dtl Query 1 Copying to tmp table SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY RAND() LIM
    411876 site_dtl localhost site_dtl Query 1 Copying to tmp table SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY RAND() LIM
    411877 site_dtl localhost site_dtl Query 1 Copying to tmp table SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY RAND() LIM
    411878 site_dtl localhost site_dtl Query 1 Copying to tmp table SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY RAND() LIM
    411879 site_dtl localhost site_dtl Query 1 Sending data SELECT COUNT(*) as count FROM dle_post WHERE category regexp '[[:<:]](44|80|81|54|55|60|61|62|63|64|
    411890 site_dtl localhost site_dtl Query 1 Sending data SELECT COUNT(*) as count FROM dle_post WHERE category regexp '[[:<:]](44|80|81|54|55|60|61|62|63|64|
    411891 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' AND date >= '2010-
    411892 site_dtl localhost site_dtl Query 1 Copying to tmp table SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY RAND() LIM
    411893 site_dtl localhost site_dtl Query 1 Copying to tmp table SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY RAND() LIM
    411894 site_dtl localhost site_dtl Query 1 Sending data SELECT COUNT(*) as count FROM dle_post WHERE category regexp '[[:<:]](44|80|81|54|55|60|61|62|63|64|
    411895 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(44,54,55,56,60,61,62,63,64,69,70,71) AND id
    411896 site_dtl localhost site_dtl Query 1 Sending data SELECT COUNT(*) as count FROM dle_post WHERE category regexp '[[:<:]](36|37|43|44|80|81|54|55|60|61|
    411897 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(44,54,55,56,60,61,62,63,64,69,70,71) AND id
    411898 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(44,54,55,56,60,61,62,63,64,69,70,71) AND id
    411899 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(44,54,55,56,60,61,62,63,64,69,70,71) AND id
    411900 site_dtl localhost site_dtl Query 1 Locked SELECT * FROM dle_post WHERE approve='1' AND category IN(44,54,55,56,60,61,62,63,64,69,70,71) AND id
    411901 site_dtl localhost site_dtl Query 2 Sorting result SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411902 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411903 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411904 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411905 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411907 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411908 site_dtl localhost site_dtl Query 2 Sorting result SELECT id, autor, date, short_story, SUBSTRING(full_story, 1, 15) as full_story, xfields, title, cat
    411909 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411910 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411911 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411912 site_dtl localhost site_dtl Query 1 Locked SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411919 site_dtl localhost site_dtl Query 2 Sorting result SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411921 site_dtl localhost site_dtl Query 2 Sorting result SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411922 site_dtl localhost site_dtl Query 2 Sorting result SELECT id, title, date, alt_name, category, flag FROM dle_post WHERE approve='1' ORDER BY date DESC
    411950 root localhost mysql Query 0 --- SHOW PROCESSLIST

=============================================== =====

SHOW CREATE TABLE dle_post\G
*************************** 1. row ***************************
Table: dle_post
Create Table: CREATE TABLE `dle_post` (
`id` int(11) NOT NULL auto_increment,
`autor` varchar(40) NOT NULL default '',
`date` datetime NOT NULL default '0000-00-00 00:00:00',
`short_story` text NOT NULL,
`full_story` text NOT NULL,
`xfields` text NOT NULL,
`title` varchar(255) NOT NULL default '',
`descr` varchar(200) NOT NULL default '',
`keywords` text NOT NULL,
`category` varchar(200) NOT NULL default '0',
`alt_name` varchar(200) NOT NULL default '',
`comm_num` smallint(5) unsigned NOT NULL default '0',
`allow_comm` tinyint(1) NOT NULL default '1',
`allow_main` tinyint(1) unsigned NOT NULL default '1',
`allow_rate` tinyint(1) unsigned NOT NULL default '1',
`approve` tinyint(1) NOT NULL default '0',
`fixed` tinyint(1) NOT NULL default '0',
`rating` smallint(5) NOT NULL default '0',
`allow_br` tinyint(1) NOT NULL default '1',
`vote_num` smallint(5) unsigned NOT NULL default '0',
`news_read` mediumint(8) NOT NULL default '0',
`votes` tinyint(1) NOT NULL default '0',
`access` varchar(150) NOT NULL default '',
`symbol` char(3) NOT NULL default '',
`flag` tinyint(1) NOT NULL default '0',
`editdate` varchar(15) NOT NULL default '',
`editor` varchar(40) NOT NULL default '',
`reason` varchar(255) NOT NULL default '',
`view_edit` tinyint(1) NOT NULL default '0',
`tags` varchar(255) NOT NULL default '',
`metatitle` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`),
KEY `autor` (`autor`),
KEY `alt_name` (`alt_name`),
KEY `category` (`category`),
KEY `approve` (`approve`),
KEY `allow_main` (`allow_main`),
KEY `date` (`date`),
KEY `symbol` (`symbol`),
KEY `comm_num` (`comm_num`),
KEY `tags` (`tags`),
FULLTEXT KEY `short_story` (`short_story`,`full_story`,`xfields`,`title`)
) ENGINE=MyISAM AUTO_INCREMENT=5265 DEFAULT CHARSET=utf8

1 row in set (0.03 sec)

=============================================== =====

SHOW TABLE STATUS LIKE 'dle_post'\G
*************************** 1. row ***************************
Name: dle_post
Engine: MyISAM
Version: 10
Row_format: Dynamic
Rows: 4971
Avg_row_length: 6685
Data_length: 33232848
Max_data_length: 281474976710655
Index_length: 7998464
Data_free: 0
Auto_increment: 5266
Create_time: 2010-04-01 15:21:19
Update_time: 2010-11-14 19:24:19
Check_time: 2010-06-20 01:32:40
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)

=============================================== =====

SHOW TABLE STATUS LIKE 'dle_post'\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: NULL
type: NULL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: NULL
Extra: No tables used
1 row in set (0.00 sec)

=============================================== =====

SHOW VARIABLES LIKE '%buffer%';
+-------------------------------+-----------+
| Variable_name | Value |
+-------------------------------+-----------+
| bulk_insert_buffer_size | 16777216 |
| innodb_buffer_pool_awe_mem_mb | 0 |
| innodb_buffer_pool_size | 8388608 |
| innodb_log_buffer_size | 1048576 |
| join_buffer_size | 3145728 |
| key_buffer_size | 671088640 |
| myisam_sort_buffer_size | 268435456 |
| net_buffer_length | 16384 |
| preload_buffer_size | 32768 |
| read_buffer_size | 3145728 |
| read_rnd_buffer_size | 4194304 |
| sort_buffer_size | 3145728 |
+-------------------------------+-----------+
12 rows in set (0.00 sec)

=============================================== =====

我希望这些信息都是解决此问题的必要条件

注意:当服务器加载180 - 350

时,已执行此命令

感谢

1 个答案:

答案 0 :(得分:2)

您有慢查询日志吗?也发布EXPLAIN语句。

你的ORDER BY RAND()对于大表来说会很慢,有更好的方法,比如this example。基本上你只需要生成0到MAX之间的随机数(PRIMARY_KEY),然后做SELECT * from table WHERE PRIMARY_KEY > @that_random_number LIMIT 1

因此,而不是来自dle_post的SELECT * ORDER BY RAND()LIMIT 1;

这样做:

  1. 计算主键的最大值(auto_increment)并将其存储在变量中。

    SELECT MAX(PRIMARY_ID_COLUMN_NAME)FROM dle_posts LIMIT 1;

  2. 生成一个随机数(最好在您的应用程序中避免数据库往返时间,尽管您可以在步骤1中将MAX替换为FLOOR(RAND() * MAX);。但在PHP中的示例:

    $ chosen = rand(0,$ max);

  3. 现在获取主键等于或大于此值的第一行:

    SELECT * FROM dle_posts WHERE PRIMARY_ID_COLUMN_NAME&gt; $ selected LIMIT 1

  4. (approve, category, date)上的索引有帮助吗?

    您的慢查询日志显示没有大问题。如果您可以修改源代码,则可以重写以下查询:

    SELECT COUNT(*) as count FROM dle_users where FROM_UNIXTIME(reg_date) > NOW() - INTERVAL 1 HOUR;
    

    到您不使用now的查询,但让您的应用程序填充时间戳。现在,查询缓存实际上可以缓存查询。