Re: One suggestion to PHP-FPM
| From: | Jérôme Loyet | Date: | Wed, 14 Apr 2010 09:01:24 +0000 |
| Subject: | Re: One suggestion to PHP-FPM | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-47938@lists.php.net to get a copy of this message | ||
Le 14 avril 2010 09:29, Jérôme Loyet <jerome@loyet.net> a écrit :
> 2010/4/6 滕路遥 <tly.phpfans@gmail.com>:
>> hi,
>>
>> We use PHP's Imagemagick extension to process images, and this would
>> consume a lot of memory under some circumstances.
>> However, the mainstream PHP's memory management is really weak, so a
>> huge amount of memory would be consumed under high server load. What's
>> worse, this even cause our server to crash frequently.
>>
>> So I suggest that if we could add a config option to PHP-FPM, so that
>> PHP-FPM could just kill a PHP process if it consumes too much memory
>> (say more than 256M).
>> This would prevent PHP from consuming a lot of memory which couldn't
>> be freed later.
>>
>> For example, assuming that this option is "exit_on_memory_exceeds",
>> and I set it to 256M. Also, I set PHP's "memory_limit" option to
>> 1024M.
>> I would expect PHP-FPM to kill the PHP process which consumes more
>> than 256M memory, even though PHP could use up to 1024M memory.
>> We have discussed this idea with the author of PHP-FPM,url is
>>
>> http://groups.google.com/group/highload-php-en/browse_thread/thread/1882a3b2257dcc5c/ea73892cea011541?lnk=gst&q=gaochunhui#ea73892cea011541!„
>> QÃèJÈ/f �
>> , and now I have reach my goal by patching the source code of PHP-FPM. So
>> we can edit the php-fpm.conf and add one item such as "<value
>> name="term_on_memory_limit">3145728</value>" in the
>> "global_options" section,
>> when PHP's memory beyond this limit,child process will exit.
>>
>> mypatch.diff
>> http://docs.google.com/leaf?id=0B-ig5wUi7GTMZTUxYjg1ZTQtOGQ5Zi00N2Q1LTkxODYtYWQ4Y2FiMzhlOWM5&hl=en<%20http://docs.google.com/leaf?id=0B-ig5wUi7GTMZTUxYjg1ZTQtOGQ5Zi00N2Q1LTkxODYtYWQ4Y2FiMzhlOWM5&hl=en>
>> This patch is for
>>
>> http://svn.php.net/repository/php/php-src/branches/PHP_5_3_FPM
>> version:
>> 294187.
>>
>
> thanks, I'll review the patch. But I don't have time right now. It's
> in my todo list.
The patch seems good (I didn't test it yet) but I'm curious about the
way you check the memory real size:
+ if(zend_memory_usage(1 TSRMLS_CC) >
fpm_global_config.term_on_memory_limit){
I don't know much about the zend_memory_usage() function. But does it
return the real memory size of the process ?
ZEND_API size_t zend_memory_usage(int real_usage TSRMLS_DC)
{
if (real_usage) {
return AG(mm_heap)->real_size;
} else {
size_t usage = AG(mm_heap)->size;
#if ZEND_MM_CACHE
usage -= AG(mm_heap)->cached;
#endif
return usage;
}
}
It seems it return the zend heap size. I don't know if it's the same
as the process heap size.
++ Jerome