我们的网站针对用户端的报告功能运行了一些非常大的收入查询。较大的帐户在某些页面上加载5-20秒。当这些查询运行时,他们使用MYSQL SUM()函数计算收入,我相信这会创建大量临时表,并且看起来有些正在磁盘上创建。我一直在运行MYSQL Tuner,但它不再对我的设置进行任何变量调整。这是一个示例输出:
-------- Performance Metrics -------------------------------------------------
[--] Up for: 5h 14m 29s (1M q [98.277 qps], 143K conn, TX: 2B, RX: 212M)
[--] Reads / Writes: 94% / 6%
[--] Total buffers: 4.1G global + 3.8M per thread (600 max threads)
[!!] Maximum possible memory usage: 6.3G (89% of installed RAM)
[OK] Slow queries: 0% (7K/1M)
[OK] Highest usage of available connections: 2% (14/600)
[OK] Key buffer size / total MyISAM indexes: 640.0M/1.0G
[OK] Key buffer hit rate: 99.9% (237M cached / 135K reads)
[OK] Query cache efficiency: 62.5% (756K cached / 1M selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (429 temp sorts / 134K sorts)
[OK] Temporary tables created on disk: 21% (25K on disk / 120K total)
[OK] Thread cache hit rate: 99% (14 created / 143K connections)
[OK] Table cache hit rate: 70% (247 open / 348 opened)
[OK] Open file limit used: 0% (440/760K)
[OK] Table locks acquired immediately: 99% (577K immediate / 578K locks)
[OK] InnoDB data size / buffer pool: 144.0K/8.0M
-------- Recommendations -----------------------------------------------------
General recommendations:
Run OPTIMIZE TABLE to defragment tables for better performance
MySQL started within last 24 hours - recommendations may be inaccurate
Reduce your overall MySQL memory footprint for system stability
此处还有我的MY.CNF设置:
[mysqld]
safe-show-database
skip-locking
skip-networking
max_connections = 600
key_buffer = 640M
table_cache = 380000
query_cache_size = 1024M
query_cache_limit = 12M
query_cache_type = 1
local-infile=0
long_query_time=1
myisam_sort_buffer_size = 64M
max_heap_table_size = 2560M
tmp_table_size = 2560M
max_allowed_packet = 8M
thread_cache_size = 70
thread_stack = 256K
sort_buffer_size = 512K
read_buffer_size = 512K
read_rnd_buffer_size = 512K
binlog_cache_size=64K
long_query_time=1
log-slow-queries=/var/log/slow-query.log
low_priority_updates=1
concurrent_insert=2
log-queries-not-using-indexes
join_buffer_size=2M
thread_concurrency = 16
任何帮助将不胜感激。我需要让这些页面加载更快。服务器是四核x2(8 CPU),内存为8 GB。表格已完全编入索引。 Thannks。
**解决:我能够通过为WHERE列创建多列索引来解决此问题。看起来这与磁盘上创建的临时表创建的缓慢无关。 QPS从98跳到212。
答案 0 :(得分:0)
您也可以尝试将查询缓存类型设置为2(按需),然后更改将真正受益于SELECT SQL_CACHE ...查询的查询...这将消除缓存查询的开销,这些查询实际上无法从缓存中获益