Bug #79519 [Com]: Memory leak in PHP 7.4

From: Date: Tue, 28 Apr 2020 17:33:12 +0000
Subject: Bug #79519 [Com]: Memory leak in PHP 7.4
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226812@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79519&edit=1

 ID:                 79519
 Comment by:         kieran at miami-nice dot co dot uk
 Reported by:        kieran at miami-nice dot co dot uk
 Summary:            Memory leak in PHP 7.4
 Status:             Open
 Type:               Bug
 Package:            Performance problem
 Operating System:   Linux
 PHP Version:        7.4.5
 Block user comment: N
 Private report:     N

 New Comment:

It's something to do with the use of require

Another example, different code, but same principle. 

https://github.com/bytestream/php74-memory-leak/tree/factories

$ php7.2 vendor/bin/phpunit --repeat 100
Time: 1.75 minutes, Memory: 322.00 MB

$ php7.3 vendor/bin/phpunit --repeat 100
Time: 1.02 minutes, Memory: 310.50 MB

$ php7.4 vendor/bin/phpunit --repeat 100
Time: 2.24 minutes, Memory: 1.32 GB


Previous Comments:
------------------------------------------------------------------------
[2020-04-28 16:27:56] kieran at miami-nice dot co dot uk

Adding more routes to the test case seems to show some interesting results.

https://github.com/bytestream/php74-memory-leak/tree/routes

$ php7.2 vendor/bin/phpunit --repeat 1000
Time: 1.09 minutes, Memory: 144.00 MB

$ php7.3 vendor/bin/phpunit --repeat 1000
Time: 17.47 seconds, Memory: 138.00 MB

$ php7.4 vendor/bin/phpunit --repeat 1000
Time: 58.73 seconds, Memory: 510.00 MB

------------------------------------------------------------------------
[2020-04-28 14:55:00] kieran at miami-nice dot co dot uk

> maybe Blackfire already collects them and I can't find it

Sent a message to Blackfire to see if they can provide any insight.

> The PHP 7.3 memory profile states that the peak memory would be
> 761 MB, but for the Text::getConsecutiveWords the allocated memory
> is reported as 4060 MB.  That appears to be contradictory.

I think this may be something else.

https://github.com/bytestream/php74-memory-leak

$ php7.3 vendor/bin/phpunit --repeat 100
Time: 3.78 seconds, Memory: 396.00 MB

$ php7.4 vendor/bin/phpunit --repeat 100
Time: 11.56 seconds, Memory: 734.00 MB

with gc_collect_cycles in tearDown - ref; https://github.com/fzaninotto/Faker/pull/1730

$ php7.3 vendor/bin/phpunit --repeat 100
Time: 4.71 seconds, Memory: 32.00 MB

$ php7.4 vendor/bin/phpunit --repeat 100
Time: 13.54 seconds, Memory: 34.00 MB

If I add gc_collect_cycles to the full app, PHP 7.4 memory usage remains unchanged at 3.89GB

------------------------------------------------------------------------
[2020-04-27 15:35:27] cmb@php.net

The PHP 7.3 memory profile states that the peak memory would be
761 MB, but for the Text::getConsecutiveWords the allocated memory
is reported as 4060 MB.  That appears to be contradictory.

------------------------------------------------------------------------
[2020-04-26 19:37:50] nikic@php.net

Not seeing anything obvious based on these profiles. Without a reproducer, the only suggestion I can
make is to a) gather garbage collection statistics using gc_status() (maybe Blackfire already
collects them and I can't find it) and b) create a memory profile using "USE_ZEND_ALLOC=0
valgrind --tool=massif php vendor/bin/phpunit" followed by "ms_print massif.*" (this
will take a long time to run). This may or may not pinpoint the source of the leak.

------------------------------------------------------------------------
[2020-04-24 17:57:09] kieran at miami-nice dot co dot uk

Description:
------------
I'm running the same code through PHP Unit 8.5.2 on PHP 7.3 and PHP 7.4 and there's a huge
memory leak in 7.4. Several others have confirmed a similar issue in https://github.com/sebastianbergmann/phpunit/issues/3915

PHPUnit 8.5.2 - PHP 7.3.17 - Memory: 769.00 MB
PHPUnit 8.5.2 - PHP 7.4.5  - Memory: 3.89 GB

Both instances are running in slightly modified images of docker php. The same changes but based off
php:7.3-cli-stretch and php:7.4-cli respectively. I can provide full php.ini of both which shows
nothing special going on...

I have generated a blackfire profile to show the issue:
* PHP 7.3 - https://blackfire.io/profiles/6b973d98-014a-4dd2-8b13-f0cf5842221c/graph
* PHP 7.4 - https://blackfire.io/profiles/c80f648b-a778-4b3c-8acf-00a628e1630f/graph

Comparison of PHP 7.3 against 7.4 - https://blackfire.io/profiles/compare/a2dfa36c-3203-4599-959b-95d87143776a/graph

--

I do note that since first running the tests (poss. PHP 7.4.4 or earlier) it was returning 4.16 GB
and on 7.4.5 it's now 3.89 GB so the memory leak fixes in recent releases has helped some
what...

Test script:
---------------
Unfortunately I cannot provide access to the code. It's a large Laravel application.

I would be grateful if based on the memory profiles someone could point in the right direction to
help debug the issue.

Expected result:
----------------
n/a

Actual result:
--------------
n/a


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=79519&edit=1


Thread (25 messages)

« previous php.bugs (#226812) next »