Linux memory usage

I tried to track down what process was gradually taking up more memory on my web server and came to the conclusion that it was Apache and Mysql.
I have a dedicated server with 2 GB memory, two dual 3GHz Pentium 4 cpu's and a 160 GB SATA HDD.

This server is used to serve dynamic content using a custom web application that I built using php and mysql.
Altogether, I use php, mysql and apache to serve the content. I have finely tuned and tested every aspect of the web application so it does not consume much memory and barely any cpu load. It is very fast and efficient. It is also commercial service that gets several thousand requests a day which is minor for what I expect to get soon. I use cpanel to manage it easier.

Throughout the last 5 days, I did some tests. First, I rebooted the server, then I used TOP and FREE to show process load and memory usage stats. The memory usage started out around 226 MB which appears to be normal, then gradually reached 300 MB by the end of the day. Fast forward 5 days later and the memory gradually reached 1.4 GB of usage. I have monitored it every day and saw it getting higher a day at a time. I did some more tests using TOP and found that mysql and apache appear to be using the most amount of memory. These are the two main programs that get used the most because these are what keeps the web application going. However, I did not expect apache and mysql to keep using more memory every day. It seems like these two servers are not using memory efficiently. I am not sure if this is normal, or if there are settings I need to change in Apache or Mysql's config files that will change the way these two servers manage memory or processes better.

If there is anyone that has experienced a similar situation and found out how to resolve it, I would appreciate some real tips.

If there is anything else you need to know, feel free to ask me.






LVL 10
ray-solomonAsked:
Who is Participating?
 
NopiusCommented:
> However, I did not expect apache and mysql to keep using more memory every day. It seems like these two servers are not using memory efficiently.
Be sure, Apache and MySQL use memory as efficiently as it could be ;-)

Most probably your problem is in PHP application that leads apache and mysql to eat more and more memory. So you have memory leaks in a PHP code. PHP itself may have memory leaks in it's internal libraries.
Apache grows because PHP mod_php runs in address space of Apache process.
MySQL process grows, if you, for example, call mysql_connect() without mysql_close().

That is only my suggestion, may be others can help you ...
0
 
ssvlCommented:

Note that in Red Hat Enterprise. Linux 3 and earlier, most free memory will be used for cache.
0
 
ray-solomonAuthor Commented:
Hi ssvl:
I have apache 1.3.37. From what I read, mod_cache is not available for 1.3.37, so it appears that nothing is being cached, but I am looking into this more. I could be wrong.
I suppose I could upgrade to apache 2.2.4 this weekend, but I am still trying to determine the exact cause first.

I will need to recompile this weekend anyway so I can add mod_info.c to the build.

Hi Nopius:
Thanks for your feedback.

I have done many more tests and I am still testing, and I feel confident it is an Apache config settings issue. After I learn more, I will update this post.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.