Welcome! Log In Create A New Profile

Advanced

why does each children workers uses a copy of memory when using APC

Posted by Libok 
Following is the question I asked on https://answers.launchpad.net/php-fpm/+question/79947,
but get no reply, so I post it here again for any help. Thank you.
==========================================================================

[REFERENCE]
1) Refer to FAQ:
http://php-fpm.org/FAQ#Is_PHP-FPM_from_the_accelerator_ZendPlatform.2C_xcache.2C_eAccelerator.2C_APC.2C_etc..3F

It said: There is just one restriction: all the worker processes, will
use the same cache, even if the workers are started under a different
uid/gid.

2) http://pecl.php.net/bugs/bug.php?id=11988
the next to the last comment refereed that php-fpm may solves the
problem of "share cache between FAST CGI processes"

[ENVIRONMENT]
I have installed php-fpm-0.5.13 + nginx/0.7.61 + php5.2.10 + APC3.0.19
on Freebsd7.2.
and in php-fpm.conf I only changed following options according the php-
fpm.conf.default:
user=www
group=www
max_children=6

The APC configuration in php.ini is as follow:
apc.enabled="0"
apc.shm_size="30"

[BACKGROUND]
when I disable apc, each php-cgi consumes around of 20M memory.
Following is the top message when disable apc:

PID USERNAME THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
579 mysql 9 20 0 43748K 17548K sigwai 0:01 0.00% mysqld
13088 www 1 4 0 19352K 9164K accept 0:00 0.20% php-cgi
13090 www 1 4 0 19352K 9156K accept 0:00 0.10% php-cgi
13091 www 1 4 0 19352K 9156K accept 0:00 0.00% php-cgi
13086 www 1 4 0 19352K 9072K accept 0:00 0.00% php-cgi
13089 www 1 4 0 19352K 9068K accept 0:00 0.29% php-cgi
13087 www 1 4 0 19352K 9064K accept 0:00 0.00% php-cgi
13085 root 1 4 0 18328K 7968K kqread 0:00 0.00% php-cgi

However, if I enable apc, each php-cgi consumes around of 50M memory,
Following is the top message after enable apc:

PID USERNAME THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
579 mysql 9 20 0 43748K 17548K sigwai 0:01 0.00% mysqld
12754 www 1 4 0 53144K 16740K accept 0:04 0.00% php-cgi
12750 www 1 4 0 51096K 12184K accept 0:02 0.00% php-cgi
12751 www 1 4 0 50072K 11576K accept 0:02 0.00% php-cgi
12755 www 1 4 0 50072K 11100K accept 0:01 0.00% php-cgi
12752 www 1 4 0 50072K 11028K accept 0:01 0.00% php-cgi
12753 www 1 4 0 50072K 10580K accept 0:01 0.00% php-cgi
12749 root 1 4 0 49048K 8008K kqread 0:01 0.00% php-cgi

[QUESTION]
This means each php-cgi uses base 20M memory and also 30M apc cache
memory.
But the FAQ said it will share the same APC cache for each workers,
why did each worker uses a copy of cache individually?
Maybe there is something wrong with my configuration, any help will be
highly appreciated.
Also thank you very much for your effort of making this great product
"php-fpm".
Someone was asking that before - that time someone answered that everything
is ok. When counting size of each process, it is counted with its own size +
size of shared memory used (for each instance of php worker the same cache
shared memory is counted once again). But when you check how much less free
memory you have when APC activated everything should be ok.
Check this if its true :)

Marcin

2009/8/16 Libok

>
> Following is the question I asked on
> https://answers.launchpad.net/php-fpm/+question/79947,
> but get no reply, so I post it here again for any help. Thank you.
> ==========================================================================
>
> [REFERENCE]
> 1) Refer to FAQ:
>
> http://php-fpm.org/FAQ#Is_PHP-FPM_from_the_accelerator_ZendPlatform.2C_xcache.2C_eAccelerator.2C_APC.2C_etc..3F
>
> It said: There is just one restriction: all the worker processes, will
> use the same cache, even if the workers are started under a different
> uid/gid.
>
> 2) http://pecl.php.net/bugs/bug.php?id=11988
> the next to the last comment refereed that php-fpm may solves the
> problem of "share cache between FAST CGI processes"
>
> [ENVIRONMENT]
> I have installed php-fpm-0.5.13 + nginx/0.7.61 + php5.2.10 + APC3.0.19
> on Freebsd7.2.
> and in php-fpm.conf I only changed following options according the php-
> fpm.conf.default:
> user=www
> group=www
> max_children=6
>
> The APC configuration in php.ini is as follow:
> apc.enabled="0"
> apc.shm_size="30"
>
> [BACKGROUND]
> when I disable apc, each php-cgi consumes around of 20M memory.
> Following is the top message when disable apc:
>
> PID USERNAME THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
> 579 mysql 9 20 0 43748K 17548K sigwai 0:01 0.00% mysqld
> 13088 www 1 4 0 19352K 9164K accept 0:00 0.20% php-cgi
> 13090 www 1 4 0 19352K 9156K accept 0:00 0.10% php-cgi
> 13091 www 1 4 0 19352K 9156K accept 0:00 0.00% php-cgi
> 13086 www 1 4 0 19352K 9072K accept 0:00 0.00% php-cgi
> 13089 www 1 4 0 19352K 9068K accept 0:00 0.29% php-cgi
> 13087 www 1 4 0 19352K 9064K accept 0:00 0.00% php-cgi
> 13085 root 1 4 0 18328K 7968K kqread 0:00 0.00% php-cgi
>
> However, if I enable apc, each php-cgi consumes around of 50M memory,
> Following is the top message after enable apc:
>
> PID USERNAME THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
> 579 mysql 9 20 0 43748K 17548K sigwai 0:01 0.00% mysqld
> 12754 www 1 4 0 53144K 16740K accept 0:04 0.00% php-cgi
> 12750 www 1 4 0 51096K 12184K accept 0:02 0.00% php-cgi
> 12751 www 1 4 0 50072K 11576K accept 0:02 0.00% php-cgi
> 12755 www 1 4 0 50072K 11100K accept 0:01 0.00% php-cgi
> 12752 www 1 4 0 50072K 11028K accept 0:01 0.00% php-cgi
> 12753 www 1 4 0 50072K 10580K accept 0:01 0.00% php-cgi
> 12749 root 1 4 0 49048K 8008K kqread 0:01 0.00% php-cgi
>
> [QUESTION]
> This means each php-cgi uses base 20M memory and also 30M apc cache
> memory.
> But the FAQ said it will share the same APC cache for each workers,
> why did each worker uses a copy of cache individually?
> Maybe there is something wrong with my configuration, any help will be
> highly appreciated.
> Also thank you very much for your effort of making this great product
> "php-fpm".
>
@Marcin, Thank you for your kindly reply.
I don't know how to exactly check how much less free memory you have when
APC activated ?

Following is my caculation,

My server only have 300M memory, and I start php-fpm with 10 workers, and
each with 50M memory in top command. But I found there still have 17M Free
memory in top.
So did this means it actually uses: 20M (each php-fpm worker) x 10 + 30M
(apc cache) = 230M? which means everything is ok?

2009/8/17 Marcin Ochab

> Someone was asking that before - that time someone answered that everything
> is ok. When counting size of each process, it is counted with its own size +
> size of shared memory used (for each instance of php worker the same cache
> shared memory is counted once again). But when you check how much less free
> memory you have when APC activated everything should be ok.
> Check this if its true :)
>
> Marcin
>
> 2009/8/16 Libok
>
>
>> Following is the question I asked on
>> https://answers.launchpad.net/php-fpm/+question/79947,
>> but get no reply, so I post it here again for any help. Thank you.
>> ==========================================================================
>>
>> [REFERENCE]
>> 1) Refer to FAQ:
>>
>> http://php-fpm.org/FAQ#Is_PHP-FPM_from_the_accelerator_ZendPlatform.2C_xcache.2C_eAccelerator.2C_APC.2C_etc..3F
>>
>> It said: There is just one restriction: all the worker processes, will
>> use the same cache, even if the workers are started under a different
>> uid/gid.
>>
>> 2) http://pecl.php.net/bugs/bug.php?id=11988
>> the next to the last comment refereed that php-fpm may solves the
>> problem of "share cache between FAST CGI processes"
>>
>> [ENVIRONMENT]
>> I have installed php-fpm-0.5.13 + nginx/0.7.61 + php5.2.10 + APC3.0.19
>> on Freebsd7.2.
>> and in php-fpm.conf I only changed following options according the php-
>> fpm.conf.default:
>> user=www
>> group=www
>> max_children=6
>>
>> The APC configuration in php.ini is as follow:
>> apc.enabled="0"
>> apc.shm_size="30"
>>
>> [BACKGROUND]
>> when I disable apc, each php-cgi consumes around of 20M memory.
>> Following is the top message when disable apc:
>>
>> PID USERNAME THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
>> 579 mysql 9 20 0 43748K 17548K sigwai 0:01 0.00% mysqld
>> 13088 www 1 4 0 19352K 9164K accept 0:00 0.20% php-cgi
>> 13090 www 1 4 0 19352K 9156K accept 0:00 0.10% php-cgi
>> 13091 www 1 4 0 19352K 9156K accept 0:00 0.00% php-cgi
>> 13086 www 1 4 0 19352K 9072K accept 0:00 0.00% php-cgi
>> 13089 www 1 4 0 19352K 9068K accept 0:00 0.29% php-cgi
>> 13087 www 1 4 0 19352K 9064K accept 0:00 0.00% php-cgi
>> 13085 root 1 4 0 18328K 7968K kqread 0:00 0.00% php-cgi
>>
>> However, if I enable apc, each php-cgi consumes around of 50M memory,
>> Following is the top message after enable apc:
>>
>> PID USERNAME THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
>> 579 mysql 9 20 0 43748K 17548K sigwai 0:01 0.00% mysqld
>> 12754 www 1 4 0 53144K 16740K accept 0:04 0.00% php-cgi
>> 12750 www 1 4 0 51096K 12184K accept 0:02 0.00% php-cgi
>> 12751 www 1 4 0 50072K 11576K accept 0:02 0.00% php-cgi
>> 12755 www 1 4 0 50072K 11100K accept 0:01 0.00% php-cgi
>> 12752 www 1 4 0 50072K 11028K accept 0:01 0.00% php-cgi
>> 12753 www 1 4 0 50072K 10580K accept 0:01 0.00% php-cgi
>> 12749 root 1 4 0 49048K 8008K kqread 0:01 0.00% php-cgi
>>
>> [QUESTION]
>> This means each php-cgi uses base 20M memory and also 30M apc cache
>> memory.
>> But the FAQ said it will share the same APC cache for each workers,
>> why did each worker uses a copy of cache individually?
>> Maybe there is something wrong with my configuration, any help will be
>> highly appreciated.
>> Also thank you very much for your effort of making this great product
>> "php-fpm".
>>
>
>
Re: why does each children workers uses a copy of memory when using APC
June 07, 2011 09:50PM
This also baffled me for a long long while!!! The same thing with Eaccelerator - the memory keeps going up.
It crashes sometimes or hang there, the php-cgis would be unresponsive.

I assume each child somehow got a copy of the APC used memory.
Re: why does each children workers uses a copy of memory when using APC
June 08, 2011 10:31AM
I'd suggest you to compile APC without mmap, use SHM instead

./configure --enable-apc --disable-apc-mmap --enable-apc-memprotect

APC 3.1.7 works fine, not leaking anything with php-fpm 5.3.x

[APC]
apc.enabled = "1"
apc.shm_size = "16M"
apc.shm_segments = "4"
apc.ttl = "90"
apc.user_ttl = "300"
apc.gc_ttl = "600"
apc.cache_by_default = "On"
apc.filters = ""
apc.max_file_size = "1M"
apc.stat = "1"


Another hint: If you are with low RAM, its better to use EAccelerator instead
Re: why does each children workers uses a copy of memory when using APC
June 09, 2011 06:04PM
Thanks for the reply. Nice person.
The EA leaks memory a lot with PHP5.2.14, could you point a link to php-fpm 5.3.x? That was why I converted to APC.
So if each PHP-CGI uses 10m by itself, how much would you expect if you turn on the EA with SHM=64M say?

Why shm is better than mmap?
apc.stat = "1" will this slow down the APC significantly since every time it has to check whether php scripts have been updated?
Re: why does each children workers uses a copy of memory when using APC
June 09, 2011 06:24PM
Also why the apc.shm_segments is set to be 4?
Re: why does each children workers uses a copy of memory when using APC
June 09, 2011 07:00PM
Just tried that with ./configure --enable-apc --disable-apc-mmap --enable-apc-memprotect

The memory still growing (compared with the 10M without APC), now it is 25M (top command RES) after 10mins run.

So going back the the original post, why 25M?
Re: why does each children workers uses a copy of memory when using APC
June 10, 2011 12:46AM
Now after 5hrs run, top command shows: (large VIRT, more than 40m php-cgi each process). SHR is about 35,
I set apc_shm =128M .

29510 wwebusr 15 0 413m 41m 35m S 7.3 0.5 0:33.38 php-cgi
29685 wwebusr 16 0 410m 39m 34m S 5.3 0.5 0:31.87 php-cgi
29514 wwebusr 15 0 413m 39m 33m S 4.0 0.5 0:30.69 php-cgi
29604 wwebusr 15 0 415m 42m 34m S 4.0 0.5 0:35.80 php-cgi
29541 wwebusr 15 0 415m 43m 35m S 3.6 0.5 0:34.91 php-cgi
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 308
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready