Showing posts with label OOM. Show all posts
Showing posts with label OOM. Show all posts

Tuesday, February 18, 2014

Apache Memory管理:Prefork and Worker

這幾日觀察提供數種服務的Linode server上,各個process使用資源的情況,發現一個apache的child process約需要20MB的memory,若是沒有多加管控,容易超出linux的memory上限,觸發OOM,部分process會被作業系統kill。

"It is not unheard of for even small to moderate sized Python web applications to consume 30MB or more of private memory in each child server process." -- from this reference

同時發現apache在分process與task有兩個mode,其一為prefork、其二為worker:
  • prefork:一個request(task)由其中一個apache process負責
  • worker:一個request(task)由多個apache process負擔
於是我開始思考使用哪個mode適合我的用途,而發現他人的建議下,除非是跑PHP的情況,使用worker模式並無太大幫助,而apache預設是prefork。

"If you use mod_wsgi daemon mode, it doesn't matter which Apache MPM you use, although suggested that for UNIX systems worker MPM be used unless you are stuck with having to also host PHP applications using mod_php as some PHP extensions aren't thread safe." -- from this reference

Monday, January 6, 2014

Django Apache Server - Processes be Killed

Few days ago, while we are trying to give out a live demo to our customers. The Django-apache server was not working accidentally. I found that I couldn't even SSH into the server. Now, I am writing down the problem I met and how I solved it in this post.

Django-Apache Server has No Response

My Django-apache has no response. The requests from the apps timeout and failed to receive the response.

Can't SSH into the Server

Same, I got timeout and failed while trying to SSH into the server. So, I try to login using the SSH interface from Linode. That works, but I see the following messages:
Out of memory: Kill process xxxxx (safesquid) score xx or sacrifice child Killed process xxx, UID xxx, (python) total-vm:xxxxKB, anon-rssxxxxkB, file-rss:xxxkB
*xxx is some number
The messages repeat a lot, and keep popping up. After doing Google Search, I think that there are some problems to do with the memory. It seems that someone use too much memory, and OS started to kill processes in order to get memories. I think OS killed the running apache server.


Turn Off Debug Mode

First, I scan through the processes running on my machine. The only two suspected service is django and celery. Then, I started to think if I am following the right deploying steps in their official document. And I found in Django Deployment Document, it says that if django is under debug mode, "All database queries will be saved in memory as the object django.db.connection.queries. As you can imagine, this eats up memory!"

So, I did the following modifications in settings.py
DEBUG = False
ALLOWED_HOSTS = ['api.plate.tw']


Result

I haven't met the same problem after switching off the debug mode, but still not sure if the problem is totally be solved.