2010/4/15 Jérôme Loyet <jer...@loyet.net>

> 2010/4/15 滕路遥 <tly.phpf...@gmail.com>:
> > We check error log after our server crashed, and we found that php heap
> > memory is out of limit,
> > so I think imagick use emalloc to allocate php heap memory, to check the
> > zend_memory_usage is
> > not a method for imagick, other circumstances which occupy huge memory
> can
> > use this method to
> > ensure the system have enough free memory.
>
> OK,
>
> one thing I didn't understand is "why should you want check de zend
> memory usage when there is a memory_limit parameter in PHP.ini " ?
> does'nt it do the same at PHP layer when allocating ?
>
>
Obviously you didn't read the original mail, and the links inside:
http://groups.google.com/group/highload-php-en/browse_thread/thread/1882a3b2257dcc5c/ea73892cea011541?lnk=gst&q=gaochunhui#ea73892cea011541

The problem here is that PHP wouldn't free any allocated memory untill
the process exits, so there's the risk of memory exhaustion if too
many PHP processes were running, even though each process wouldn't
exceed PHP's memory_limit.

My suggestion is more about releasing the allocated memory as soon as
possible. That is, this option is similar to "max_requests".
PHP-FPM would kill the PHP process if the requests a process handled
exceed max_requests, and similarly, PHP-FPM should kill the PHP
process whose memory usage exceeds "exit_on_memory_exceeds".

So one of your lib (for example imagick) leaks memory, on the long run, it
will exhaust the memory limit, and will kill a totaly request.
You can set that how many request should be served with one worker, but you
can't soft limit it's memory consumption.
This is what the patch does:
if you set the hard limit: (memory_limit) you can guarante that no process
will use more memory, because if it tries, it will fail.
and you can set soft limit, if that reached, the process will die and
respawn after finishing the current request.

Tyrael

> >
> > thanks,
> >     looyao
> >
> > 2010/4/14 Rasmus Lerdorf <ras...@lerdorf.com>
> >>
> >> On 04/14/2010 02:01 AM, Jérôme Loyet wrote:
> >> > 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 ?
> >>
> >> Right, that will only give you the memory allocated by the memory
> >> manager, obviously.  But, pecl/imagick does seem to use emalloc to
> >> allocate the imagick objects.  However, if the underlying magickwand
> >> library mallocs a bunch of temporary space on its own, this will not get
> >> picked up.
> >>
> >> -Rasmus
> >
> >
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Reply via email to