0

I've installed LEMP stack on my server. My server have 1GB of RAM with no load. I've installed php-fpm and it looks like it's using most of the RAM of my server.

I've used the below command to get the list of running programs:

ps aux

and the results produced by this command are:

[user@server]$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  19232  1348 ?        Ss   Aug23   0:00 init
root         2  0.0  0.0      0     0 ?        S    Aug23   0:00 [kthreadd/145]
root         3  0.0  0.0      0     0 ?        S    Aug23   0:00 [khelper/145]
root       125  0.0  0.0  10640   476 ?        S<s  Aug23   0:00 /sbin/udevd -d
root       462  0.0  0.1 183552  1936 ?        Sl   Aug23   0:00 /sbin/rsyslogd
root       476  0.0  0.1  66256  1200 ?        Ss   Aug23   0:00 /usr/sbin/sshd
root       483  0.0  0.0  22136   988 ?        Ss   Aug23   0:00 xinetd -stayali
root       519  0.0  0.1  11304  1532 ?        S    Aug23   0:00 /bin/sh /usr/bi
mysql      726  0.0  4.6 781640 49200 ?        Sl   Aug23   3:30 /usr/libexec/my
root       765  0.0  0.0  66444   968 ?        Ss   Aug23   0:00 /usr/sbin/sasla
root       767  0.0  0.0  66444   660 ?        S    Aug23   0:00 /usr/sbin/sasla
root       784  0.0  0.2  82496  2360 ?        Ss   Aug23   0:07 sendmail: accep
smmsp      792  0.0  0.1  78228  2072 ?        Ss   Aug23   0:00 sendmail: Queue
root       802  0.0  0.4 278324  4472 ?        Ss   Aug23   0:11 php-fpm: master
nginx      804  0.0  5.5 305848 58388 ?        S    Aug23   0:18 php-fpm: pool w
nginx      805  0.0  5.4 305528 57432 ?        S    Aug23   0:18 php-fpm: pool w
nginx      806  0.0  5.4 304972 57440 ?        S    Aug23   0:19 php-fpm: pool w
nginx      807  0.0  5.9 308032 62004 ?        S    Aug23   0:19 php-fpm: pool w
nginx      808  0.0  5.2 298328 55292 ?        S    Aug23   0:19 php-fpm: pool w
root       818  0.0  0.4  96768  4812 ?        Ss   Aug23   0:00 nginx: master p
root       829  0.0  0.1  20412  1264 ?        Ss   Aug23   0:01 crond
nginx      852  0.0  5.3 299400 55724 ?        S    Aug23   0:18 php-fpm: pool w
nginx     1054  0.0  5.6 305744 59072 ?        S    Aug23   0:17 php-fpm: pool w
nginx     4211  0.0  5.8 308008 60992 ?        S    Aug23   0:17 php-fpm: pool w
nginx     4215  0.0  5.7 308332 60720 ?        S    Aug23   0:17 php-fpm: pool w
nginx     4216  0.0  5.6 305840 59300 ?        S    Aug23   0:18 php-fpm: pool w
root     13238  0.0  0.4  95924  4232 ?        Ss   19:41   0:00 sshd: user [pr
user    13242  0.0  0.1  95924  1828 ?        S    19:41   0:00 sshd: user@pts
user    13243  0.0  0.1  11440  1816 pts/0    Ss   19:41   0:00 -bash
nginx    13488  0.0  0.3  97184  3416 ?        S    21:07   0:00 nginx: worker p
nginx    13489  0.0  0.3  97184  3416 ?        S    21:07   0:00 nginx: worker p
nginx    13490  0.0  0.3  97448  4064 ?        S    21:07   0:00 nginx: worker p
nginx    13491  0.0  0.3  97184  3416 ?        S    21:07   0:00 nginx: worker p
user    13508  0.0  0.1  13372  1060 pts/0    R+   21:13   0:00 ps aux

As you can see guys, php-fpm process is using lots of RAM. Tell me what to do to optimize php-fpm and reduce the memory consumption of my server.

4 Answers 4

3

php-fpm by default can have a very large number of child servers running... Each of these can take 20-30 megs of ram, which can easily add up...

The simplest thing to do would be to reduce the default starting servers, and the max servers in the php-fpm conf for your server...

The file to edit would typically be /etc/php-fpm.d/www.conf. Typical settings for a smaller website would be

pm.max_children = 10
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 3

Obviously, you would want to read the documentation (or at least the comments in the default conf file), however these sample settings should start with around 90-100MB and reach a max of around 300-400MB when all the children are up and running.

Depending on your needs, you should play around with these numbers as appropriate. (Test configs and real world ram usage based on traffic).

2

~60MB for each process is not a strange value.

If you need to consume less memory, you can decrease the number of workers of your pool.

1
  1. ps cannot exactly show you how much memory is used, check with this:

    http://www.pixelbeat.org/scripts/ps_mem.py

  2. set memory_limit in php.ini

0

For each of the configuration files listed in:

php --ini

One by one, comment out the extension lines of modules you don't use:

; extension=redis.so

Restart php-fpm each time.

Also, if APC or other optimizer is installed each instance is eating up N MB of RAM, as configured in apc.ini.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .