Performance issue to PHP include file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

We observed the performance issue to PHP include file for PHP 5.4.41. Sorry
for using the old version, we haven't got the time to check whether the
issue still exists in the recent version.

PHP sample code:
include “core/Core.class.php”
include "core/View.class.php"
include ...
//do some work below
...

1. From the perfomance test, we observed as high as 80%+ CPU sys% for about
100 concurret requests.
2. We used strace to attach php-fpm process:

open("/srv/www/simulation/my/core/View.class.php", O_RDONLY) = 9
fstat(9, {st_mode=S_IFREG|0644, st_size=2034, ...}) = 0
fstat(9, {st_mode=S_IFREG|0644, st_size=2034, ...}) = 0
fstat(9, {st_mode=S_IFREG|0644, st_size=2034, ...}) = 0
mmap(NULL, 2034, PROT_READ, MAP_SHARED, 9, 0) = 0x7fa21727c000
stat("/srv/www/simulation/my/core/View.class.php", {st_mode=S_IFREG|0644,
st_size=2034, ...}) = 0
fcntl(3, F_SETLKW, {type=F_WRLCK, whence=SEEK_SET, start=0, len=1}) = 0
fcntl(3, F_SETLKW, {type=F_UNLCK, whence=SEEK_SET, start=0, len=1}) = 0
munmap(0x7fa21727c000, 2034)            = 0
close(9)                                = 0

>From the above log, we observed php-fpm used fcntl to accqure write lock
for the including file "core/View.class.php". Similar log were observed as
well for other including files.
3. We used perf, and found out most of CPU time were consumed by
fcntl_setlk:
-   88.23%     0.13%          php-fpm  [kernel.kallsyms]            [k]
fcntl_setlk
                                     ▒
   - fcntl_setlk

                                  ▒
      - 100.00% sys_fcntl

                                 ▒
           system_call_fastpath

                                 ▒
           __GI___libc_fcntl


All the above messages seem to indicate that PHP would acquire file writer
lock to include file, and the lock contention lead to serious perfomance
issue.

Then, we did another experiment by writing the code from includeing files
directly to the same PHP file.

PHP sample code:
//the code from “core/Core.class.php"
...
//the code from  "core/View.class.php"
...
//the original code
...

>From the test, we got more than twice perfomance improvements than the
pervious, measured by tps (transaction per second).

Is this a known issue to PHP? And are there any good solutions to the
issue, except for do not use "include" file?

Thanks!

-Ethan

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux