Ceilometer 19、wsgi及其部署模式


1 wsgi含义

wsgi是web服务网关接口,可以认为mod_wsgi是连接python应用和web服务器的桥梁

2 wsgi部署模式

而mod_wsgi中支持如下几种模式:
模式1:
prefork模式: 多进程模式(multi-process)
处理过程: 预创一定数量子进程,每个进程起一个线程,接受请求,不够就再创建进程。数量到设置的最大值后,拒绝新请求。
优点: 线程安全,因为一个进程只有一个线程
缺点: 内存多
模式2:
worker模式:多线程模式(multi-threaded)
本质: apache创建多个进程,每个进程起多个线程,每个线程接受请求。
优点:占用内存少,支持较高并发
缺点:同一进程的多个线程需要考虑线程安全


目前gnocchi采用了多线程模式,即上述模式2,具体采用4 进程,8线程的策略。
样例结果如下:
WSGIDaemonProcess gnocchi processes=4 threads=8 user=gnocchi group=gnocchi display-name=%{GROUP}

根据以下内容的描述:
The worker MPM uses multiple child processes with many threads each. Each thread handles one connection at a time. Worker generally is a good choice for high-traffic servers because it has a smaller memory footprint than the prefork MPM.
The event MPM is threaded like the Worker MPM, but is designed to allow more requests to be served simultaneously by passing off some processing work to supporting threads, freeing up the main threads to work on new requests.
The prefork MPM uses multiple child processes with one thread each. Each process handles one connection at a time. On many systems, prefork is comparable in speed to worker, but it uses more memory. Prefork's threadless design has advantages over worker in some situations: it can be used with non-thread-safe third-party modules, and it is easier to debug on platforms with poor thread debugging support.
可以知道采用worker模式,每个thread只可以处理一个连接。

3 wsgi性能调优


关于wsgi.conf中processes和threads建议如下:
threads配置为cpu个数,processes的数量设置为1.5倍的cpu个数

4 注意问题


如果有的应用不支持wsgi的多线程模式,即2中的模式2,需要将threads个数调整为1,避免出现线程安全问题 

参考:
[1] https://blog.csdn.net/taiyangdao/article/details/56047246
[2] http://ohmystack.com/articles/apache-mod_wsgi
[3] https://httpd.apache.org/docs/2.4/misc/perf-tuning.html
[4] https://gnocchi.xyz/operating.html

猜你喜欢

转载自blog.csdn.net/qingyuanluofeng/article/details/84558020