[英]MySQL 10x slower on one server compared to another
I have a live server and my dev server, and I am finding that queries on my LIVE (not dev) server run 10x slower, even though the live server is more powerful and they are both running comparable load. 我有一个实时服务器和我的开发服务器,即使实时服务器功能更强大并且它们都在可比较的负载下运行,我的LIVE (非开发服务器)上的查询运行速度也慢了10倍。 It's not a database structure thing because I load the backup from the live server into my dev server. 这不是数据库结构,因为我将备份从实时服务器加载到开发服务器中。
Does anybody have any ideas on where I could look for the discrepancy? 有人对我在哪里可以找到差异有任何想法吗? Could it be a MySQL config thing? 难道这是一个MySQL配置的东西吗? Where should I start looking? 我应该从哪里开始寻找?
Live Server: 实时服务器:
mysql> SELECT count(`Transaction`.`id`) as count, sum(`Transaction`.`amount`) as sum, sum(Transaction.citiq_margin+rounding + Transaction.citiq_margin_vat) as revenue FROM `transactions` AS `Transaction` LEFT JOIN `meters` AS `Meter` ON (`Transaction`.`meter_id` = `Meter`.`id`) LEFT JOIN `units` AS `Unit` ON (`Meter`.`unit_id` = `Unit`.`id`) WHERE (NOT (`Unit`.`building_id` IN ('1', '85')) AND NOT (`Transaction`.`state` >= 90)) AND DAY(`Transaction`.`created`) = DAY(NOW()) AND YEAR(`Transaction`.`created`) = YEAR(NOW()) AND (MONTH(`Transaction`.`created`)) = MONTH(NOW()); +-------+---------+---------+ | count | sum | revenue | +-------+---------+---------+ | 413 | 3638550 | 409210 | +-------+---------+---------+ 1 row in set (2.62 sec) [root@mises ~]# uptime 17:11:57 up 55 days, 1 min, 1 user, load average: 0.45, 0.56, 0.60
Dev Server (result count is different because of slight time delay from backup): 开发服务器(由于从备份到时间的延迟,结果计数有所不同):
mysql> SELECT count(`Transaction`.`id`) as count, sum(`Transaction`.`amount`) as sum, sum(Transaction.citiq_margin+rounding + Transaction.citiq_margin_vat) as revenue FROM `transactions` AS `Transaction` LEFT JOIN `meters` AS `Meter` ON (`Transaction`.`meter_id` = `Meter`.`id`) LEFT JOIN `units` AS `Unit` ON (`Meter`.`unit_id` = `Unit`.`id`) WHERE (NOT (`Unit`.`building_id` IN ('1', '85')) AND NOT (`Transaction`.`state` >= 90)) AND DAY(`Transaction`.`created`) = DAY(NOW()) AND YEAR(`Transaction`.`created`) = YEAR(NOW()) AND (MONTH(`Transaction`.`created`)) = MONTH(NOW()); +-------+---------+---------+ | count | sum | revenue | +-------+---------+---------+ | 357 | 3005550 | 338306 | +-------+---------+---------+ 1 row in set (0.22 sec) [www@smith test]$ uptime 18:11:53 up 12 days, 1:57, 4 users, load average: 0.91, 0.75, 0.62
Live Server (2 x Xeon Quadcore): 实时服务器(2 x Xeon Quadcore):
processor : 7 vendor_id : GenuineIntel cpu family : 6 model : 44 model name : Intel(R) Xeon(R) CPU E5620 @ 2.40GHz stepping : 2 cpu MHz : 2395.000 cache size : 12288 KB physical id : 0 siblings : 8 core id : 10 cpu cores : 4
Dev Server (1 x Quadcore) 开发服务器(1 x Quadcore)
processor : 3 vendor_id : GenuineIntel cpu family : 6 model : 23 model name : Intel(R) Core(TM)2 Quad CPU Q8300 @ 2.50GHz stepping : 10 microcode : 0xa07 cpu MHz : 1998.000 cache size : 2048 KB physical id : 0 siblings : 4 core id : 3 cpu cores : 4
Live Server: 实时服务器:
Dev Server: 开发服务器:
The obvious first thing to check would be your MySql configuration file to make sure you are utilizing an appropriate amount of memory for queries.. such as key_buffer, sort_buffer, etc... There are far smarter people than me out there who have entire blogs dedicated to configuring MySql. 首先要检查的是MySql配置文件,以确保您正在使用适当数量的内存进行查询..例如key_buffer,sort_buffer等。在这里,有比我聪明得多的人拥有整个博客专门用于配置MySql。
You can also prepend your query with "explain" to see what is taking the most time... but that might just be something for general use later on. 您还可以在查询中添加“解释”,以查看花费最多的时间...但是稍后可能只是一般用途。
In reality, your "live" server has caching capabilities and twice the number of cores to make these queries, and it likely has enough horsepower and memory to explain the difference in query times between the servers. 实际上,您的“实时”服务器具有缓存功能和两倍于执行这些查询的内核数量,并且它可能具有足够的能力和内存来解释服务器之间的查询时间差异。
So, I ran the same database and queries on a Virtual Machine running Centos, 1 CPU and 512MB of memory: it provides the answer to that query in 0.3 seconds; 因此,我在运行Centos,1个CPU和512MB内存的虚拟机上运行了相同的数据库并进行了查询:它在0.3秒内为该查询提供了答案; system load is 0.4 :/ 系统负载为0.4:/
The only real difference seems to be that I am running Mysql 5.5 on that server. 唯一真正的区别似乎是我在该服务器上运行Mysql 5.5。 And it seems that there really is a 10x performance improvement in my case from Mysql 5.0 to Mysql 5.5. 从Mysql 5.0到Mysql 5.5,看来我的性能确实提高了10倍。
I will only know for sure once I have migrated my live servers from Mysql 5.0 to Mysql 5.5, I will confirm the results once I have done that. 我将只知道将实时服务器从Mysql 5.0迁移到Mysql 5.5后,就可以确定结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.