Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Main Section Web Server
  • Search

Web server running out of RAM

Questions regarding the Web Server
Apache + Nginx, Nginx + PHP5-FPM
Post Reply
  • Print view
Advanced search
14 posts
  • 1
  • 2
  • Next
vesta_mtl
Posts: 70
Joined: Wed Dec 21, 2016 2:08 pm

Web server running out of RAM
  • Quote

Post by vesta_mtl » Mon Mar 06, 2017 2:44 pm

I have a 4 GB DigitalOcean droplet and I have found that it runs out of RAM after 24-48 hours.

Someone on another forum suggested I limit the amount of processes spawned like this:

In this file: /etc/httpd/conf.d/fcgid.conf
Add this: FcgidMaxProcesses 35

In this file: /etc/httpd/conf/httpd.conf
Add this:
<IfModule prefork.c>
ServerLimit 35
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 35
MaxConnectionsPerChild 75
</IfModule>


However, someone was kindly helping me in another post on this forum, and suggested this was a bad idea since I would eventually be kicking out users:
viewtopic.php?f=11&t=14033&p=57492#p57486

So my question is this: What is the best way to ensure my VPS doesn't run out of RAM? Is there a way to make the spawned processes recycle themselves more efficiently? Or is there something else that I should try?

Thanks in advance for your help.
Top

skurudo
VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:
Contact skurudo
Website Facebook Google+ Skype
Twitter

Re: Web server running out of RAM
  • Quote

Post by skurudo » Tue Mar 07, 2017 8:43 am

* Optimization configuration of php5-fpm and mysql of course
* Check your php code, maybe you have memory leak.
Top

newtron
Posts: 22
Joined: Wed Jan 13, 2016 4:43 pm

Re: Web server running out of RAM
  • Quote

Post by newtron » Tue Mar 07, 2017 8:52 am

Check if your webpages is sending spam (or users), a way to detect, use this in terminal:

Code: Select all

tail -f /var/log/exim4/mainlog
Top

skurudo
VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:
Contact skurudo
Website Facebook Google+ Skype
Twitter

Re: Web server running out of RAM
  • Quote

Post by skurudo » Tue Mar 07, 2017 11:08 am

newtron wrote:Check if your webpages is sending spam (or users), a way to detect, use this in terminal:
tail show you only last 10 lines of file? It's not so much for analysis, ic ;-)
Top

plutocrat
Posts: 232
Joined: Fri Jan 27, 2017 9:16 am

Os: Ubuntu 17x
Web: apache + nginx
Re: Web server running out of RAM
  • Quote

Post by plutocrat » Wed Mar 08, 2017 6:03 am

VestaCP is quite happy running in 1Gb, or even 512Mb DO droplet if you really squeeze it, so I think you might have to look around to see what's causing the problems.
mysqltuner.pl (from )https://github.com/major/MySQLTuner-perl is good for diagnosing database problems. In particular look at the number of connections. This is usually set waaaay too high. mysqltuner will tell you you've only used a max of, say, 10 out of 300 connections, so in this case try brining it down to 50 or so. Experiment.

htop and ps_mem.py are also useful. It will tell you what is using the memory in your system. Get familar with them.
(htop can be installed with your package manager (apt-get install htop). ps_mem.py is from here https://github.com/pixelb/ps_mem

You could also look at putting php-fpm into 'ondemand' mode, and limit the number of child processes and servers is spawns.

OK, those should get you started. I'd be interested if you posted some of your results.
Top

vesta_mtl
Posts: 70
Joined: Wed Dec 21, 2016 2:08 pm

Re: Web server running out of RAM
  • Quote

Post by vesta_mtl » Wed Mar 08, 2017 1:13 pm

Thanks everyone for the helpful advice. It's enough to get me started.

Thanks again.
Top

SS88
Posts: 336
Joined: Thu Nov 19, 2015 12:40 pm

Re: Web server running out of RAM
  • Quote

Post by SS88 » Mon Mar 13, 2017 2:22 pm

If you have a default install of MySQL you will be fine but they can always be optimized. Kudos to plutocrat.

The usual culprit is PHP-FPM and I bet the setting is set to dynamic.

If you are using a default.tpl for PHP-FPM then edit this:

/usr/local/vesta/data/templates/web/php-fpm/default.tpl

Change to:

Code: Select all

[%backend%]
listen = 127.0.0.1:%backend_port%
listen.allowed_clients = 127.0.0.1

user = %user%
group = %user%

pm = ondemand
pm.max_children = 50
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 10
pm.process_idle_timeout = 10s
pm.max_requests = 500

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
If you are using socket.tpl, edit this:

/usr/local/vesta/data/templates/web/php-fpm/socket.tpl

Change to:

Code: Select all

[%backend%]
listen = /var/run/php5-%backend%.sock
listen.allowed_clients = 127.0.0.1

user = %user%
group = %user%

listen.owner = %user%
listen.group = nginx

pm = ondemand
pm.max_children = 50
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 10
pm.process_idle_timeout = 10s
pm.max_requests = 500

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp = /tmp
Top

vesta_mtl
Posts: 70
Joined: Wed Dec 21, 2016 2:08 pm

Re: Web server running out of RAM
  • Quote

Post by vesta_mtl » Mon Mar 13, 2017 5:13 pm

Thanks for the advice.

I am using the "sk-php70" web template from here:
viewtopic.php?t=10854

It is FastCGI, but not php-fpm, so I don't know if your advice would be applicable.

I made some optimizations in this file:
/etc/httpd/conf.d/fcgid.conf

As follows (modified from my original post):

Code: Select all

FcgidMinProcessesPerClass 0
FcgidMaxRequestsPerProcess 0
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 0
FcgidInitialEnv PHP_FCGI_CHILDREN 0
FcgidMaxProcesses 120
FcgidMaxProcessesPerClass 20
FcgidFixPathinfo 1
FcgidIdleTimeout 30
FcgidBusyTimeout 300
FcgidProcessLifeTime 60
FcgidIOTimeout 300
FcgidIdleScanInterval 15
FcgidErrorScanInterval 15
FcgidZombieScanInterval 15
This, combined with the Apache tuning done in /etc/httpd/conf/httpd.conf (see original post), has resulted in my RAM usage being much more stable and normal. Always around 50%.

I am not an expert, and perhaps there are flaws in my logic, but this is what I have found to be a functional solution for me.
Top

SS88
Posts: 336
Joined: Thu Nov 19, 2015 12:40 pm

Re: Web server running out of RAM
  • Quote

Post by SS88 » Mon Mar 13, 2017 5:21 pm

Yes, scrap my idea as it won't work for you.

You can always reduce "FcgidProcessLifeTime" from 60 to 30 if you like. This will kill processes that are not being used after 30 seconds. Technically, this is always best with SSD disks.
Top

vesta_mtl
Posts: 70
Joined: Wed Dec 21, 2016 2:08 pm

Re: Web server running out of RAM
  • Quote

Post by vesta_mtl » Mon Mar 13, 2017 5:30 pm

Thanks, I had that initially, and it was good. So I tried going to 60 and it is still good, so I left it there.

From what I found online, FcgidIdleTimeout should be about half of FcgidProcessLifeTime, which is why I have FcgidIdleTimeout set to 30.
Top


Post Reply
  • Print view

14 posts
  • 1
  • 2
  • Next

Return to “Web Server”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

Login  •  Register

I forgot my password