W
W
WoZ2012-03-12 18:42:19
PHP
WoZ, 2012-03-12 18:42:19

Memory consumption after update from PHP 5.2 to 5.3?

I ran into something strange after updating from 5.2 to 5.3 (5.2.10 to 5.3.10, mod_php, x86_64). There are heavy scripts that consume a lot of memory, on 5.2 there was a 2GB memory limit for scripts, on 5.3 they fall due to lack of memory. Experimentally established that after the update, where less than 2GB used to be enough, now 8.6GB is required.
I googled it and didn't find anything similar, maybe someone else has experienced something similar? There is no mention of increased consumption in the release notes.
Unfortunately, I can’t profile the same code on 5.2, now on 5.3 for each element of the array, where the element is stdClass with three fields of 25 characters on average, it consumes under 1kb of memory, which is outrageously a lot.
UPD. curl is not used, etc., the problem is clearly different. I see two options: 1) memory consumption for stdClass objects has increased; 2) gc for some unknown reason does not clean up memory.
UPD2 . After many tests, it was found that gc is not to blame, it is in 5.3 that the memory consumption is unrealistic and exceeds all possible limits. This PHP code consumes 3181MB of memory, but the python code (2.6.6) consumes only 1648MB of memory. But python code takes 1 min 38 sec while php code takes 14 sec. Offtopic, but why does python code work so slowly? On python 3.2.2, the time is 16.3 sec, and the memory consumption is 2352MB. The global trend towards increasing memory consumption.

Answer the question

In order to leave comments, you need to log in

9 answer(s)
H
homm, 2012-03-12
@WoZ

Don't you think that you have chosen the wrong tool for your task?

E
edogs, 2012-03-12
@edogs

Google says something crazy “PHP 5.3.0 and up has a better garbage collector but it is disabled by default. To enable it, you must call gc_enable() once.", but maybe that's the issue?

V
Vlad Zhivotnev, 2012-03-12
@inkvizitor68sl

Hm. And how did you set the limit to 9 GB? Does it fall into a segfault at a limit higher than 2.3?

P
prairie_dog, 2012-03-12
@prairie_dog

I somehow accidentally forgot code that had recursion in it. On 5.2 - this script worked and reached the memory limit, under 5.3 it worked similarly, but the memory limit was reached faster. All the memory, I believe, was spent on remembering the return point and, possibly, on the context. Tell us more about the script, what libraries are used, if the mentioned curl, at least the line on which the limit is reached.

E
Eternalko, 2012-03-12
@Eternalko

> For each element of the array.
It looks like there's a problem here. This is most likely garbage collector junk.
Try measuring memory consumption on the test set with:

echo memory_get_usage() / 1024 / 1024;

And then in the cycles where the data is used, try to put unset handles everywhere.

A
Anatoly, 2012-03-12
@taliban

1. habrahabr.ru/blogs/php/137860/ - This method will slightly reduce memory consumption, but this is provided that only work with the database survives the memory
2. php.net/manual/ru/function.mysql-free-result.php Pay attention to the last comment (according to chronology, it is the first) Moreover, the second comment from the top confirms the same glitch. Check out this option too.

V
vivo, 2012-03-15
@vivo

$ python -V
Python 2.7.2+
$ time python py.py
Memory used: 900.89MB
real 0m13.582s
user 0m12.929s
sys 0m0.588s
$ php -v
PHP 5.3.6-13ubuntu3.6 with Suhosin-Patch (cli ) (built: Feb 11 2012 02:17:16)
$ time php php.php
Memory used: -1742.00 MB
real 0m13.998s
user 0m12.365s
sys 0m1.512s

S
Sergey Beresnev, 2012-03-31
@sectus

After your question, I was looking for the reason for such an increase in memory and found an interesting article, here is its translation .

S
Sannis, 2012-03-13
@Sannis

Well, it’s good that they didn’t switch to 5.3. It will be necessary to rummage before this, why this is happening.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question