Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

My VPS plan gives me 1GB of RAM burstable to 2GB. Of course I cannot use 2 GB, nor > 1 GB, everyday, so I'm planning to optimize the performance of my webserver.

The average of hits-per-hour is about 8'000-10'000. This means about 2 connections-per-second. Max hits-per-hour reached until now is about 60'000. That means about 16 connections-per-second.

Unluckily my current apache configuration uses too much memory (when there are not connected clients - usually during the night - it uses about 1GB) so I've tried to customize the apache installation to fit to my needs.

I'm using Ubuntu, kernel 2.6.18, with apache2-mpm-worker, since I've read it requires less memory, and fcgid ( + PHP). This is my /etc/apache2/apache2.conf:

Timeout 45
KeepAlive on
MaxKeepAliveRequests 100
KeepAliveTimeout 10
<IfModule mpm_worker_module>
    StartServer 2
    MinSpareThreads 25
    MaxSpareThreads 75
    MaxClients 100
    MaxRequestsPerChild 0
</IfModule>

This is the output of ps aux:

www-data  9547  0.0  0.3 423828  7268 ?        Sl   20:09   0:00 /usr/sbin/apache2 -k start
root     17714  0.0  0.1  76496  3712 ?        Ss   Feb05   0:00 /usr/sbin/apache2 -k start
www-data 17716  0.0  0.0  75560  2048 ?        S    Feb05   0:00 /usr/sbin/apache2 -k start
www-data 17746  0.0  0.1  76228  2384 ?        S    Feb05   0:00 /usr/sbin/apache2 -k start
www-data 20126  0.0  0.3 424852  7588 ?        Sl   19:24   0:02 /usr/sbin/apache2 -k start
www-data 24260  0.0  0.3 424852  7580 ?        Sl   19:42   0:01 /usr/sbin/apache2 -k start

while this is ps aux for php5:

www-data  7461  2.9  2.2 142172 47048 ?        S    19:39   1:39 /usr/lib/cgi-bin/php5
www-data 23845  1.3  1.7 135744 35948 ?        S    20:17   0:15 /usr/lib/cgi-bin/php5
www-data 23900  2.0  1.7 136692 36760 ?        S    20:17   0:22 /usr/lib/cgi-bin/php5
www-data 27907  2.0  2.0 142272 43432 ?        S    20:00   0:43 /usr/lib/cgi-bin/php5
www-data 27909  2.5  1.9 138092 40036 ?        S    20:00   0:53 /usr/lib/cgi-bin/php5
www-data 27993  2.4  2.2 142336 47192 ?        S    20:01   0:50 /usr/lib/cgi-bin/php5
www-data 27999  1.8  1.4 135932 31100 ?        S    20:01   0:38 /usr/lib/cgi-bin/php5
www-data 28230  2.6  1.9 143436 39956 ?        S    20:01   0:54 /usr/lib/cgi-bin/php5
www-data 30708  3.1  2.2 142508 46528 ?        S    19:44   1:38 /usr/lib/cgi-bin/php5

As you can see it use a lot of memory. How can I reduce it to fit to just 1GB of RAM?

PS: I also think about the switch to nginx, if Apache can't fit to my needs...

UPDATE1: I've just written some lines about fcgid config, since I didn't it before:

FcgidMaxRequestsPerProcess 1000
FcgidIdleTimeout 15
FcgidBusyTimeout 30
FcgidMaxProcessesPerClass 5
share|improve this question
add comment

migrated from webmasters.stackexchange.com Feb 6 '11 at 18:30

This question came from our site for pro webmasters.

2 Answers

Reducing the amount of memory used by Apache is fairly straightforward ... just reduce the amount of processes by increasing the amount of threads.

Reducing the amount of memory used by CGI / PHP on the other hand will greatly depend on your PHP applications, how memory efficient they are, and also which version of PHP you are using.

At the least, you could look modify your Apache with the following which'll give you 2 Apache processes with 50 threads a piece and ensures that Apache processes will reload themselves every 10k connections ( doesn't take into account keepalived connections ) to free up Apache memory :

<IfModule mpm_worker_module>
    KeepAlive On
    MaxKeepAliveRequests    100
    KeepAliveTimeout        15
    StartServers            2
    ServerLimit             2
    MinSpareThreads         50
    MaxSpareThreads         100 
    ThreadLimit             100
    ThreadsPerChild         50
    MaxClients              100
    MaxRequestsPerChild     10000
</IfModule>

Then you may want to look at your fcgid configuration to ensure that you limit the amount of active php processes, and ensure that processes get reloaded so as to free up unused memory. This, however, greatly depends on your web app and usage patterns :

FcgidMaxRequestsPerProcess
FcgidIdleTimeout
FcgidBusyTimeout
FcgidMaxProcesses
FcgidMaxProcessesPerClass
share|improve this answer
    
I'm using a SMF forum and a single index.php page that acts as homepage. That's it :) –  Markon Feb 6 '11 at 19:05
add comment
up vote 0 down vote accepted

I've solved by compiling apache (using prefork!) + PHP5 on my VPS. Now it starts with 50 children processes and consumes about 6-700 MB.

I think this is the best I could do :P

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.