Thursday, September 12, 2019

ubuntu - Virtual server freeze (apache ?)



I rent a small virtual server at 1und1.de. (Link, but German only) (2GB RAM dynamic, 512MB at least, 20 GB HDD) I choose to run a Ubuntu 8.04 LTS as operating system (64 Bit). I installed apache2 + php5 + mysql via the Ubuntu repositories and later eAccelerator.



I running some development stuff and a production site. This site is a kind of directory and has a few visitors (250 each day) and a lot of pages (about 7,5k). Every few days the servers freezes. This means, it's up, could be pinged, but any other action will result in "server refused connection". Looking into the admin panel it says that my kmemsize is to high and also there a lot of apache processes that were spawned.




For me it seems that my apache consumes all my ressources (and it also seems, that these freezes seems to start if Google or another crawler start to crawl the page).



Then I tried to avoid this freezes:




  • I lowered MaxKeepAliveRequests and KeepAliveTimeout in the Apache config

  • I set MaxRequestsPerChild in the setting of the prefork settings, to keep Apache workers cleaned more often.



This seems to improve the situation, but still freezes are happening.




Anyone any idea what could / should be changed?



Solution.


Answer



Figure out what the problem Actually Is:
Don't start tuning until you have used something like top or the ps command to see what is actually using the memory. It could be anywhere in the stack ( Mysql, PHP, Apache ). If it is Apache...



Switch to lighter HTTP Daemon:
Have you considered lighter HTTP daemon such as:






Consider a different MPM with Apache:
I would test this a lot before pushing this into production, but you might consider switching the the worker (instead of perfork) Multi-Processing Module (MPM). This article says this was used at dealnews.com and it helped with memory usage. I haven't done this with Ubuntu, but I think it is just:



sudo apt-get remove apache2-mpm-prefork
sudo apt-get install apache2-mpm-worker


But you might want to consider building Apache from source so you only have the modules you need, that can be kind of a big project though. Also, from the article keep in mind:





This is an important part. You can't
use radical extensions in PHP when you
are using worker.




Tune PHP as Well:
This IBM Developerworks article has some php tuning options that might help reduce memory as well.



Tune MySQL as Well:
The third article in the above IBM Lamp tuning article talks about MySQL tuning. This can end up using quite a bit of memory.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...