【发布时间】:2015-06-03 17:49:33
【问题描述】:
我在优化要使用的 VPS MySQL 时遇到问题。我在 RamNode 中有一个具有以下规格的计划:
- Intel® Xeon® CPU E3-1240 V2 @ 3.40GHz (4 Cores)
- 4GB de Ram
- 135 GB SSD Raid 10
我托管的一个应用程序出现问题,速度慢,有时会放弃错误“最大用户连接数”。
下面是在 MySQLTunner 中进行的测试:
存储引擎统计数据
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MRG_MYISAM
[--] Data in MyISAM tables: 136M (Tables: 300)
[--] Data in InnoDB tables: 44M (Tables: 202)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[!!] Total fragmented tables: 220
性能指标
[--] Up for: 1d 20h 25m 13s (3M q [23.681 qps], 251K conn, TX: 9B, RX: 605M)
[--] Reads / Writes: 57% / 43%
[--] Total buffers: 528.0M global + 3.6M per thread (400 max threads)
[!!] Query cache prunes per day: 7322
[!!] Sorts requiring temporary tables: 69% (144K temp sorts / 208K sorts)
[!!] Joins performed without indexes: 21719
-------- 推荐 -------------------------------------- ---------------
一般建议: 运行 OPTIMIZE TABLE 对表进行碎片整理以获得更好的性能。启用慢查询日志以解决错误查询。调整您的连接查询以始终使用索引
要调整的变量:
query_cache_size (> 64M)
sort_buffer_size (> 2M)
read_rnd_buffer_size (> 236K)
join_buffer_size (> 128.0K, or always use indexes with joins)
My.CNF 下方
[mysqld]
max_connections = 400
max_user_connections=40
key_buffer_size = 256M
myisam_sort_buffer_size = 16M
read_buffer_size = 1M
table_open_cache = 2048
thread_cache_size = 128
wait_timeout = 20
connect_timeout = 10
tmp_table_size = 128M
max_heap_table_size = 64M
max_allowed_packet=268435456
net_buffer_length = 5500
max_connect_errors = 10
concurrent_insert = 2
read_rnd_buffer_size = 242144
bulk_insert_buffer_size = 2M
query_cache_limit = 2M
query_cache_size = 64M
query_cache_type = 1
query_prealloc_size = 87382
query_alloc_block_size = 21845
transaction_alloc_block_size = 2730
transaction_prealloc_size = 1364
max_write_lock_count = 2
log-error
external-locking=FALSE
open_files_limit=15000
default-storage-engine=MyISAM
innodb_file_per_table=1
[mysqld_safe]
[mysqldump]
quick
max_allowed_packet = 8M
[isamchk]
key_buffer = 128M
sort_buffer = 128M
read_buffer = 64M
write_buffer = 64M
[myisamchk]
key_buffer = 128M
sort_buffer = 128M
read_buffer = 64M
write_buffer = 64M
#### Per connection configuration ####
sort_buffer_size = 2M
join_buffer_size = 2M
thread_stack = 192K
log-slow-queries
如果你能帮助我,谢谢:)
【问题讨论】:
-
如果你把整个
mysqltuner和my.cnf都放在这里就不好看了。只放重要的相关内容
标签: php mysql multithreading performance caching