Высокая Mysql нагрузка - процессор 360% - PullRequest
1 голос
/ 15 ноября 2010

у меня высокий уровень использования процессора mysql на сервере Intel® Xeon® R E5520 @ 2,27 ГГц 16 ядерных процессоров и 16 ГБ оперативной памяти, работающих на Centos 5,4

средняя загрузка для сервера 500 - 900, это действительно ВЫСОКИЕ ЧИСЛА

вот некоторая информация, чтобы помочь нам

файл конфигурации 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 Ответ

2 голосов
/ 15 ноября 2010

Есть ли у вас медленный журнал запросов ?Также публикуйте операторы EXPLAIN.

Ваш ORDER BY RAND() будет медленным для больших таблиц, есть лучшие методы, такие как в этом примере .Обычно вы просто генерируете случайное число от 0 до MAX (PRIMARY_KEY), затем делаете SELECT * from table WHERE PRIMARY_KEY > @that_random_number LIMIT 1.

Так что вместо SELECT * из dle_post 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:

    $ selected = rand (0, $ max);

  3. Теперь получите первую строку с первичным ключом, равным или превышающим это значение:

    SELECT *ОТ dle_posts ГДЕ PRIMARY_ID_COLUMN_NAME> $ selected LIMIT 1

Помогает ли индекс для (approve, category, date) помочь?

Ваш медленный журнал запросов не показывает больших проблем. Если вы можете изменитьИсходный код, вы можете переписать следующий запрос:

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

взапрос, в котором вы не используете сейчас, но ваше приложение заполняет отметку времени.Теперь кеш запросов может фактически кешировать запрос.

...