BitOne / php-meminfo

PHP extension to get insight about memory usage
MIT License
1.08k stars 78 forks source link

Memory leak not displayed in the dump #94

Closed goetas closed 5 years ago

goetas commented 5 years ago

First of all, this is a great extension, thank you. Is making my life really easier.

But here my issue... (looks rather similar to https://github.com/BitOne/php-meminfo/issues/54). As you pointed in https://github.com/BitOne/php-meminfo/issues/54 there might be an extension leak... or this extension is not able to detect some memory content.

However, running this:

for ($i = 0; $i<100; $i++){
  $func();
  echo round(memory_get_usage()/1024/1024, 6).PHP_EOL;
  gc_collect_cycles();
}
echo round(memory_get_usage()/1024/1024, 6).PHP_EOL;
meminfo_dump(fopen('dump_file_z.json', 'w'));

$func is a closure that runs a complete symfony 3.4 app.

Independently from how many iterations does the for loop, the dumped file looks always the same, but memory usage goes up ~2MB on each loop iteration (reaching my current 500MB memory limit).

Here the dump:

root@dad957857bb5:/opt/php-meminfo/analyzer# bin/analyzer summary dump.json 
+-------------------------------+-----------------+-----------------------------+
| Type                          | Instances Count | Cumulated Self Size (bytes) |
+-------------------------------+-----------------+-----------------------------+
| string                        | 1090            | 63384                       |
| array                         | 492             | 35424                       |
| integer                       | 281             | 4496                        |
| boolean                       | 39              | 624                         |
| null                          | 8               | 128                         |
| unknown                       | 5               | 80                          |
| Composer\Autoload\ClassLoader | 1               | 72                          |
| DateTimeZone                  | 1               | 72                          |
| Predis\Response\Status        | 1               | 72                          |
+-------------------------------+-----------------+-----------------------------+

Any idea on what could be?

goetas commented 5 years ago

Tried even disabling most of the PHP extensions... currently having:

PHP 7.2.13 (cli) (built: Dec 29 2018 05:15:58) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

[PHP Modules]
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
hash
iconv
intl
json
libxml
mbstring
mysqlnd
openssl
pcntl
pcre
PDO
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
xsl
zip
zlib

[Zend Modules]
goetas commented 5 years ago

Tried also with a hello-world 4.2 symfony and same result.

goetas commented 5 years ago

Interesting detail. Running gc_collect_cycles(); increases the memory..

for ($i = 0; $i<100; $i++){
  $func();

  if(($i%10)===0) {
      echo round(memory_get_usage()/1024/1024, 6).PHP_EOL;
      gc_collect_cycles();
 } 
}

Running gc_collect_cycles every 20 iterations makes ram go up 10x faster!

goetas commented 5 years ago

Seems a symfony issue, created ticket here https://github.com/symfony/symfony/issues/32220

goetas commented 5 years ago

Found the issue... https://bugs.php.net/bug.php?id=76982 :sob:

goetas commented 5 years ago

I guess that this in not fault/responsability of this library