I'm using WAMP on a Windows 10 (i5,ssd) machine and noticed the websites are quite slow. Much slower than on my old Windows 7 (i3,hd) PC.
When I loop a simple script with a calculation: 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
The script I use insert a simple hash in a table "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
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:
- Change servername from localhost into 127.0.0.1
- Apache: disable CGI
- PHP: disable Xdebug
- Disabled firewall
- Disabled virusscanner
- Data dir on different Harddisk
raised buffers a lot in 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.
Update:
- Reinstalled 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. 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. The result for inserting 10.000 rows is 0.13sec on the old computer and 8.5 seconds on the new one.
- 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.
- Installed VMWare windows 7 on the new PC with Wamp 2.5. Interesting, the execution time is about the same, also slow.