Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:47938 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27996 invoked from network); 14 Apr 2010 09:01:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Apr 2010 09:01:29 -0000 Authentication-Results: pb1.pair.com smtp.mail=jerome@loyet.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=jerome@loyet.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain loyet.net from 209.85.218.219 cause and error) X-PHP-List-Original-Sender: jerome@loyet.net X-Host-Fingerprint: 209.85.218.219 mail-bw0-f219.google.com Received: from [209.85.218.219] ([209.85.218.219:63543] helo=mail-bw0-f219.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5F/9E-07606-86485CB4 for ; Wed, 14 Apr 2010 05:01:29 -0400 Received: by bwz19 with SMTP id 19so30941bwz.1 for ; Wed, 14 Apr 2010 02:01:25 -0700 (PDT) MIME-Version: 1.0 Received: by 10.239.135.83 with HTTP; Wed, 14 Apr 2010 02:01:24 -0700 (PDT) In-Reply-To: References: Date: Wed, 14 Apr 2010 11:01:24 +0200 Received: by 10.102.182.28 with SMTP id e28mr3916178muf.78.1271235684953; Wed, 14 Apr 2010 02:01:24 -0700 (PDT) Message-ID: To: =?UTF-8?B?5ruV6Lev6YGl?= Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] One suggestion to PHP-FPM From: jerome@loyet.net (=?ISO-8859-1?B?Suly9G1lIExveWV0?=) Le 14 avril 2010 09:29, J=C3=A9r=C3=B4me Loyet a =C3=A9c= rit : > 2010/4/6 =E6=BB=95=E8=B7=AF=E9=81=A5 : >> 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/1882= a3b2257dcc5c/ea73892cea011541?lnk=3Dgst&q=3Dgaochunhui#ea73892cea011541 >> , and now I have reach my goal by patching the source code of PHP-FPM. S= o >> we can edit the php-fpm.conf and add one item such as "> name=3D"term_on_memory_limit">3145728" in the "global_options" s= ection, >> when PHP's memory beyond this limit,child process will exit. >> >> mypatch.diff http://docs.google.com/leaf?id=3D0B-ig5wUi7GTMZTUxYjg1ZTQtO= GQ5Zi00N2Q1LTkxODYtYWQ4Y2FiMzhlOWM5&hl=3Den<%20http://docs.google.com/leaf?= id=3D0B-ig5wUi7GTMZTUxYjg1ZTQtOGQ5Zi00N2Q1LTkxODYtYWQ4Y2FiMzhlOWM5&hl=3Den> >> =C2=A0This 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 =3D AG(mm_heap)->size; #if ZEND_MM_CACHE usage -=3D 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