php-meminfo icon indicating copy to clipboard operation
php-meminfo copied to clipboard

Don't see memory leack in memory dump

Open Shkarbatov opened this issue 7 years ago • 9 comments

Hi, I have memory leack in my workers.

I have done memory_get_usage() on each iteration: 50183840 91469968 95433592 99533688 103630880 107729448 .. 378392128

Also I have done memory dump by meminfo: meminfo_dump(fopen('/home/dmitriy/phpmem/my_dump_file_'.$i.'.json', 'w'));

But when I compare files with 2 and 43 iteration almost nothing changed.

I attached two files fith 2 and 43 iteration. https://drive.google.com/open?id=1amDpzmyIel0QWdYqZp64F-f5L5fisqvC

Any ideas, why I don't see anything?

Shkarbatov avatar Dec 28 '17 15:12 Shkarbatov

Hi @Shkarbatov ,

It's difficult to tell exactly what is happening. It could be one of the following reason:

  • you didn't reach yet 10.000 items in the GC buffer, so the Garbage Collector didn't run yet (see https://speakerdeck.com/bitone/hunting-down-memory-leaks-with-php-meminfo to get more details on how PHP frees memory). Try to force the GC collection by calling gc_collect_cycles http://php.net/manual/en/function.gc-collect-cycles.php. PHP Meminfo records only "reacheable objects", so objects than can be collected by the GC, but not yet collected would not be seen by PHP Meminfo.
  • sometimes a memory leak in PHP can comes from one of its extension. In this case, PHP Meminfo would not be able to see it because the items responsible for the leaks will not be part of the PHP program memory. This can be the case of buffered queries that get a lot of records. See http://php.net/manual/en/mysqlinfo.concepts.buffering.php for more information.

BitOne avatar Dec 31 '17 21:12 BitOne

you didn't reach yet 10.000 items in the GC buffer,

I try it with the GC: gc_collect_cycles(); meminfo_dump(fopen('/home/dmitriy/phpmem/my_dump_file_'.$i.'.json', 'w'));

Result is the same.

Shkarbatov avatar Jan 02 '18 12:01 Shkarbatov

sometimes a memory leak in PHP can comes from one of its extension.

I understand this, but if I see difference in meminfo dump, isn't it's don't mean that I can see difference in meminfo?

For 2 iteration:

string - 30415 - 1271927
array - 16665 - 1199880
null - 6708 - 107328
boolean - 5667 - 90672
integer - 3025 - 48400

For 43 iteration:

string - 32970 - 1345086
array - 18103 - 1303416
null - 6720 - 107520
boolean - 5937 - 94992
integer - 3117 - 49872

Shkarbatov avatar Jan 02 '18 14:01 Shkarbatov

If XHProf show me, there is no any difference in memory between 2 and 43 iteration, but memory_get_usage() show that memory is rising. What it can be? GC run in each iteration.

Shkarbatov avatar Jan 02 '18 15:01 Shkarbatov

Maybe you have a small leak of PHP items that you can see in phpMeminfo and a big leak coming from an extension. Can you provide the two full dump files instead of the summaries (for your iterations 2 and 43) ?

BitOne avatar Jan 04 '18 14:01 BitOne

Adding dumps 3 and 389 iteration: https://drive.google.com/drive/folders/1izeyMBlf85y09Or0BeCd70yfqE8_ygWb?usp=sharing

Shkarbatov avatar Jan 04 '18 15:01 Shkarbatov

In example there is Symfony\Component\Stopwatch\StopwatchPeriod, I disabled it and repeated script - result is the same.

Shkarbatov avatar Jan 05 '18 06:01 Shkarbatov

Is there any update on this? i have the same situation but cannot solve it...

shxofficial avatar Jul 11 '18 22:07 shxofficial

Hey @Shkarbatov and @shxofficial ,

Do you have any code that you could share so we can reproduce the issue?

By the way, I'm thinking of adding an option to dump the content of the strings. Would that be helpful for you?

BitOne avatar Aug 06 '18 09:08 BitOne