A
A
Alexander2021-07-13 21:03:51
PHP
Alexander, 2021-07-13 21:03:51

Why can PHP file operations be slow?

There is a site on Bitrix on Dedicated. When testing, in particular, it gives the following picture:
60edd45ae954c531158228.png
As you can see, it's not a fountain. However, if you test the disk speed:

[email protected] ~# hdparm -t /dev/md126 

/dev/md126:
 Timing buffered disk reads: 2532 MB in  3.00 seconds = 843.80 MB/sec
[email protected] ~# sync; dd if=/dev/zero of=tempfile bs=1M count=1024; sync
1024+0 записей получено
1024+0 записей отправлено
 скопировано 1073741824 байта (1,1 GB), 0,672519 c, 1,6 GB/c

That indicators och. not bad. Still - there nvme. I checked it on a VDS with a regular SSD which is almost twice as slow as this one, and got> 44000 pho / s

How so?
PHP 7.4.21
open_basedir is not set
Both there and there php is an apache module.

UPD:
Here is a script for testing the speed of file operations.
<?
function getmicrotime()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}
    
    
$res = array();
$file_name = __DIR__."/../upload/perfmon#i#.php";
$content = "<?\$s='".str_repeat("x", 1024)."';?><?/*".str_repeat("y", 1024)."*/?><?\$r='".str_repeat("z", 1024)."';?>";

for ($j = 0; $j < 4; $j++)
{
    $s1 = getmicrotime();
    for ($i = 0; $i < 100; $i++)
    {
        $fn = str_replace("#i#", $i, $file_name);
    }
    $e1 = getmicrotime();
    $N1 = $e1 - $s1;

    $s2 = getmicrotime();
    for ($i = 0; $i < 100; $i++)
    {
        //This is one op
        $fn = str_replace("#i#", $i, $file_name);
        $fh = fopen($fn, "wb");
        fwrite($fh, $content);
        fclose($fh);
        include($fn);
        unlink($fn);
    }
    $e2 = getmicrotime();
    $N2 = $e2 - $s2;

    if ($N2 > $N1)
        $res[] = 100 / ($N2 - $N1);
}

if (count($res))
    echo array_sum($res) / doubleval(count($res));
else
    echo 0;

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2021-07-26
Madzhugin @Suntechnic

I asked myself, I answer myself:
The nesting of the site's document root greatly affects the test result, since when open, the lstat system call is called recursively for the entire path if the file does not exist. More details: https://www.linux.org.ru/forum/web-development/164...
Thus, it makes no sense to rely on the data of this test, since the site rarely creates non-existent files, except perhaps when creating cache files. The include statement is not affected by this problem and nesting has no meaning with it. So it makes no sense to move the document root higher in the file system tree.

S
SagePtr, 2021-07-13
@SagePtr

Faced such a situation, / dev / md sagged a lot in iops performance. The problem can be fixed by installing a hardware raid controller.

A
Anton Shamanov, 2021-07-13
@SilenceOfWinter

The obvious solution is to see how the Bitrix gets this value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question