Apache mod_wsgi django启用多线程多进程 [英] Apache mod_wsgi django enable multi-thread multi-process

查看:240
本文介绍了Apache mod_wsgi django启用多线程多进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

  1. 我怎么知道我的apache服务器是否已经在多进程中运行了?多线程模式 因为当我对其进行负载测试时,它以不同的线程数为我提供了相同的结果时间.我用25个线程和50个线程进行测试.

  1. how can i know if my apache server has already run in multi-process & multi-thread mode ? because when i load tested it, it giving me same result time with different threads count. i run test with 25 threads and 50 threads.

对于多线程/多进程工作,我需要在Django代码中进行任何调整吗?

Is there any adjustment that i have to do in the Django code for the multi-thread / multi-process work?

我必须更改MPM配置(/conf/extra/httpd-mpm.conf)吗?

Am I have to change the MPM config (/conf/extra/httpd-mpm.conf) ?

下面是我的服务器详细信息和配置:

below is my server detail and configuration :

Server redhat enterprise 6.9
Apache server 2.4.33
Postgre 9.6.6
Python 3.6
Virtualbox RAM 8Gb, 2 Core (4 vCpu).

我的httpd.conf:

my httpd.conf :

Listen 8000

LoadModule wsgi_module modules/mod_wsgi.so

Include conf/extra/httpd-vhosts.conf

WSGIScriptAlias / /home/applmgr/Harpa/HarpaBackend/harpa/wsgi.py
WSGIPythonHome /home/applmgr/Harpa/pyenv_sl
WSGIPythonPath /home/applmgr/Harpa/HarpaBackend
WSGIPassAuthorization On

<Directory /home/applmgr/Harpa/HarpaBackend/harpa>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

我的httpd-vhosts.conf:

my httpd-vhosts.conf :

<VirtualHost *:8000>

    Alias /static /home/applmgr/Harpa/HarpaBackend/static
    <Directory /home/applmgr/Harpa/HarpaBackend/static>
        Require all granted
    </Directory>

    WSGIDaemonProcess harpa python-home=/home/applmgr/Harpa/pyenv_sl processes=15 threads=50 python-path=/home/applmgr/Harpa/HarpaBackend  
    WSGIProcessGroup harpa

    <Directory /home/applmgr/Harpa/HarpaBackend/harpa>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>
</VirtualHost>

ps -ef | grep httpd:

ps -ef | grep httpd :

applmgr   2817     1  0 14:18 ?        00:00:00 /opt/apache_http/bin/httpd -k start
applmgr   2818  2817  0 14:18 ?        00:00:04 /opt/apache_http/bin/httpd -k start
applmgr   2819  2817  0 14:18 ?        00:00:00 /opt/apache_http/bin/httpd -k start
applmgr   2820  2817  0 14:18 ?        00:00:03 /opt/apache_http/bin/httpd -k start
applmgr   2821  2817  0 14:18 ?        00:00:06 /opt/apache_http/bin/httpd -k start
applmgr   2822  2817  0 14:18 ?        00:00:03 /opt/apache_http/bin/httpd -k start
applmgr   2823  2817 26 14:18 ?        00:34:21 /opt/apache_http/bin/httpd -k start
applmgr   2824  2817  0 14:18 ?        00:00:06 /opt/apache_http/bin/httpd -k start
applmgr   2825  2817 47 14:18 ?        01:01:16 /opt/apache_http/bin/httpd -k start
applmgr   2826  2817  0 14:18 ?        00:00:00 /opt/apache_http/bin/httpd -k start
applmgr   2827  2817 25 14:18 ?        00:33:00 /opt/apache_http/bin/httpd -k start
applmgr   2828  2817  0 14:18 ?        00:00:00 /opt/apache_http/bin/httpd -k start
applmgr   2829  2817  0 14:18 ?        00:00:03 /opt/apache_http/bin/httpd -k start
applmgr   2830  2817  0 14:18 ?        00:00:03 /opt/apache_http/bin/httpd -k start
applmgr   2831  2817  0 14:18 ?        00:00:00 /opt/apache_http/bin/httpd -k start
applmgr   2832  2817  0 14:18 ?        00:00:03 /opt/apache_http/bin/httpd -k start
applmgr   2833  2817  0 14:18 ?        00:00:00 /opt/apache_http/bin/httpd -k start
applmgr   2834  2817  0 14:18 ?        00:00:00 /opt/apache_http/bin/httpd -k start
applmgr   2835  2817  0 14:18 ?        00:00:00 /opt/apache_http/bin/httpd -k start
applmgr   3875  2817  0 14:23 ?        00:00:00 /opt/apache_http/bin/httpd -k start
applmgr   4979  2642  0 16:26 pts/1    00:00:00 grep httpd

./apachectl -V:

./apachectl -V :

Server version: Apache/2.4.33 (Unix)
Server built:   Apr  9 2018 16:42:03
Server's Module Magic Number: 20120211:76
Server loaded:  APR 1.6.3, APR-UTIL 1.6.1
Compiled using: APR 1.6.3, APR-UTIL 1.6.1
Architecture:   64-bit
Server MPM:     event
threaded:     yes (fixed thread count)
forked:     yes (variable process count)
Server compiled with....
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT="/opt/apache_http"
-D SUEXEC_BIN="/opt/apache_http/bin/suexec"
-D DEFAULT_PIDLOG="logs/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"

推荐答案

由于Python GIL,在Python中设置大量线程通常是一个坏主意.在过度使系统过载的情况下进行基准测试会更加糟糕,因为它会使情况恶化并给出不可靠的结果.我建议不要运行使用超过40-60%容量的线程的Python Web服务器,因为一旦将吞吐量提高了(尤其是如果CPU数量增加了),事情就会迅速恶化.发送最大请求的基准非常快,因此毫无意义.

Setting a high number of threads in Python is usually a bad idea because of the Python GIL. And doing benchmark testing where you excessively overload the system is even worse as it jut exacerbates things and gives unreliable results. I'd recommend not running a Python web server which uses threading at over 40-60% capacity because once you push throughput higher, especially if more CPU bound, then things go rapidly down hill. Benchmarks which send max requests, do this very quickly and so are meaningless.

我建议您观看下面两个涉及一些问题的会议视频.

I would suggest watching the following two conference talk videos which goes into some of the issues.

  • https://www.youtube.com/watch?v=k6Erh7oHvns&t=1s
  • https://www.youtube.com/watch?v=SGleKfigMsk&t=133s

一般而言,请执行以下操作:

As a general rule of thumb, do the following:

  • 使用守护程序模式.
  • 使用WSGIRestrictEmbedded On禁用嵌入式模式.
  • 每个进程最多使用5个线程,除非I/O绑定过多.
  • 在线程上使用进程,但也不会被进程占用.
  • 可在多台计算机上扩展.
  • 说明WSGI服务器和应用程序,现在就说明它在实际系统中的性能.
  • Use daemon mode.
  • Disable embedded mode using WSGIRestrictEmbedded On.
  • Use at most 5 threads per process, unless excessively I/O bound.
  • Use processes over threads, but don't get carried away with processes either.
  • Scale across multiple machines.
  • Instrument the WSGI server and application so now how it performs for real system.

有关添加度量以监视mod_wsgi的信息,请参见:

For adding metrics to monitor mod_wsgi see:

如果要讨论指标,请使用mod_wsgi邮件列表以获取最新信息.

If want to discuss metrics, use the mod_wsgi mailing list for latest information.

更新1

也请注意:

最后,它讨论了您应该查看和设置的各种设置守护程序模式.另请参阅:

At the end of this it talks about various settings daemon mode you should look at and set. Also see the end of:

有关守护进程设置的一些建议默认值.

for some recommended defaults for daemon process settings.

这篇关于Apache mod_wsgi django启用多线程多进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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