Django的,蟒蛇,mod_wsgi的和Apache工人 [英] Django, python, mod_wsgi and Apache worker

查看:177
本文介绍了Django的,蟒蛇,mod_wsgi的和Apache工人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从阿帕奇prefork对工人提出并开始在后台模式下运行的mod_wsgi。到现在为止还挺好。我没有经历过最大负荷还没有,但是服务器似乎更加一致,我们没有看到随机请求采取2分钟等待mod_wsgi的响应。内存占用已经从3.5G到了1G。这太棒了。我们正在与RAM 6G的一个VPS运行。有这个sevrer 1 Django应用程序运行的内存缓存使用的一个实例一起,这是我们所分配的内存1G。我们有一个单独的MySQL服务器。

I just moved from apache prefork to worker and started running mod_wsgi in daemon mode. So far, so good. I haven't experienced max load yet, but the server seems more consistent and we're not seeing random requests take 2min waiting for a mod_wsgi response. Memory footprint has gone from 3.5G to 1G. This is awesome. We're running on a single VPS with 6G of ram. There's one Django app running on this sevrer along with an instance of memcache, to which we've allocated 1G of ram. We have a separate MySql server.

我们的应用是笨重,当然可以进行优化。我们使用现在NewRelic的解决一些比较慢的运行页面。我读过优化的mod_wsgi /阿帕奇很多,但像其他人一样,我还是留下了一些问题。

Our application is bulky and can certainly be optimized. We're using NewRelic to troubleshoot some of the more slow running pages now. I've read a lot on optimizing mod_wsgi/apache but, like everyone else, I'm still left with a few questions.

我们的应用程序的平均页面加载时间为650-750ms。我们的很多页面都在200毫秒范围内,但我们有一些狗,取2-5 +秒加载。我们得到约15-20请求/秒时正常加载时间和30-40请求/秒在高峰时段,可能持续30-60分钟。

Our average application page load time is 650-750ms. A lot of our pages are in the 200ms range, but we've got some dogs that take 2-5+ seconds to load. We get around 15-20 requests/second during normal load times and 30-40 requests/second during peak times, which may last 30-60 minutes.

下面是我的Apache的配置,正在运行的工作MPM。

Here's my apache config, running worker mpm.

StartServers        10
MaxClients         400
MinSpareThreads     25
MaxSpareThreads     75
ThreadsPerChild     25
MaxRequestsPerChild  0

我开始了默认值(StatServers = 2的MaxClients = 150),但我们的网站放缓最小负载下一路下滑。我猜它花了很长的时间来旋转起来服务器,请求进来了。我们从S3服务90%的媒体。其他10%都是通过Apache在我们的HTTPS页面或懒洋洋地有人指向我们的本地服务器提供服务。在额定负载,15工作进程最终被创建的,所以我想我可能只是设置StartServers的= 15?有了这个配置我假设我有运行(这我可以确认NewRelic的)每25个线程15工作进程(这我不知道如何确定,猜测15分之400)。

I started out with the defaults (StatServers=2 and MaxClients=150) but our site slowed way down under minimal load. I'm guessing it took a long time to spin up servers as requests came in. We're serving 90% of our media from s3. The other 10% are served through Apache on our https pages or someone pointing lazily to our local server. At nominal load, 15 worker processes end up being created, so I'm thinking I should probably just set StartServers=15? With this configuration I'm assuming I have 15 worker processes running (which I can confirm with NewRelic) with 25 threads each (which I don't know how to confirm, guessing 400/15).

我的Apache / mod_wsgi的指令是这样的:

My apache/mod_wsgi directives look like this:

<VirtualHost *:80>
    # Some stuff
    WSGIDaemonProcess app1 user=http group=http processes=10 threads=20
    WSGIProcessGroup app1
    WSGIApplicationGroup app1
    WSGIScriptAlias / /path/to/django.wsgi
    WSGIImportScript /path/to/django.wsgi process-group=app1 application-group=app1    
    # Some more stuff    
</VirtualHost>

<VirtualHost *:443>
    # Some stuff
    WSGIDaemonProcess app1-ssl user=http group=http processes=2 threads=20
    WSGIProcessGroup app1-ssl
    WSGIApplicationGroup app1-ssl
    WSGIScriptAlias / /path/to/django.wsgi
    WSGIImportScript /path/to/django.wsgi process-group=app1-ssl application-group=app1-ssl
    # Some more stuff
</VirtualHost>

有我的网站的SSL侧不同WSGIDaemonProcess / WSGIProcessGroup,嗯,这只是感觉不对的。我敢肯定,100%我搞乱的东西在这里。为了虽然更大一点,我已经拨出200 + 40线程的mod_wsgi来处理来自Apache的请求,留下160线程处理需要传递起来(通过SSL或没有指向S3的懒惰),任何媒体。

Having a different WSGIDaemonProcess/WSGIProcessGroup for the ssl side of my site, well, that just doesn't feel right at all. I'm 100% sure I've mucked something up here. To the greater point though, I've allocated 200+40 threads for mod_wsgi to handle requests from Apache, leaving 160 threads to deal with whatever media needs to be delivered up (through ssl or laziness of not pointing to s3).

所以给了我们上面的应用负载,任何人都可以提出如何提高我的网站的表现呢?我在处理与SSL / mod_wsgi的指令是否正确?哪里是格雷厄姆? ;)

So given our application load above, can anyone suggest ways I can improve performance of my site? Am I dealing with the ssl/mod_wsgi directives properly? Where's Graham? ;)

推荐答案

参见讨论:

https://groups.google.com/forum/? fromgroups =#!话题/ modwsgi / Hakr6FjRVQM

这篇关于Django的,蟒蛇,mod_wsgi的和Apache工人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆