Aiohttp: 圧縮+エンコーディングはおそらくエグゼキュータで発生するはずです

作成日 2018年08月18日  ·  4コメント  ·  ソース: aio-libs/aiohttp

メインスレッドが5秒以上ハングしたときに追跡する、aiohttpサーバー用のウォッチドッグユーティリティを実装したところ、以下のコールスタックがキャッチされました。 この応答は、圧縮が有効になっている大きなjsonオブジェクトを返しました。 コールスタックに基づいて、おそらく圧縮はバックグラウンドスレッドで実行する必要があると思います。そうしないと、ウェブサーバーが数秒間ブロックされてヘルスチェックが失敗する可能性があります(AWSではデフォルトは5秒なので、操作に5秒以上かかる場合はサーバーがリサイクルされる可能性があります)。


  | Aug 18 00:08:25.467 |   |   | WeatherAPIInternalService | File "/usr/local/fbn/fbn.com/api/weather/services/weatherapi/service.py", line 1430 in <module>
  | Aug 18 00:08:25.467 |   |   | WeatherAPIInternalService | File "/usr/local/fbn/fbn.com/api/weather/services/weatherapi/service.py", line 1426 in start_app
  | Aug 18 00:08:25.467 |   |   | WeatherAPIInternalService | File "/usr/local/lib/python3.6/site-packages/fbn_async_server/entrypoint.py", line 237 in run_server
  | Aug 18 00:08:25.467 |   |   | WeatherAPIInternalService | File "/usr/local/lib/python3.6/asyncio/base_events.py", line 422 in run_forever
  | Aug 18 00:08:25.467 |   |   | WeatherAPIInternalService | File "/usr/local/lib/python3.6/asyncio/base_events.py", line 1434 in _run_once
  | Aug 18 00:08:25.467 |   |   | WeatherAPIInternalService | File "/usr/local/lib/python3.6/asyncio/events.py", line 145 in _run
  | Aug 18 00:08:25.467 |   |   | WeatherAPIInternalService | File "/usr/local/lib/python3.6/site-packages/fbn_async_server/entrypoint.py", line 44 in start
  | Aug 18 00:08:25.467 |   |   | WeatherAPIInternalService | File "/usr/local/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 398 in start
  | Aug 18 00:08:25.467 |   |   | WeatherAPIInternalService | File "/usr/local/lib/python3.6/site-packages/aiohttp/web_response.py", line 300 in prepare
  | Aug 18 00:08:25.467 |   |   | WeatherAPIInternalService | File "/usr/local/lib/python3.6/site-packages/aiohttp/web_response.py", line 605 in _start
  | Aug 18 00:08:25.467 |   |   | WeatherAPIInternalService | File "/usr/local/lib/python3.6/site-packages/aiohttp/web_response.py", line 329 in _start
  | Aug 18 00:08:25.467 |   |   | WeatherAPIInternalService | File "/usr/local/lib/python3.6/site-packages/aiohttp/web_response.py", line 290 in _start_compression
  | Aug 18 00:08:25.467 |   |   | WeatherAPIInternalService | File "/usr/local/lib/python3.6/site-packages/aiohttp/web_response.py", line 616 in _do_start_compression

おそらくrun_in_executorますか?

enhancement question server

最も参考になるコメント

レポートをありがとう。
私は最初からこのようなことを期待していました。

すべての圧縮/エンコードをスレッドプールに切り替えると、単純なケースの速度が低下する可能性があります。
オプションとして、大きなデータにはエグゼキュータを使用し、たとえば1kbのバッファを解凍するための直接呼び出しに戻すことができます。

全てのコメント4件

ここに別の問題があります:


  | Aug 18 00:08:13.717 |   |   | WeatherAPIInternalService | File "/usr/local/fbn/fbn.com/api/weather/services/weatherapi/service.py", line 734 in get_weather_for_locations
  | Aug 18 00:08:13.717 |   |   | WeatherAPIInternalService | File "/usr/local/fbn/fbn.com/api/weather/python/fbn/asyncio/aiohttp_utils.py", line 25 in json_response
  | Aug 18 00:08:13.717 |   |   | WeatherAPIInternalService | File "/usr/local/lib/python3.6/site-packages/aiohttp/web_response.py", line 632 in json_response
  | Aug 18 00:08:13.717 |   |   | WeatherAPIInternalService | File "/usr/local/lib/python3.6/site-packages/simplejson/__init__.py", line 399 in dumps
  | Aug 18 00:08:13.717 |   |   | WeatherAPIInternalService | File "/usr/local/lib/python3.6/site-packages/simplejson/encoder.py", line 296 in encode
  | Aug 18 00:08:13.717 |   |   | WeatherAPIInternalService | File "/usr/local/lib/python3.6/site-packages/simplejson/encoder.py", line 378 in iterencode

dumpsメソッドを使用する別の場所は、エグゼキューターで実行できます。または、呼び出し元がエグゼキューターで実行できるように、非同期メソッドをサポートすることもできます。

レポートをありがとう。
私は最初からこのようなことを期待していました。

すべての圧縮/エンコードをスレッドプールに切り替えると、単純なケースの速度が低下する可能性があります。
オプションとして、大きなデータにはエグゼキュータを使用し、たとえば1kbのバッファを解凍するための直接呼び出しに戻すことができます。

私は何かをコード化するつもりです、これは私たちにとって優先度が高いのでprを提出します

わかりました、これを最初に刺してください、あなたたちがどう思うか教えてください

このページは役に立ちましたか?
0 / 5 - 0 評価