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