From: alex dot farcas at race dot com
Operating system: Ubuntu 18.04.1 LTS
PHP version: 7.4.7
Package: Performance problem
Bug Type: Bug
Bug description:Random extreme execution times on CPU intensive loads
Description:
------------
The issue manifested itself immediately after we upgraded from PHP-FPM
7.4.1 to 7.4.7. We're using the Ondrej PPA packages.
We have code which looks like this (please ignore it's quality):
foreach ($scratchrows as $ss) {
if ($ss['region']!=$region) continue;
if ($ss['clli_search']!=$clli_search) continue;
if ($ss['city_search']!=$city_search) continue;
if ($ss['propertyname_search']!=$propertyname_search) continue;
if ($ss['address_search']!=$address_search) continue;
$flag=false;
if ($data->search) {
if ($ss['locationid']==$search) $flag=true;
if ($ss['aliaslocationid']==$search) $flag=true;
// if ($ss['nonexistent']==$search) $flag=true;
if (!$flag) continue;
}
$srows[$ss['locationid']]=$ss;
}
Basically, a loop with a lot of comparisons. $scratchrows contains about
30k entries. All the data is made of plain arrays of strings or strings.
On a server with zero traffic, this type of code randomly takes from sub
second to 10 minutes to execute. It's very difficult to reproduce
reliably, but we noticed that it has to do with comparisons with non
existent array keys. For example if we uncomment the one commented line
above, the load time increases with about 30 seconds. Adding one more
adds another 30 seconds. Yet sometimes adding these lines has no effect
at all and the whole thing runs in sub second time.
We introduced timings all over the code to make sure we isolate the
problem as narrowly as possible. We basically had a microtime printed
before the loop and one after the loop.
Running strace on such a process had the following output:
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
78.46 6.252417 34 181733 munmap
21.54 1.716797 9 181380 mmap
0.00 0.000013 4 3 2 write
0.00 0.000012 12 1 futex
0.00 0.000011 2 5 close
0.00 0.000000 0 1 read
0.00 0.000000 0 1 fstat
0.00 0.000000 0 1 poll
0.00 0.000000 0 1 lseek
0.00 0.000000 0 1 setitimer
0.00 0.000000 0 3 sendto
0.00 0.000000 0 3 recvfrom
0.00 0.000000 0 1 shutdown
0.00 0.000000 0 1 fcntl
0.00 0.000000 0 1 chdir
0.00 0.000000 0 1 times
0.00 0.000000 0 1 openat
------ ----------- ----------- --------- --------- ----------------
100.00 7.969250 363138 2 total
--
Edit bug report at https://bugs.php.net/bug.php?id=79713&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79713&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79713&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79713&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79713&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79713&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79713&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79713&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79713&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79713&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79713&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79713&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79713&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79713&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79713&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79713&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79713&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79713&r=mysqlcfg