apache + uwsgi + flakeの負荷テストでのエラーについて
- uwsgiのAPIからのレスポンスがクライアントへ戻る
- この時apacheとuwsgiのセッションは張ったままとなる
- クライアントから⑧の2回目の接続の際にapacheが②の1回目のセッションを再利用しようとした瞬間、セッションが切断されるとエラーとなり、以下の様なエラーが/var/log/httpd/error_logに記録される
[Thu Jun 30 20:48:53.243189 2022] [proxy_http:error] [pid 3405] (20014)Internal error: [client 192.168.0.252:53838] AH01102: error reading status line from remote server 127.0.0.1:8080 [Thu Jun 30 20:48:53.243204 2022] [proxy:error] [pid 3405] [client 192.168.0.252:53838] AH00898: Error reading from remote server returned by /http
apacheの設定変更
- /etc/httpd/conf.d/uwsgi.confの設定を以下のように変更する
- SetEnv proxy-initial-not-pooled 1を追加
- この設定を追加するとapacheとuwsgiの間の通信を行う際にセッションを張り直すのでエラーログに出ている接続しに行った瞬間にセッションが切断される問題が回避できる
# mod_proxy_uwsgiをapacheに組み込む LoadModule proxy_uwsgi_module /usr/lib64/httpd/modules/mod_proxy_uwsgi.so SetEnv proxy-initial-not-pooled 1 # フォワードプロキシをOffにする ProxyRequests Off ProxyPass /http http://127.0.0.1:8080 ProxyPassReverse /http http://127.0.0.1:8080 ProxyPass /unix uwsgi://127.0.0.1:9090 ProxyPassReverse /unix uwsgi://127.0.0.1:9090
もう一回負荷テスト
- httpでapache + uwsgiと連携した場合
設定変更後は前回の負荷テストで出ていたNon-2xx responses: 3555がなくなった
/http
# ab -c 100 -n 10000 http://192.168.0.150/http This is ApacheBench, Version 2.3 <$Revision: 1843412 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.0.150 (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: Apache/2.4.6 Server Hostname: 192.168.0.151 Server Port: 80 Document Path: /http Document Length: 4 bytes Concurrency Level: 100 Time taken for tests: 5.646 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 2010000 bytes HTML transferred: 40000 bytes Requests per second: 1771.08 [#/sec] (mean) Time per request: 56.463 [ms] (mean) Time per request: 0.565 [ms] (mean, across all concurrent requests) Transfer rate: 347.64 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.3 0 6 Processing: 5 56 14.0 52 135 Waiting: 5 56 14.0 52 135 Total: 7 56 14.0 52 135 Percentage of the requests served within a certain time (ms) 50% 52 66% 57 75% 62 80% 66 90% 76 95% 85 98% 96 99% 103 100% 135 (longest request)
# ab -c 100 -n 10000 http://192.168.0.150/unix This is ApacheBench, Version 2.3 <$Revision: 1843412 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.0.151 (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: Apache/2.4.6 Server Hostname: 192.168.0.150 Server Port: 80 Document Path: /unix Document Length: 4 bytes Concurrency Level: 100 Time taken for tests: 5.927 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 2010000 bytes HTML transferred: 40000 bytes Requests per second: 1687.17 [#/sec] (mean) Time per request: 59.271 [ms] (mean) Time per request: 0.593 [ms] (mean, across all concurrent requests) Transfer rate: 331.17 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.3 0 10 Processing: 5 59 17.5 54 170 Waiting: 4 54 16.1 50 160 Total: 7 59 17.6 54 171 Percentage of the requests served within a certain time (ms) 50% 54 66% 60 75% 65 80% 70 90% 84 95% 95 98% 110 99% 118 100% 171 (longest request)
結論
- socketでapche + uwsgiの連携を行うとエラーが出ない、またはhttpで連携する場合は以下の設定を入れる
- 以下のエラーが出た場合はapacheの設定にSetEnv proxy-initial-not-pooled 1を入れると回避できる
- 多少レスポンスが落ちる
- 負荷テストの際にuwsgiのiniファイルの設定でprocesses, threadsの設定をいじるとRequests per secondの値が結構変わったのでuwsgiのパフォーマンスチューニングを行ってみる
[Thu Jun 30 20:48:53.243189 2022] [proxy_http:error] [pid 3405] (20014)Internal error: [client 192.168.0.252:53838] AH01102: error reading status line from remote server 127.0.0.1:8080 [Thu Jun 30 20:48:53.243204 2022] [proxy:error] [pid 3405] [client 192.168.0.252:53838] AH00898: Error reading from remote server returned by /http