Bug #80695 [Opn->Nab]: Extremely slow PHP file access operations on all Windows OS's
| From: | cmb@php.net | Date: | Tue, 02 Feb 2021 12:48:09 +0000 |
| Subject: | Bug #80695 [Opn->Nab]: Extremely slow PHP file access operations on all Windows OS's | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-231886@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80695&edit=1
ID: 80695
Updated by: cmb@php.net
Reported by: info at futurion dot si
Summary: Extremely slow PHP file access operations on all
Windows OS's
-Status: Open
+Status: Not a bug
Type: Bug
Package: *Directory/Filesystem functions
Operating System: Windows (All platforms)
PHP Version: 7.4.14
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Generally, such performance comparisons are ⦠difficult.
Obviously, there are huge architectural differences between
Windows and Linux; some of these can be influenced by the system
adminstrator, some cannot[1]. There is nothing to do about that
from the PHP side. And PHP can't do anything about the rest of
the system (e.g. AV scanners, other background processes, amount
of free memory, etc.)
Then there is the issue that PHP is primarily developed for Linux,
and the Windows implementation tries to match the given POSIX
semantics as closely as possible. Newer PHP versions have caught
up on that (especially PHP 7.4), and that may well slow down the
performance of file access in favor of improved compatibility with
the Linux implementation.
Then there are relevant differences between thread-safe (ZTS) and
non-thread-safe (NTS) builds, and also regarding some
configuration options (e.g. realpath_cache).
Now I'm a bit irritated that you've mentioned safe mode; this
"feature" is removed as of PHP 5.4.0. Did you really tests such
old versions?
Then you mentioned that you have tested with different Webservers,
and your test results already acknowledge that performance is
considerable worse for Apache2 than CLI on the same system (Ubuntu
Linux 20.04). So obviously it makes sense to focus on a certain
SAPI (CLI seems to be most appropriate).
Also, for this bug report to be actionable, at the very least we
would have to check the performance for any of the actively
supported PHP versions[2], and only something that could be
regarded as bug could be addressed for PHP 7.4/8.0; any potential
improvements would have to target the master branch (i.e. 8.1, but
there are no releases yet).
Furthermore, I suggest to use hrtime() instead of microtime() for
any benchmarks.
Anyhow, I have now run the modified script (using hrtime()) with
the official PHP 7.4.14 NTS x64 build[3] on Windows 10 2004, and
with a minimal PHP 7.4.14 NTS x64 build on a Debian 10.2
VirtualBox VM on the same machine. I can confirm your findings,
but that is comparing apples and oranges. If I run the test from
a mounted NTFS folder, I see roughly the same performance as with
the Windows builds. So obviously, we're hitting the differences
mentioned in the first paragraph, which PHP can't solve.
If you notice performance regressions with the same kind of builds
on Windows, compared to earlier PHP versions, please open a new
ticket. For the given test script, the performance of 7.3.26 and
7.4.14 is roughly the same in my environment.
[1] <https://superuser.com/questions/1124472/why-is-linux-30x-faster-than-windows-10-in-copying-files>
[2] <https://www.php.net/supported-versions.php>
[3] <https://bugs.php.net/bug.php?id=80695>
Previous Comments:
------------------------------------------------------------------------
[2021-02-01 19:57:18] beberlei@php.net
Just to clarify, the stat cache is only a *single* entry cache, storing the stat information of the
last file that was accessed. So that explains why clearstatcache before/after example makes no
difference.
------------------------------------------------------------------------
[2021-02-01 19:54:25] info at futurion dot si
Description:
------------
I did some extensive tests on various PHP versions on windows and linux platforms. Long story short,
it seems windows suffer big time from slow file-access with all PHP file-related functions. I used
as a sample a simple PHP script, which is published here:
https://pastebin.com/VfLCgs3K
That script takes about 10x or more time on windows in comparison to linux. I tried all possible
combinations (power profiles, opcache, safe mode, windows defender and firewall disable, wincache,
etc.), but it doesn't matter, nothing helps. I also tried different windows versions, different
web servers, also running that script in CLI is slow as well.
That above being said, would you be maybe kind enough to look into this issue, or maybe try running
that same script at your side as well and maybe write something useful back. Is there actually any
way to gain some "speed" on windows to be at least close to linux's performance? I
really can't believe PHP on windows is so much slower than on linux.
Kind regards and thank you in advance for your answer.
Tomaz Kavcic.
Test script:
---------------
<?php
$microtime = microtime(true);
function displayCounter($txt){
global $microtime;
echo "<p> {$txt}: ". round((microtime(true) - $microtime) * 1000,0)
."ms</p>";
$microtime = microtime(true);
}
$file_prefix = __DIR__ . '/file';
for($i= 1; $i < 1000; $i++){
file_put_contents($file_prefix . $i, '');
}
displayCounter('File Creation');
for($i= 1; $i < 1000; $i++){
file_exists($file_prefix . $i);
}
displayCounter('file_exists');
clearstatcache();
for($i= 1; $i < 1000; $i++){
file_exists($file_prefix . $i);
}
displayCounter('file_exists (after cache clear)');
for($i= 1; $i < 1000; $i++){
unlink($file_prefix . $i);
}
displayCounter('unlink');
Expected result:
----------------
Tested on Ubuntu Linux 20.04 (Apache 2)
-
File Creation: 33ms
file_exists: 4ms
file_exists (after cache clear): 4ms
unlink: 22ms
Teset on Ubuntu Linux 20.04 (PHP CLI)
-
File Creation: 20ms
file_exists: 2ms
file_exists (after cache clear): 2ms
unlink: 11ms
Actual result:
--------------
Tested on Windows 2019 Server (Also on other Windows OS's - similar results)
-
File Creation: 104ms
file_exists: 21ms
file_exists (after cache clear): 20ms
unlink: 62ms
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80695&edit=1