[英]MariaDB & MySQL very slow on Windows 10
I'm using WAMP on a Windows 10 (i5,ssd) machine and noticed the websites are quite slow.我在 Windows 10 (i5,ssd) 机器上使用 WAMP 并注意到网站速度很慢。 Much slower than on my old Windows 7 (i3,hd) PC.
比我的旧 Windows 7 (i3,hd) PC 慢得多。
When I loop a simple script with a calculation: Win10: 0.4 sec Win7: 9.5 sec当我用计算循环一个简单的脚本时: Win10: 0.4 sec Win7: 9.5 sec
But when I add database queries in a loop, it's the opposite: Win10: 147 sec Win7: 15 sec但是当我在循环中添加数据库查询时,情况正好相反: Win10: 147 sec Win7: 15 sec
The script I use insert a simple hash in a table "test":我使用的脚本在表“test”中插入一个简单的哈希:
CREATE TABLE `test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`testvalue` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
The PHP testscript: PHP 测试脚本:
<?php
set_time_limit(0);
$time_start = microtime(true);
$insertTotal = 100000;
$servername = "127.0.0.1";
$username = "root";
$password = "";
$dbname = "speedtest";
$db = new mysqli($servername, $username, $password, $dbname);
$db->query("TRUNCATE test");
for($i=0;$i<$insertTotal;$i++)
{
$db->query("INSERT INTO test VALUES(null,'".md5(time().rand(0,999999999))."')");
}
$time_end = microtime(true);
$execution_time = ($time_end - $time_start);
echo 'Total exec time: '.$execution_time.' sec.';
There are quite a few topics about this, so I will sum up all I already did:有很多关于这个的话题,所以我将总结我已经做过的所有事情:
raised buffers a lot in my.ini:在 my.ini 中提出了很多缓冲区:
key_buffer_size = 512M
max_allowed_packet = 64M
table_open_cache = 256
sort_buffer_size = 4M
net_buffer_length = 8K
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 128M
So what else I'm missing here?那么我在这里还缺少什么?
Some additional info: when executing the script, the SSD is having 0% load and the CPU has about a 30% load.一些附加信息:执行脚本时,SSD 的负载为 0%,CPU 的负载约为 30%。
Update:更新:
INSERT
;INSERT
批处理 100 行; it will run about 10 times as fast.autocommit
is irrelevant to MyISAM. autocommit
与 MyISAM 无关。INSERTs
in a single transaction has other problems.INSERTs
有其他问题。 Either do the batching, above, or put only 100 inserts in a transaction.#update# There was actually a problem with my PC indeed. #update#我的电脑确实有问题。 I fixed it at last ( https://superuser.com/questions/1584203/windows-10-very-slow-how-to-find-the-cause ) and now the test script runs 34 times faster.
我最后修复了它( https://superuser.com/questions/1584203/windows-10-very-slow-how-to-find-the-cause ),现在测试脚本的运行速度提高了 34 倍。 So also the better script that use multi value insert is way faster.
因此,使用多值插入的更好的脚本也更快。 The whole WAMP runs many times faster now.
现在整个 WAMP 的运行速度要快很多倍。 Glad this is solved.
很高兴这已解决。 #update#
#更新#
After spending way to much hours on this issue I went on working on my actual import script and suddenly realize I have been barking up on the wrong tree all along.在这个问题上花了很多时间之后,我继续研究我的实际导入脚本,突然意识到我一直在错误的树上咆哮。 I have been trying to fix a problem that was not actually a problem.
我一直在尝试解决一个实际上不是问题的问题。
Sure, it's not correct I have a write speed of 500 seperate queries per second when the old PC can do 50.000 or so, but I should never gonne use seperate queries after all.当然,这是不正确的,当旧 PC 可以执行 50.000 左右时,我的写入速度为每秒 500 个单独查询,但毕竟我永远不应该使用单独查询。 I was so focused on this problem, that I did not realize the performance issue was not effecting everything else persé that MySQL and MariaDB could do.
我如此专注于这个问题,以至于我没有意识到性能问题并没有影响 MySQL 和 MariaDB 可以做的所有其他事情。
So Rick James answer was actually right thinking.所以里克詹姆斯的回答实际上是正确的想法。
Sorry guys for wasting your time.对不起,浪费你的时间。 Thank you for helping me!
感谢你们对我的帮助! I have been working days on problems before and fix them, but never work on a problem so long that was not a real problem at all!
我以前一直在处理问题并解决它们,但从来没有处理过一个根本不是真正问题的问题!
To give an example, I modified the test script a bit.举个例子,我稍微修改了测试脚本。 This can insert 200 million rows in about 14 minutes:
这可以在大约 14 分钟内插入 2 亿行:
<?php
set_time_limit(0);
$time_start = microtime(true);
$insertTotal = 200000000;
$servername = "127.0.0.1";
$username = "root";
$password = "";
$dbname = "speedtest";
$db = new mysqli($servername, $username, $password, $dbname);
$db->query("TRUNCATE test");
$counter = 0;
$sql = array();
for($i=0;$i<$insertTotal;$i++)
{
$sql[] = "(null,'".md5(time().rand(0,999999999))."')";
if($counter == 5000)
{
$sql = implode(",",$sql);
$db->query("INSERT INTO test VALUES ".$sql.";");
$counter = 0;
$sql = array();
}
$counter++;
}
$sql = implode(",",$sql);
$db->query("INSERT INTO test VALUES ".$sql.";");
$time_end = microtime(true);
$execution_time = ($time_end - $time_start);
echo 'Total exec time: '.$execution_time.' sec.';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.