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.

I'm hosting 4 domains using virtualhost on my AWS free tier account with Ubuntu micro instance.. When I hosted only one domain, the ram usage was around 250MB out of 613MB available. After adding 4 domains, it's 535.67 MB used, with 11 instances of apache2 running.
Is it supposed to work like this? Provided, those domains are not being accessed at all. They are just redirected there and vhost record is added. That's it. So is it like apache keeps itself scaled as we add more vhost record? if I want to host around 4 domains on a server, how much should the RAM amount be for standard cases?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Apache, unfortunately, launches one worker thread per request - which entails launching essentially a complete copy of Apache (there is some shared memory). This makes it very easy for low load to consume all the available memory. You will want to disable as many modules as possible to minimize Apache's footprint (keeping in mind that the threads spawned tend to stick around for a while). You will want to look at the average memory usage per Apache process (e.g. using ps/top) and then calculate the maximum number of processes you can run (setting that value in the prefork or mpm block of httpd.conf). On the t1.micro instance, I would also recommend adding an EBS based swap volume so that if you do run out of memory it doesn't bring your server down.

Domains themselves do not add to your memory usage, but Apache will spawn more workers if your settings permit it - it is possible that search engines, etc. are accessing the domains which will result in the additional processes.

It is fairly common for Apache processes to start around 10MB, and grow with use (easily reaching 40-60MB per process). One of the big contributors to this is PHP (if you are using it). Avoid using mod_php on the t1.micro as it adds considerable overhead to each Apache thread. Instead go with either php-fcgi or better yet php-fpm. In both of the latter cases the php interpreter runs independently of Apache, offering much better memory utilization (there is a slight performance loss, but the benefits far outweigh the losses).

If you do not need to use Apache (e.g. don't have a requirement for a specific module and don't require .htaccess files) I would highly recommend nginx (with php-fpm). The overall memory usage will drop considerably, and you should also notice a performance increase.

share|improve this answer
    
Hmm. Compared to your examples of apache's memory usage, this is how it is in my case. dpaste.com/650194 I guess I should play with it a bit more to understand how the memory is being used in my case. –  Bibhas Nov 9 '11 at 18:15
2  
Your numbers (around 40MB/process) can certainly be in line with expectations - you probably have more modules than needed enabled - and will find the memory usage grows as the processes are used. Take a look at emergent.urbanpug.com/?p=60 for a good guide on tuning your Apache/MySQL settings. (Side note: it looks like you are using Ubuntu - if your setup isn't too elaborate (i.e. wouldn't be too hard to move) I would recommend Amazon's Linux - it has a really light footprint. I have about 10 small sites running on a t1.micro (with another 10 subdomains) - taking 170MB) –  cyberx86 Nov 9 '11 at 18:25
    
Interesting. Ok. Will try it. Thanks. :) –  Bibhas Nov 9 '11 at 18:56
add comment

Modern operating systems are generally designed intentionally to use all available memory. The assumption is that you can't save it for later, so there is no benefit to leaving it unused. Data kept in RAM might turn out to be needed later and save a disk access. Free RAM that is unlikely to be used in the near future provides no benefit at all, so there's no point in creating a lot of it.

The system assumes you gave it that memory because you wanted it to use it to improve performance.

share|improve this answer
    
Ummm. The free tier compatible instances(t1.micro) have 613MB fixed physical memory. 250MB is the amount of total memory used when I had only one domain hosted. I'm not using swap, so thats the physical memory. –  Bibhas Nov 9 '11 at 18:07
    
Right, so as I explained, software is designed to use all available memory. The assumption is that you can't save it for later, so not using it is simply wasting it and making it free (if it will go unused) has no benefit. –  David Schwartz Nov 9 '11 at 18:11
    
That I know that it's allowed to take as much of memory as it wants. I just wanted to know how apache is hogging the memory. cyberx86's answer clears some doubt. rest I need to test few things. But thanks for the reply. :) –  Bibhas Nov 9 '11 at 18:16
    
Apache isn't hogging the memory. The operating system is, because it's designed to. Nothing else wants the memory, and it takes effort to make memory free. Memory that's free does nothing. Memory that's in use eliminates disk accesses. –  David Schwartz Nov 9 '11 at 18:27
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.