简体   繁体   English

MariaDB 和 MySQL 在 Windows 10 上非常慢

[英]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:有很多关于这个的话题,所以我将总结我已经做过的所有事情:

  1. Change servername from localhost into 127.0.0.1将服务器名从 localhost 更改为 127.0.0.1
  2. Apache: disable CGI Apache:禁用 CGI
  3. PHP: disable Xdebug PHP:禁用 Xdebug
  4. Disabled firewall禁用防火墙
  5. Disabled virusscanner禁用病毒扫描程序
  6. Data dir on different Harddisk不同硬盘上的数据目录

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:更新:

  • Reinstalled Wamp 3.2.3.重新安装 Wamp 3.2.3。 Tested it with MySql 5.7.31, 8.0.21 And MariaDB 10.4.10, 10.4.13, 10.5.5.使用 MySql 5.7.31、8.0.21 和 MariaDB 10.4.10、10.4.13、10.5.5 对其进行了测试。 There is a difference of a few seconds here and there, but still slow.这里和那里有几秒钟的差异,但仍然很慢。
  • Also I changed the script to use $db->multi_query($sql) see if this works.另外我将脚本更改为使用 $db->multi_query($sql) 看看这是否有效。 The result for inserting 10.000 rows is 0.13sec on the old computer and 8.5 seconds on the new one.插入 10.000 行的结果在旧计算机上为 0.13 秒,在新计算机上为 8.5 秒。
  • Just to be sure it's not the SSD or something I wrote a same testscript only using SQlite3 this time and insert 1.000.000 rows in just 7 seconds, so it is only MySQL and MariaDB only.只是为了确保它不是 SSD 或我这次只使用 SQlite3 编写了相同的测试脚本并在短短 7 秒内插入了 1.000.000 行,所以它只是 MySQL 和 MariaDB。
  • Installed VMWare windows 7 on the new PC with Wamp 2.5.在带有 Wamp 2.5 的新 PC 上安装了 VMWare windows 7。 Interesting, the execution time is about the same, also slow.有趣的是,执行时间差不多,也很慢。
  • Move from MyISAM to InnoDB从 MyISAM 迁移到 InnoDB
  • Batch 100 rows in a single INSERT ;在单个INSERT批处理 100 行; it will run about 10 times as fast.它的运行速度大约是原来的 10 倍。
  • Depending on the amount of spare RAM and which Engine you are using, some tuning should be done.根据备用 RAM 的数量和您使用的引擎,应该进行一些调整。
  • Multi-query should never be used.永远不应该使用多查询。
  • autocommit is irrelevant to MyISAM. autocommit与 MyISAM 无关。
  • 100K INSERTs in a single transaction has other problems.单个事务中的 100K INSERTs有其他问题。 Either do the batching, above, or put only 100 inserts in a transaction.要么做上面的批处理,要么只在一个事务中插入 100 个插入。 (Going above 100 in either case is "diminishing returns".) (在任何一种情况下超过 100 都是“收益递减”。)

#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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM