N
N
Nepofigist2011-03-22 12:47:00
PHP
Nepofigist, 2011-03-22 12:47:00

Nginx + php-fpm eating too much memory?

Good afternoon, Habr!
Server: cloud 16 cores x 2.66 GHz / 512 RAM / 10Gb HDD.
Webmin testimonials.

Физической памяти: всего 519.81 MB / свободно 347.23 MB Виртуальной памяти: всего 1023.99 MB / свободно 1023.92 MB

PhpSysInfo script readings.
Физическая память: занято 81%, свободно 98.93 MiB, занято 420.89 MiB, всего 519.81 MiB.

The result of executing the free command is the same as PhpSysInfo.
Server - Debian 6, nginx and php5-fpm installed with php-apc and memcached. Nothing else is spinning there, even mail is via ssmtp.
nginx.conf:
worker_processes 2;<br/>
worker_priority -5;<br/>
pid /var/run/nginx.pid;<br/>
<br/>
events {<br/>
 worker_connections 1024;<br/>
 multi_accept on;<br/>
 }<br/>

php-fpm.conf:
pm = dynamic<br/>
pm.max_children = 3<br/>
pm.start_servers = 2<br/>
pm.min_spare_servers = 1<br/>
pm.max_spare_servers = 3<br/>
pm.max_requests = 1024

Processes running:
1680 www-data 200364 kB php-fpm: pool www<br/>
21709 www-data 191180 kB php-fpm: pool www<br/>
21681 www-data 187788 kB php-fpm: pool www<br/>
21679 root 184312 kB php-fpm: master process (/etc/php5/fpm/php5-fpm.conf)<br/>
1502 mysql 171952 kB /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306<br/>
21687 nobody 128072 kB /usr/bin/memcached -m 64 -p 11211 -u nobody -l 127.0.0.1<br/>
22775 root 74784 kB /usr/share/webmin/proc/index_size.cgi<br/>
1507 root 71896 kB /usr/bin/python /usr/bin/fail2ban-server -b -s /var/run/fail2ban/fail2ban.sock<br/>
21769 root 71732 kB /usr/bin/perl /usr/share/webmin/miniserv.pl /etc/webmin/miniserv.conf<br/>
22380 root 70452 kB sshd: [email protected]/0<br/>
21670 www-data 55452 kB nginx: worker process<br/>
21672 www-data 55404 kB nginx: worker process<br/>
21669 root 54668 kB nginx: master process /usr/sbin/nginx<br/>
1249 root 54548 kB /usr/sbin/rsyslogd -c4<br/>
1372 root 49164 kB /usr/sbin/sshd<br/>
22610 root 42392 kB mc<br/>
1321 root 23556 kB /usr/sbin/cron<br/>
22396 root 20400 kB -bash<br/>
22612 root 20396 kB bash -rcfile .bashrc<br/>
711 root 16744 kB udevd --daemon<br/>
811 root 16740 kB udevd --daemon<br/>
812 root 16740 kB udevd --daemon<br/>
22782 root 14808 kB ps --cols 2048 -eo user:80,ruser:80,group:80,rgroup:80,pid,ppid,pgid,pcpu,vsz,nice,etime,time,stime,tty,args<br/>
22685 root 12552 kB editor /etc/php5/fpm/php5-fpm.conf<br/>
1 root 8348 kB init [2]<br/>
1118 root 6744 kB dhclient -v -pf /var/run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases eth0<br/>
1163 root 6744 kB dhclient -v -pf /var/run/dhclient.eth1.pid -lf /var/lib/dhcp/dhclient.eth1.leases eth1<br/>
1750 root 5924 kB /sbin/getty 38400 tty1<br/>
1751 root 5924 kB /sbin/getty 38400 tty2<br/>
1752 root 5924 kB /sbin/getty 38400 tty3<br/>
1753 root 5924 kB /sbin/getty 38400 tty4<br/>
1754 root 5924 kB /sbin/getty 38400 tty5<br/>
1755 root 5924 kB /sbin/getty 38400 tty6<br/>
1390 root 3948 kB /bin/sh /usr/bin/mysqld_safe<br/>
22684 root 3948 kB /bin/sh /usr/bin/sensible-editor /etc/php5/fpm/php5-fpm.conf<br/>
22781 root 3948 kB sh -c ps --cols 2048 -eo user:80,ruser:80,group:80,rgroup:80,pid,ppid,pgid,pcpu,vsz,nice,etime,time,stime,tty,args 2&gt;/dev/null<br/>
1503 root 3848 kB logger -t mysqld -p daemon.error<br/>

Question: Is this normal? What to do? Where to dig? How to reduce memory consumption?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Anatoly, 2011-03-22
@Nepofigist

Why do you need free memory? It's a pity, isn't it? Share if anything, do not worry. I scored everything on 190 meters of memory, and nothing, and shares with muscle and the rest do not suffer. You should worry not when the memory is full and everything works, but when something does not work _because_ the memory is full.

C
cadmi, 2011-03-22
@cadmi

free memory = wasted memory :D
Until it starts to slow down or swap, there is nothing to worry about in advance.
Solaris, for example, would generally take all the RAM for the ZFS disk cache. Returning when needed, on demand, when someone needs it.

A
AlexeyK, 2011-03-22
@AlexeyK

I can assume that each worker has the entire php-apc cache in itself, which is why so much memory is being eaten.
The only problem that can be is a php-fpm memory leak, but if after restarting php-fpm it eats about the same amount of memory as before the restart, then there are most likely no leaks
Well, as you have already been told, you need to worry when swap is used

N
Nepofigist, 2011-03-22
@Nepofigist

I figured out what was the matter: the cache was too inflated with a small number of nginx and php-fpm worker processes, plus the load scaling function was enabled in the server properties. I turned off scaling, significantly increased the number of nginx and php-fpm worker processes, slightly reduced the cache - the memory was freed up to 150-200 megabytes depending on the load, of which about 100 megabytes of cache.
Less is not better, %username%.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question