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
, 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:
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
, 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:
thanks, I'll review the patch. But I don't have time right now. It's
in my todo list.
++ Jerome
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
, 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:
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
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
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.
thanks,
looyao
2010/4/14 Rasmus Lerdorf rasmus@lerdorf.com
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
2010/4/15 滕路遥 tly.phpfans@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 ?
thanks,
looyao2010/4/14 Rasmus Lerdorf rasmus@lerdorf.com
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
2010/4/15 Jérôme Loyet jerome@loyet.net
2010/4/15 滕路遥 tly.phpfans@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,
looyao2010/4/14 Rasmus Lerdorf rasmus@lerdorf.com
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
2010/4/15 Jérôme Loyet jerome@loyet.net
2010/4/15 滕路遥 tly.phpfans@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:
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
Btw: did you know about
http://php.net/manual/en/function.apache-child-terminate.php I just noticed
a few days ago, obviously, you can't use with cgi/fastcgi/php-fpm but for
apache, it does exactly what you need, except that you have to execute from
userland.
So I think it would be a good idea, to generally implement a soft/hard limit
for memory allocation: if soft fails, the process terminates after the
request, if the hard limit fails, it is terminated instantly.
Tyrael
2010/4/15 Ferenc Kovacs tyra3l@gmail.com:
2010/4/15 Jérôme Loyet jerome@loyet.net
2010/4/15 滕路遥 tly.phpfans@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:
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
Btw: did you know about
http://php.net/manual/en/function.apache-child-terminate.php I just noticed
a few days ago, obviously, you can't use with cgi/fastcgi/php-fpm but for
apache, it does exactly what you need, except that you have to execute from
userland.
This function is interesting but it's called from php scripts. When
you are a sysadmin who host hundreds of different customers, you can't
garanty each customer will call this function each time he uses
consomption scripts.
2010/4/15 Ferenc Kovacs tyra3l@gmail.com:
2010/4/15 Jérôme Loyet jerome@loyet.net
2010/4/15 滕路遥 tly.phpfans@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:
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
Btw: did you know about
http://php.net/manual/en/function.apache-child-terminate.php I just
noticed
a few days ago, obviously, you can't use with cgi/fastcgi/php-fpm but for
apache, it does exactly what you need, except that you have to execute
from
userland.This function is interesting but it's called from php scripts. When
you are a sysadmin who host hundreds of different customers, you can't
garanty each customer will call this function each time he uses
consomption scripts.
Yeah, I know, and I think I did mention that, but this sounds like a good
feature in the language, but sadly it has too many limitation in it's
current form. (no windows support, only works with apache)
Tyrael
2010/4/15 Ferenc Kovacs tyra3l@gmail.com:
2010/4/15 Ferenc Kovacs tyra3l@gmail.com:
2010/4/15 Jérôme Loyet jerome@loyet.net
2010/4/15 滕路遥 tly.phpfans@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:
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
Btw: did you know about
http://php.net/manual/en/function.apache-child-terminate.php I just
noticed
a few days ago, obviously, you can't use with cgi/fastcgi/php-fpm but
for
apache, it does exactly what you need, except that you have to execute
from
userland.This function is interesting but it's called from php scripts. When
you are a sysadmin who host hundreds of different customers, you can't
garanty each customer will call this function each time he uses
consomption scripts.Yeah, I know, and I think I did mention that, but this sounds like a good
feature in the language, but sadly it has too many limitation in it's
current form. (no windows support, only works with apache)
I see how soft_limit could work (after processing a page, memory is
checked and if it's more than the soft limit, the process is killed).
But how can you make the hard_limit to work ? You'll have to setup
memory check for each process by a master process, because the child
won't be able to check it's memory realtime (or I missed something)
++ Jerome
2010/4/15 Ferenc Kovacs tyra3l@gmail.com:
2010/4/15 Ferenc Kovacs tyra3l@gmail.com:
On Thu, Apr 15, 2010 at 9:09 AM, Ferenc Kovacs tyra3l@gmail.com
wrote:2010/4/15 Jérôme Loyet jerome@loyet.net
2010/4/15 滕路遥 tly.phpfans@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:
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
Btw: did you know about
http://php.net/manual/en/function.apache-child-terminate.php I just
noticed
a few days ago, obviously, you can't use with cgi/fastcgi/php-fpm but
for
apache, it does exactly what you need, except that you have to execute
from
userland.This function is interesting but it's called from php scripts. When
you are a sysadmin who host hundreds of different customers, you can't
garanty each customer will call this function each time he uses
consomption scripts.Yeah, I know, and I think I did mention that, but this sounds like a good
feature in the language, but sadly it has too many limitation in it's
current form. (no windows support, only works with apache)I see how soft_limit could work (after processing a page, memory is
checked and if it's more than the soft limit, the process is killed).
But how can you make the hard_limit to work ? You'll have to setup
memory check for each process by a master process
This is what the proposed php-fpm patch does, or am I missing something?
, because the child
won't be able to check it's memory realtime (or I missed something)++ Jerome
If we talking about my proposal(to kill/set to kill the worker from inside
the request), then maybe you are right, I don't know much about the internal
memory management system, but you are saying, that there is no way to tell
the worker's memory consumption from inside the php userland?
there are functions like memory_get_usage()
, memory_get_peak_usage()
, and
there are ways in every OS to tell the ~ memory consumption of a given
process.
Am I missing something?
Tyrael
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.
Sounds like you more or less want a "request_terminate_timeout" type
of functionality but based on memory. Since set_time_limit()
and other
things in PHP don't seem to force kill the process. So PHP-FPM
forcefully terminates the process based on the actual wall clock
seconds.
I'm thinking you're hoping for the same thing to be possible but for
memory limits per-process? I would say that could be cool, either per
pool or per child somehow. No clue if it is possible, but that would
be a great way to limit the usage forcefully - helpful on lower
resource machines (like a vps...)
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.Sounds like you more or less want a "request_terminate_timeout" type
of functionality but based on memory. Sinceset_time_limit()
and other
things in PHP don't seem to force kill the process. So PHP-FPM
forcefully terminates the process based on the actual wall clock
seconds.Unfortunately I don't know how PHP-FPM handles it's worker pool, but as far
as with goes with apache php_prefork and fastcgi you can limit how many
request should one worker process, but it will be a good option to limit the
process lifetime based on the memory consumption.
I'm thinking you're hoping for the same thing to be possible but for
memory limits per-process? I would say that could be cool, either per
pool or per child somehow.
Yeah.
No clue if it is possible, but that would
be a great way to limit the usage forcefully - helpful on lower
resource machines (like a vps...)
Its possible, the patch adds this functionality to the php-fpm.
but I started thinking about, that the possibility to terminate (I mean
really terminate, not just abort the execution of the current request) the
worker would be a good feature in the php language itself.
Tyrael
When allocate memory from PHP memory heap, PHP runtime check the
memory_limit which
in php.ini, but this can only give a error message and not to continue to
excute php code, it can't
control the PHP-FPM child process, my idea is that when the memory out of
limit we set,
kill this child process, we know, though PHP runtime can free its heap
memory, but it can't give
it back to the system, so we can kill this child process and ensure the
system have enough free
memory. We do check the memory limit is to control the process.
2010/4/15 Jérôme Loyet jerome@loyet.net
2010/4/15 滕路遥 tly.phpfans@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 ?thanks,
looyao2010/4/14 Rasmus Lerdorf rasmus@lerdorf.com
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
2010/4/14 Rasmus Lerdorf rasmus@lerdorf.com
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.
does someone know a way to get the memory usage of the current process ?
getrusage is not accurate in linux.
Thx
++ jerome
in linux, read the /proc/self(pid)/status, and the VmRSS(real memory usage)
or VmSize(virtual memory usage) is the the memory usage of the current
process.
2010/4/24 Jérôme Loyet jerome@loyet.net
2010/4/14 Rasmus Lerdorf rasmus@lerdorf.com
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.does someone know a way to get the memory usage of the current process ?
getrusage is not accurate in linux.Thx
++ jerome
Le 26 avril 2010 04:02, looyao teng tly.phpfans@gmail.com a écrit :
in linux, read the /proc/self(pid)/status, and the VmRSS(real memory usage)
or VmSize(virtual memory usage) is the the memory usage of the current
process.
in fact I was looking of a cleaner way to do it.
2010/4/24 Jérôme Loyet jerome@loyet.net
2010/4/14 Rasmus Lerdorf rasmus@lerdorf.com
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.does someone know a way to get the memory usage of the current process ?
getrusage is not accurate in linux.Thx
++ jerome
Hello !
in linux, read the /proc/self(pid)/status, and the VmRSS(real memory usage)
or VmSize(virtual memory usage) is the the memory usage of the current
process.in fact I was looking of a cleaner way to do it.
Moreover, this solution is not available on OS like *BSD...
Best regards,
Fred.
hi,
thank you for reading my suggestion, and now I hope that PHP_FPM can
add process control to prevent from system memory running out.
There are many ways to do this, my patch is to check the PHP heap memory,
this is very easy. We can also control the child process's life time, all I
need
is to control the FPM child process, so ensure my system have enough free
memory, and I think many people also need this feature.
thanks.
looyao
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).
I personally don't think this belongs to any SAPI.
How about adding another ini option to PECL/memtrack to not just throw a warning,
but terminate the process when it hits some limit?
--
Wbr,
Antony Dovgal
http://pinba.org - realtime statistics for PHP
2010/4/15 Antony Dovgal tony@daylessday.org:
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).I personally don't think this belongs to any SAPI.
How about adding another ini option to PECL/memtrack to not just throw a warning,
but terminate the process when it hits some limit?
In fork processes it could be great but when dealing with threads it won't work
2010/4/15 Antony Dovgal tony@daylessday.org:
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).I personally don't think this belongs to any SAPI.
How about adding another ini option to PECL/memtrack to not just throw a warning,
but terminate the process when it hits some limit?In fork processes it could be great but when dealing with threads it won't work
Adding this to FPM won't help anyway - FPM doesn't use threads.
--
Wbr,
Antony Dovgal
http://pinba.org - realtime statistics for PHP
2010/4/15 Antony Dovgal tony@daylessday.org
2010/4/15 Antony Dovgal tony@daylessday.org:
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).I personally don't think this belongs to any SAPI.
How about adding another ini option to PECL/memtrack to not just throw a
warning,
but terminate the process when it hits some limit?In fork processes it could be great but when dealing with threads it
won't workAdding this to FPM won't help anyway - FPM doesn't use threads.
You meant won't hurt?
Tyrael
Adding this to FPM won't help anyway - FPM doesn't use threads.
You meant won't hurt?
No, I mean implementing it in PECL/memtrack would be better since this way you add it to all non-threaded SAPIs.
While adding it to FPM means that other non-threaded SAPIs will have to do it in an other way.
--
Wbr,
Antony Dovgal
http://pinba.org - realtime statistics for PHP
Adding this to FPM won't help anyway - FPM doesn't use threads.
You meant won't hurt?
No, I mean implementing it in PECL/memtrack would be better since this way
you add it to all non-threaded SAPIs.
While adding it to FPM means that other non-threaded SAPIs will have to do
it in an other way.Yeah, this could be implemented there, but it seems that its not actively
developed, last release 0.1 beta more than a year ago.
But as you say, it would be a huge benefit, to add this feature for all
non-threaded SAPI.
Tyrael
Yeah, this could be implemented there, but it seems that its not
actively developed, last release 0.1 beta more than a year ago.
In this case 'not actively developed' means 'it works and no bugs were found/reported',
so I don't see it as a disadvantage.
--
Wbr,
Antony Dovgal
http://pinba.org - realtime statistics for PHP
Yeah, this could be implemented there, but it seems that its not
actively developed, last release 0.1 beta more than a year ago.In this case 'not actively developed' means 'it works and no bugs were
found/reported',
so I don't see it as a disadvantage.If this is the case, then it should be stable for now, isn't it?
Tyrael
If this is the case, then it should be stable for now, isn't it?
I guess you can call it that, yes.
--
Wbr,
Antony Dovgal
http://pinba.org - realtime statistics for PHP
If this is the case, then it should be stable for now, isn't it?
I guess you can call it that, yes.
I mean this should be reflected in the pecl package status field.
Tyrael