【发布时间】:2014-10-21 09:22:49
【问题描述】:
我在具有 4GB RAM、2CPU、60GB SSD 特性的 VPS 上运行基于 Prestashop 1.6 的电子商店。目前,我的商店中有大约 20000 种产品,并且由于 mysql 查询运行时间长,我在加载网站时遇到了问题。当我运行 htop 来分析进程时,我看到 mysql 消耗了两个 CPU 的 100%。这是 mysqltuner 的输出:
-------- Performance Metrics -------------------------------------------------
[--] Up for: 1h 29m 9s (241K q [45.109 qps], 319 conn, TX: 318M, RX: 126M)
[--] Reads / Writes: 78% / 22%
[--] Total buffers: 192.0M global + 2.7M per thread (151 max threads)
[OK] Maximum possible memory usage: 597.8M (15% of installed RAM)
[OK] Slow queries: 0% (8/241K)
[OK] Highest usage of available connections: 2% (4/151)
[OK] Key buffer size / total MyISAM indexes: 16.0M/44.9M
[OK] Key buffer hit rate: 99.6% (36M cached / 133K reads)
[OK] Query cache efficiency: 49.6% (101K cached / 205K selects)
[!!] Query cache prunes per day: 1386761
[OK] Sorts requiring temporary tables: 0% (1 temp sorts / 7K sorts)
[!!] Joins performed without indexes: 78
[OK] Temporary tables created on disk: 8% (846 on disk / 9K total)
[OK] Thread cache hit rate: 98% (4 created / 319 connections)
[!!] Table cache hit rate: 10% (340 open / 3K opened)
[OK] Open file limit used: 62% (643/1K)
[OK] Table locks acquired immediately: 100% (239K immediate / 239K locks)
-------- Recommendations -----------------------------------------------------
General recommendations:
Add skip-innodb to MySQL configuration to disable InnoDB
MySQL started within last 24 hours - recommendations may be inaccurate
Enable the slow query log to troubleshoot bad queries
Adjust your join queries to always utilize indexes
Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
query_cache_size (> 16M)
join_buffer_size (> 128.0K, or always use indexes with joins)
table_cache (> 400)
请提出任何优化方法。
编辑:
慢查询输出日志为here。
【问题讨论】:
-
所以基本上你是在免费寻求专业的调优帮助,而且你不知道从哪里开始优化?
-
如何获取慢查询日志并发布导致性能下降的实际罪魁祸首 SQL 查询。一堆统计数据与没有看到编写不佳的查询和已知索引可能真的是事情令人窒息的地方。我不知道我是否会同意所示的 0% 的慢速查询。注意你的 JOINS WITHOUT INDEXES = 78
-
@DRapp 这里是慢查询日志的输出pastie.org/9664946
-
@N.B.如果我知道我就不会问了。不管是不是专业调音,我都有学习的权利。
-
当然你有学习的权利,我永远不会质疑这一点。但是,您发布了一个程序的输出,然后您期望用勺子喂食?例如,程序会告诉您:
Enable the slow query log to troubleshoot bad queries。谷歌 > “启用慢查询日志以解决错误查询” > 如果遇到问题 - 在此处询问。这样,您似乎希望一切都为您完成,因为您提出的问题没有足够的信息来帮助您。看起来您想要一个完整的解决方案,而不是解决问题的线索。
标签: mysql query-optimization prestashop database-administration mysqltuner