POLALA.COM welcome to my space |
HOME MySQL Optimisation Required |
MySQL Optimisation Required | | Published by: rose 2009-01-07 |
| | It appears MySQL is causing my servers CPU usage to shoot up to 100% a couple of times per day, and for no apparent reason (also, I've noticed this happening. This results in my site being inaccessible until I restart MySQL (I'm having to restart everytime this is happening). Occassionally, I do manage to access the site during these periods only to be given a "Database Error" page generated from vBulletin.
This problem has only recently started happening, and although there has been a small increase in site usage, I'm only still averaging around 6 members online and 60 guests/spiders (over a 15 minute period). The server load averages around 0.5 throughout the day and memory usage 50%.
I'd appreciate it if somebody could suggest some optimised configurations for my server (specifically mysql), of which I've listed the specs below.
Thanks!
Server specs:
Dedicated...
P4 2.8Ghz, 1GB RAM
250GB SATA, non raid
CentOS 4.3
Apache/1.3.37
MySQL 4.1.21 (ISAM)
vB Version: 3.6.4
MySQL config:
[mysqld]
set-variable = max_connections=500
safe-show-database
query_cache_type=2
query_cache_limit=1M
query_cache_size=32M
Apache config:
KeepAlive On (Apache is running fine so at the moment I've chosen to leave KeepAlive On)
Timeout 300
MaxKeepAliveRequests 100
KeepAliveTimeout 15
MinSpareServers 5
MaxSpareServers 10
StartServers 5
MaxClients 150
Maxrequestsperchild 0
Try the following in this exact order. You can ignore any of the suggestions that you have already done.
1. Upgrade MySQL server to 4.1.22
2. Upgrade PHP to 4.4.4 and/or recompile PHP 4.4.4 after upgrading MySQL
3. Edit /etc/my.cnf and place the following mysql server settings in /etc/my.cnf and restart mysql server afterwards
[mysqld]
safe-show-database
#old_passwords
back_log = 100
skip-innodb
max_connections = 500
key_buffer = 16M
myisam_sort_buffer_size = 64M
join_buffer_size = 1M
read_buffer_size = 1M
sort_buffer_size = 2M
table_cache = 1800
thread_cache_size = 256
wait_timeout = 45
connect_timeout = 10 15 tips on optimising MySQL databases and MySQL queries - esn studio:: May 18, 2007 I have been reading articles on how to optimise MySQL databases and queries and Name (required). Mail (will not be published) (required) http://eisabainyo.net/weblog/2007/05/18/15-tips-on-optimising-mysql-databases-and-mysql-queries/HOME | MySQL Optimization Tips « Database Articles:: Mar 24, 2008 MYSQL Optimization Tips The MySQL database server performance depends Avoid the use of cursors in the stored procedure if not required. http://sqldbpool.wordpress.com/2008/03/24/mysql-optimization-tips/HOME |
tmp_table_size = 128M
max_heap_table_size = 64M
max_allowed_packet = 64M
max_connect_errors = 10
read_rnd_buffer_size = 524288
bulk_insert_buffer_size = 16M
query_cache_limit = 2M
query_cache_size = 16M
query_cache_type = 1
query_prealloc_size = 163840
query_alloc_block_size = 32768
default-storage-engine = MyISAM
[mysqld_safe]
open_files_limit = 8192
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer = 384M
sort_buffer = 384M
read_buffer = 256M
write_buffer = 256M
[mysqlhotcopy]
interactive-timeout
4. Install Xcache which seems to be a bit faster than APC Cache - http://www.vbulletin.com/forum/showthread.php?t=213267
5. Upgrade to vB 3.0.17 http://www.vbulletin.com/forum/showthread.php?t=209720 if you're on vB 3.0.xx or upgrade to vB 3.5.7 http://www.vbulletin.com/forum/showthread.php?t=209719 if you're on vB 3.5.x. Upgrade to vB 3.6.4 http://www.vbulletin.com/forum/showthread.php?t=209717 if you're on vB 3.6.x
6. If you just upgraded to vB 3.5.x/3.6.x try to disable these 4 options:
Admin CP -> vBulletin Options -> Forums Home Page Options -> Display Logged in Users?
Admin CP -> vBulletin Options -> Forum Display Options (forumdisplay) -> Show Users Browsing Forums
Admin CP -> vBulletin Options -> Thread Display Options -> Show Users Browsing Thread
Admin CP -> vBulletin Options -> Message Searching Options -> Automatic Similar Thread search
7. Edit httpd.conf values to the below ones and restart apache MySQL Optimization Hack - How to Increase Load without Failing :: Dec 10, 2008 MySQL Optimization Hack - How to Increase Load without Failing your MySQL Name (required). Mail (will not be published) (required) http://zedomax.com/blog/2008/12/10/mysql-optimization-hack-how-to-increase-load-without-failing-your-mysql-server/HOME | High Performance MySQL: Optimization, Backups, Replication, and :: Download Free eBook:High Performance MySQL: Optimization, Backups, Replication, required. Email: required, hidden. Mail To: need login. Comments: http://www.ebookee.com/High-Performance-MySQL-Optimization-Backups-Replication-and-More_191927.htmlHOME |
KeepAlive: on
MaxKeepAliveRequests: 100
KeepAliveTimeout: 5
MinSpareServers: 15
MaxSpareServers: 20
StartServers: 15
MaxClients: 150
#MaxRequestsPerChild: 500
The spike has just occurred again so I've captured the top data... I'd really appreciate some help.
TOP (taken from last CPU spike)
top - 00:13:42 up 2 days, 1 min, 1 user, load average: 1.48, 1.27, 0.80
Tasks: 191 total, 1 running, 190 sleeping, 0 stopped, 0 zombie
Cpu(s): 90.4% us, 9.6% sy, 0.0% ni, 0.0% id, 0.0% wa, 0.0% hi, 0.0% si
Mem: 1034668k total, 1018040k used, 16628k free, 21852k buffers
Swap: 2048276k total, 9036k used, 2039240k free, 92884k cached
Unknown command - try 'h' for help
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3878 mysql 15 0 165m 30m 2372 S 91.3 3.0 58:51.14 mysqld
18070 nobody 15 0 24992 14m 3136 S 0.3 1.4 0:04.22 httpd
29475 nobody 15 0 19080 8244 3036 S 0.3 0.8 0:00.14 httpd
32038 root 16 0 3160 1032 760 R 0.3 0.1 0:00.02 top
1 root 15 0 2204 552 472 S 0.0 0.1 0:00.96 init
2 root 34 19 0 0 0 S 0.0 0.0 0:00.15 ksoftirqd/0
3 root 5 -10 0 0 0 S 0.0 0.0 0:00.08 events/0
4 root 10 -10 0 0 0 S 0.0 0.0 0:00.00 khelper
5 root 15 -10 0 0 0 S 0.0 0.0 0:00.00 kacpid
20 root 5 -10 0 0 0 S 0.0 0.0 0:00.00 kblockd/0
39 root 16 0 0 0 0 S 0.0 0.0 0:00.56 pdflush
41 root 10 -10 0 0 0 S 0.0 0.0 0:00.00 aio/0
21 root 15 0 0 0 0 S 0.0 0.0 0:00.00 khubd
40 root 15 0 0 0 0 S 0.0 0.0 0:03.74 kswapd0
187 root 25 0 0 0 0 S 0.0 0.0 0:00.00 kseriod
288 root 5 -10 0 0 0 S 0.0 0.0 0:00.00 ata/0
290 root 23 0 0 0 0 S 0.0 0.0 0:00.00 scsi_eh_0
291 root 24 0 0 0 0 S 0.0 0.0 0:00.00 scsi_eh_1
305 root 15 0 0 0 0 S 0.0 0.0 0:14.11 kjournald
1479 root 6 -10 1808 460 380 S 0.0 0.0 0:00.01 udevd
1675 root 6 -10 0 0 0 S 0.0 0.0 0:00.00 kauditd
1716 root 6 -10 0 0 0 S 0.0 0.0 0:00.00 kmirrord
1741 root 19 0 0 0 0 S 0.0 0.0 0:00.00 kjournald
1742 root 15 0 0 0 0 S 0.0 0.0 0:00.35 kjournald
2411 root 16 0 3132 548 456 S 0.0 0.1 0:00.95 syslogd
2415 root 16 0 2412 384 316 S 0.0 0.0 0:00.05 klogd
2436 named 18 0 38040 3072 1692 S 0.0 0.3 0:19.88 named
2498 root 15 0 3196 292 232 S 0.0 0.0 0:00.00 courierlogger
2499 root 16 0 3076 592 488 S 0.0 0.1 0:00.00 authdaemond
2525 root 16 0 3076 364 248 S 0.0 0.0 0:00.04 authdaemond
2526 root 16 0 3076 364 248 S 0.0 0.0 0:00.04 authdaemond
2527 root 16 0 3076 364 248 S 0.0 0.0 0:00.03 authdaemond
2528 root 16 0 3076 364 248 S 0.0 0.0 0:00.05 authdaemond
2529 root 16 0 3076 364 248 S 0.0 0.0 0:00.05 authdaemond
2530 root 16 0 5356 268 168 S 0.0 0.0 0:00.03 rpc.idmapd
2604 root 19 0 1784 440 368 S 0.0 0.0 0:00.00 acpid
2613 root 16 0 8360 1720 1324 S 0.0 0.2 0:00.01 cupsd
2700 root 18 0 4312 1228 1044 S 0.0 0.1 0:00.00 bash
2762 root 16 0 5028 936 744 S 0.0 0.1 0:00.00 sshd
2775 root 18 0 2812 628 544 S 0.0 0.1 0:00.00 xinetd
2793 root 15 0 13304 7772 1084 S 0.0 0.8 0:00.99 chkservd
2804 root 18 0 1684 212 160 S 0.0 0.0 0:00.00 courierlogger
2805 root 18 0 2328 480 408 S 0.0 0.0 0:00.00 couriertcpd
2812 root 23 0 1764 212 160 S 0.0 0.0 0:00.00 courierlogger
2813 root 24 0 1808 480 408 S 0.0 0.0 0:00.00 couriertcpd
2820 root 16 0 3404 292 232 S 0.0 0.0 0:00.33 courierlogger
2821 root 16 0 1736 496 428 S 0.0 0.0 0:00.34 couriertcpd
2826 root 22 0 2180 212 160 S 0.0 0.0 0:00.00 courierlogger
2827 root 23 0 3216 480 408 S 0.0 0.0 0:00.00 couriertcpd
3216 mailnull 16 0 8448 876 580 S 0.0 0.1 0:00.45 exim
3220 mailnull 19 0 7632 836 544 S 0.0 0.1 0:00.00 exim
3226 root 16 0 4008 1116 640 S 0.0 0.1 0:00.48 antirelayd
3463 root 16 0 26216 22m 1972 S 0.0 2.3 0:01.74 spamd
MySQL Stats
Can't seem to capture more info than this, the length of output is too long...
max_join_size 4294967295
max_length_for_sort_data 1024
max_prepared_stmt_count 16382
max_relay_log_size 0
max_seeks_for_key 4294967295
max_sort_length 1024
max_tmp_tables 32
max_user_connections 0
max_write_lock_count 4294967295
myisam_data_pointer_size 4
myisam_max_extra_sort_file_size 2147483648
myisam_max_sort_file_size 2147483647
myisam_recover_options OFF
myisam_repair_threads 1
myisam_sort_buffer_size 8388608
myisam_stats_method nulls_unequal High Performance MySQL | O'Reilly Media:: In High Performance MySQL you will learn about MySQL indexing and optimization in depth so you can make better use of these key features. http://oreilly.com/catalog/9780596003067/HOME | Re: bulk insert optimization required: msg#00004 db.mysql.c++:: Re: bulk insert optimizat - Find Help in our db.mysql.c++ Forum. http://osdir.com/ml/db.mysql.c++/2007-04/msg00004.htmlHOME |
net_buffer_length 16384
net_read_timeout 30
net_retry_count 10
net_write_timeout 60
new OFF
old_passwords OFF
open_files_limit 2510
pid_file /var/lib/mysql/server.mydomain.com.pid
port 3306
preload_buffer_size 32768
prepared_stmt_count 0
protocol_version 10
query_alloc_block_size 8192
query_cache_limit 1048576
query_cache_min_res_unit 4096
query_cache_size 33554432
query_cache_type DEMAND
query_cache_wlock_invalidate OFF
query_prealloc_size 8192
range_alloc_block_size 2048
read_buffer_size 131072
read_only OFF
read_rnd_buffer_size 262144
relay_log_purge ON
relay_log_space_limit 0
rpl_recovery_rank 0
secure_auth OFF
server_id 0
skip_external_locking ON
skip_networking OFF
skip_show_database OFF
slave_net_timeout 3600
slave_transaction_retries 0
slow_launch_time 2
socket /var/lib/mysql/mysql.sock
sort_buffer_size 2097144
sql_mode
sql_notes ON
sql_warnings ON
storage_engine MyISAM
sync_binlog 0
sync_frm ON
sync_replication 0
sync_replication_slave_id 0
sync_replication_timeout 0
system_time_zone GMT
table_cache 64
table_type MyISAM
thread_cache_size 0
thread_stack 196608
time_format %H:%i:%s
time_zone SYSTEM
tmp_table_size 33554432
tmpdir
transaction_alloc_block_size 8192
transaction_prealloc_size 4096
tx_isolation REPEATABLE-READ
version 4.1.21-standard-log
version_comment MySQL Community Edition - Standard (GPL)
version_compile_machine i686
version_compile_os pc-linux-gnu
wait_timeout 28800
+---------------------------------+----------------------------------------------+
+----------------------------+-----------+
Variable_name Value
+----------------------------+-----------+
Aborted_clients 0
Aborted_connects 6
Binlog_cache_disk_use 0
Binlog_cache_use 0
Bytes_received 98619139
Bytes_sent 167730990
Com_admin_commands 1
Com_alter_db 0
Com_alter_table 0
Com_analyze 0
Com_backup_table 0
Com_begin 0
Com_change_db 173805
Com_change_master 0
Com_check 0
Com_checksum 0
Com_commit 0
Com_create_db 0
Com_create_function 0
Com_create_index 0
Com_create_table 0
Com_dealloc_sql 0
Com_delete 2116
Com_delete_multi 0
Com_do 0
Com_drop_db 0
Com_drop_function 0
Com_drop_index 0
Com_drop_table 0
Com_drop_user 0
Com_execute_sql 0
Com_flush 1
Com_grant 0
Com_ha_close 0
Com_ha_open 0
Com_ha_read 0
Com_help 0
Com_insert 5072
Com_insert_select 0
Com_kill 0
Com_load 0
Com_load_master_data 0
Com_load_master_table 0
Com_lock_tables 110
Com_optimize 0
Com_preload_keys 0
Com_prepare_sql 0
Com_purge 0
Com_purge_before_date 0
Com_rename_table 0
Com_repair 0
Com_replace 718
Com_replace_select 0
Com_reset 0
Com_restore_table 0
Com_revoke 0
Com_revoke_all 0
Com_rollback 0
Com_savepoint 0
Com_select 290989
Com_set_option 162
Com_show_binlog_events 0
Com_show_binlogs 0
Com_show_charsets 0
Com_show_collations 0
Com_show_column_types 0
Com_show_create_db 0
Com_show_create_table 0
Com_show_databases 1
Com_show_errors 0
Com_show_fields 0
Com_show_grants 0
Com_show_innodb_status 0
Com_show_keys 0
Com_show_logs 0
Com_show_master_status 0
Com_show_ndb_status 0
Com_show_new_master 0
Com_show_open_tables 0
Com_show_privileges 0
Com_show_processlist 210
Com_show_slave_hosts 0
Com_show_slave_status 0
Com_show_status 4
Com_show_storage_engines 0
Com_show_tables 1
Com_show_variables 12
Com_show_warnings 0
Com_slave_start 0
Com_slave_stop 0
Com_stmt_close 0
Com_stmt_execute 0
Com_stmt_prepare 0
Com_stmt_reset 0
Com_stmt_send_long_data 0
Com_truncate 0
Com_unlock_tables 110
Com_update 82071
Com_update_multi 445
Connections 174162
Created_tmp_disk_tables 428
Created_tmp_files 1774
Created_tmp_tables 5056
Delayed_errors 0
Delayed_insert_threads 0
Delayed_writes 0
Flush_commands 1
Handler_commit 0
Handler_delete 4081
Handler_discover 0
Handler_read_first 72871
Handler_read_key 1725510
Handler_read_next 28339180
Handler_read_prev 278260
Handler_read_rnd 435995
Handler_read_rnd_next 58331917
Handler_rollback 0
Handler_update 83643
Handler_write 306794
Key_blocks_not_flushed 0
Key_blocks_unused 6003
Key_blocks_used 1266
Key_read_requests 4754904
Key_reads 4752
Key_write_requests 88525
Key_writes 49065
Max_used_connections 19
Not_flushed_delayed_rows 0
Open_files 116
Open_streams 0
Open_tables 64
Opened_tables 1899
Qcache_free_blocks 2
Qcache_free_memory 33542184
Qcache_hits 9998
Qcache_inserts 4297
Qcache_lowmem_prunes 0
Qcache_not_cached 286644
Qcache_queries_in_cache 2
Qcache_total_blocks 8
Questions 740025
Rpl_status NULL
Select_full_join 3
Select_full_range_join 0
Select_range 64713
Select_range_check 0
Select_scan 59596
Slave_open_temp_tables 0
Slave_retried_transactions 0
Slave_running OFF
Slow_launch_threads 0
Slow_queries 1
Sort_merge_passes 885
Sort_range 39360
Sort_rows 2079487
Sort_scan 1867
Table_locks_immediate 434468
Table_locks_waited 91
Threads_cached 0
Threads_connected 1
Threads_created 174161
Threads_running 1
Uptime 62489
+----------------------------+-----------+
Uptime: 62489 Threads: 1 Questions: 740026 Slow queries: 1 Opens: 1899 Flush tables: 1 Open tables: 64 Queries per second avg: 11.843
mysqladmin Ver 8.41 Distrib 4.1.21, for pc-linux-gnu on i686
(C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Server version 4.1.21-standard-log
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 17 hours 21 min 29 sec
Threads: 1 Questions: 740026 Slow queries: 1 Opens: 1899 Flush tables: 1 Open tables: 64 Queries per second avg: 11.843
MySQL Report
MySQL 4.1.21-standard-l uptime 0 16:33:21 Sun Feb 11 16:47:29 2007
__ Key __________________________________________________ _______________
Buffer used 1.23M of 8.00M %Used: 15.41
Current 2.15M %Usage: 26.93
Write ratio 0.554
Read ratio 0.001
__ Questions __________________________________________________ _________
Total 695.93k 11.7/s
DMS 358.13k 6.0/s %Total: 51.46
Com_ 164.40k 2.8/s 23.62
COM_QUIT 164.15k 2.8/s 23.59
QC Hits 9.21k 0.2/s 1.32
+Unknown 36 0.0/s 0.01
Slow 1 0.0/s 0.00 %DMS: 0.00
DMS 358.13k 6.0/s 51.46
SELECT 273.03k 4.6/s 39.23 76.24
UPDATE 77.66k 1.3/s 11.16 21.68
INSERT 4.79k 0.1/s 0.69 1.34
DELETE 1.98k 0.0/s 0.28 0.55
REPLACE 677 0.0/s 0.10 0.19
Com_ 164.40k 2.8/s 23.62
change_db 163.81k 2.7/s 23.54
show_proces 200 0.0/s 0.03
set_option 159 0.0/s 0.02
__ SELECT and Sort __________________________________________________ ___
Scan 55.91k 0.9/s %SELECT: 20.48
Range 60.31k 1.0/s 22.09
Full join 3 0.0/s 0.00
Range check 0 0/s 0.00
Full rng join 0 0/s 0.00
Sort scan 1.77k 0.0/s
Sort range 36.51k 0.6/s
Sort mrg pass 660 0.0/s
__ Query Cache __________________________________________________ _______
Memory usage 10.45k of 32.00M %Used: 0.03
Block Fragmnt 25.00%
Hits 9.21k 0.2/s
Inserts 4.00k 0.1/s
Insrt:Prune 4.00k:1 0.1/s
Hit:Insert 2.30:1
__ Table Locks __________________________________________________ _______
Waited 80 0.0/s %Total: 0.02
Immediate 408.00k 6.8/s
__ Tables __________________________________________________ ____________
Open 64 of 64 %Cache: 100.00
Opened 1.78k 0.0/s
__ Connections __________________________________________________ _______
Max used 19 of 500 %Max: 3.80
Total 164.15k 2.8/s
__ Created Temp __________________________________________________ ______
Disk table 407 0.0/s
Table 4.72k 0.1/s
File 1.32k 0.0/s
__ Threads __________________________________________________ ___________
Running 1 of 6
Cached 0 of 0 %Hit: 0
Created 164.15k 2.8/s
Slow 0 0/s
__ Aborted __________________________________________________ ___________
Clients 0 0/s
Connects 4 0.0/s
__ Bytes __________________________________________________ _____________
Sent 4.17G 70.0k/s
Received 92.51M 1.6k/s
Other scripts running on server?
I use vb database api for my frontend, but there are no other 3rd party scripts or hacks are installed.
Concurrent Users
Average 70-80 users over 15 mins.
PHPinfo
http://markw.fireflyinternet.co.uk/phpinfo.htm
ulimit
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
pending signals (-i) 1024
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
stack size (kbytes, -s) unlimited
cpu time (seconds, -t) unlimited
max user processes (-u) 16367
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel(R) Pentium(R) 4 CPU 2.80GHz
stepping : 9
cpu MHz : 2814.795
cache size : 512 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe cid xtpr
bogomips : 5630.33
need more info all info asked at http://www.vbulletin.com/forum/showthread.php?t=70117
Sorry eva - I've now updated my previous post with the requested. Thanks for your help.
Where's The Advantage In Windows Genuine Advantage?
Stocks Bounce After S&P Joins Bear Market
|
#If you have any other info about this subject , Please add it free.# | |
|