多线程apache服务器上的wsgi单线程配置

Wsgi single thread configuration on a multi-threaded apache server

WSGIDaemonProcess <user> processes=5 threads=1 python-home=/path/to

WSGIProcessGroup <user>
WSGIRestrictEmbedded On
WSGILazyInitialization On
WSGIApplicationGroup %{GLOBAL}

我的应用程序使用非线程安全的 Gdal。 documentation 建议将 wsgi 与 threads=1 一起使用。如果 apache 配置使用线程 mpm-workerthreads=1 保证线程安全吗?

Apache 设置:

KeepAlive Off
SetEnvIf X-Forwarded-SSL on HTTPS=1
ServerLimit 1
StartServers 1
MaxRequestWorkers 5
MinSpareThreads 1
MaxSpareThreads 3
ThreadsPerChild 5

A complementary quote 接受的答案如下:

StartServers          2
ThreadsPerChild      25
WSGIDaemonProcess processes=1 threads=15

In the case of the WSGI application, the Apache child worker processes only act as a proxy, forwarding the requests across to the mod_wsgi daemon mode process(es) for handling.

Thus, with 2 Apache child worker processes, maximum number of connections is 50 (where each has 25 threads). These Apache child worker processes accept connections for both static file requests and dynamic requests which are then proxied across to the mod_wsgi daemon mode process. With only a single mod_wsgi daemon mode process, the WSGI application itself will be able to handle 15 concurrent requests.

If there are requests being handled by mod_wsgi daemon mode process, because the Apache child worker processes is proxying the requests and responses, a thread is still consumed for the life of the request in the Apache child worker processes. The 35 (50-15) additional threads in Apache child worker processes would still be available for handling static requests, keep alive connections and acting as a buffering mechanism for pending dynamic requests against WSGI application. The latter particularly useful for slow clients as apache child worker processes will not forward request onto mod_wsgi daemon process until full request information available.

Note that just because mod_wsgi daemon mode process can only handle 15 concurrent requests doesn't mean that it can only handle that many requests per second. How many requests per second is going to be dictated by how slow your application is and what contention there is on shared resources. The latter have an impact on whether operations need to be serialised.

Overall, just think of mod_wsgi daemon mode as being similar to using mod_proxy in front of a separate back end web server. In this case though mod_wsgi has created the daemon processes and is managing them on your behalf.

Graham Dumpleton

当使用 mod_wsgi 守护进程模式时,Python 请求在与 Apache 子工作进程分开的进程中处理,所以是的,在这种情况下使用 threads=1 将保证线程安全。

有关 mod_wsgi 中的进程和线程如何工作的更多信息,请阅读相关文档:

您还可以观看: