问题:
我怎么知道我的apache服务器是否已经在多进程&多线程模式? 因为当我加载测试它时,它给我相同的结果时间与不同的线程数。我用25个线程和50个线程运行测试。
我是否需要在Django代码中进行多线程/多进程工作的调整?
我是否需要更改MPM配置(/conf/extra/httpd-mpm.conf)?
下面是我的服务器详细信息和配置:
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:
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:
<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:
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:
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"
答案 0 :(得分:2)
由于Python GIL,在Python中设置大量线程通常是个坏主意。并且在你过度使系统过载的情况下进行基准测试会更糟糕,因为它会加剧事情并产生不可靠的结果。我建议不要运行使用超过40-60%容量的线程的Python Web服务器,因为一旦你将吞吐量推高,特别是如果CPU限制更多,那么事情就会迅速下滑。发送最大请求的基准,非常快速地执行此操作,因此毫无意义。
我建议观看以下两个会议讨论视频,其中涉及一些问题。
作为一般经验法则,请执行以下操作:
WSGIRestrictEmbedded On
停用嵌入模式。要添加指标以监控mod_wsgi,请参阅:
如果想讨论指标,请使用mod_wsgi邮件列表获取最新信息。
更新1
另请注意:
最后,它讨论了您应该查看并设置的各种设置守护程序模式。另见:
结束用于守护进程设置的一些推荐默认值。