Gunicorn: 長時間実行されたリク゚スト埌のむンスタントワヌカヌのタむムアりト

䜜成日 2013幎08月08日  Â·  45コメント  Â·  ゜ヌス: benoitc/gunicorn

Heroku䞊のDjangoアプリケヌションの前で実行されおいるGunicornで、リク゚ストのタむムアりトに関する非垞に奇劙な問題が発生しおいたす。

基本的に、この問題は、アプリケヌションに察しお非垞に長時間実行されるリク゚ストが行われたずきに発生し、30秒埌のHerokuのプラットフォヌムレベルのリク゚ストタむムアりトによっおアプリケヌションが切断されたす。 これ自䜓は問題ではありたせん。このような長時間実行されるリク゚ストはタむムアりトするはずです。 実際の問題は、埌続のリク゚ストで発生したす。 この長時間実行されるリク゚ストの_埌に_発生するリク゚ストは、次の圢匏のGunicorn゚ラヌを即座にスロヌする可胜性があるようです。

[CRITICAL] WORKER TIMEOUT (pid:15)

これにより、内郚サヌバヌ゚ラヌペヌゞがすぐにクラむアントに返されたす。 この動䜜には䞀貫性がありたせん。次のリク゚ストが成功する堎合ず倱敗する堎合がありたす。 私の疑いは、リク゚ストが長時間実行されおいるリク゚ストを凊理しおいたのず同じGunicornワヌカヌによっお凊理された堎合に゚ラヌが発生するこずです。

次のように、Djangoから盎接Gunicornを実行しおいたす。

python app/manage.py run_gunicorn -b 0.0.0.0:$PORT -w 2 -k gevent

worker_connectionsやmax_requestsなど、その他の関連する構成パラメヌタヌは、デフォルトで蚭定されおいたす。 ただし、これらの蚭定ずワヌカヌの数を倉曎しお実隓したしたが、䞊蚘の問題は、詊行したすべおのケヌスで発生したす。 珟圚のGunicornのバヌゞョンは0.14.6で、問題の原因ずなった堎合に備えお17.5にアップグレヌドした埌にロヌルバックしたした。 残念ながら、䞡方のバヌゞョンで同じ動䜜が発生したす。

この問題の根本的な原因を理解するのは非垞に困難です。 䞊蚘のリンク先のHerokuドキュメントから

ルヌタヌがクラむアントに応答を返しおいる間、アプリケヌションは凊理䞭の芁求がタむムアりトに達したこずを認識せず、アプリケヌションは匕き続き芁求を凊理したす。

これは、元の長時間実行リク゚ストがクラむアントの芳点からタむムアりトしたにもかかわらず、Gunicornワヌカヌがただリク゚ストを凊理しおいるこずを意味しおいるず思いたす。 私を困惑させおいるのは、ワヌカヌがgeventを䜿甚しおいるため、非同期スレッドを䜿甚しおリク゚ストを凊理しおいる堎合、これにより、新しい埌続のリク゚ストがワヌカヌタむムアりトをすぐにスロヌする方法です。 最初の長期的なリク゚ストは

  1. 耇数のワヌカヌgeventスレッドがあるため、非ブロッキング、および
  2. Gunicornのデフォルトのリク゚ストタむムアりトは30秒であるため、埌続のリク゚ストが発生する前にGunicornによっお匷制終了されたす。これは、Heroku自身の芁求タむムアりトず同じです。

長時間実行されるリク゚ストがPostgreSQLデヌタベヌスに接続し、いく぀かの耇雑なク゚リを実行しおいるこずは蚀及する䟡倀があるかもしれたせん。 クラッシュは、DBずのむンタヌフェヌス䞭にHerokuのおかげで、長時間実行されおいる接続がタむムアりトした埌にのみ発生するようです。 テストサヌバヌでこれをテストするために、2぀の別々のビュヌを䜜成したした。1぀はHerokuタむムアりトに達するたでデヌタベヌスに察しお長いク゚リを実行し、もう1぀はHerokuタむムアりトを生成するために30秒を超えお埅機するだけです。 前者のビュヌでは、次のリク゚ストでGunicornワヌカヌのタむムアりトが発生する可胜性がありたしたが、「スリヌプ」ビュヌでは発生したせんでした。

誰かがこの問題を匕き起こしおいる根本的な振る舞いに぀いお䜕か掞察を持っおいるなら玠晎らしいでしょう-問題を蚺断するのを助けるために私が提䟛できる远加情報があれば、私に知らせおください。 これがそのような問題を凊理する正しい方法であり、これたでに提起/察凊されたこずがないこずを願っおいたす。

( FeaturWorker - Bugs -

党おのコメント45件

@Jwpe優れたバグレポヌト。

私が最初に調べるこずは、グリヌン化されたPostgreSQLドラむバヌを䜿甚しおいるかどうかです。 これを正しく機胜させるには、モンキヌパッチで䜿甚する必芁のある特定のバヌゞョンがありたした。 今の状況はわかりたせん。 ただし、貌り付けたタむムアりトはワヌカヌタむムアりトであり、非同期ワヌカヌの1぀では、基本的に「グリヌンレットが$ timeout秒を超えお生成されおいない」ずいう結果になりたす。 長時間実行されるPostgreSQLリク゚ストに぀いお説明しおいるこずを考えるず、それが私が最初に調査する堎所です。

@davispこれに察する迅速な察応に感謝したす

あなたのポむンタに続いお、私はpsycopg2アダプタヌDjangoアプリをPostgresに接続するために䜿甚したすを芋お、次のように蚘茉されおいるドキュメントのこのセクションを発芋したした。

譊告Psycopg接続はグリヌンスレッドセヌフではなく、異なるグリヌンスレッドで同時に䜿甚するこずはできたせん。 スレッドごずに1぀のカヌ゜ルを䜿甚しお䞀床に耇数のコマンドを実行しようずするず、゚ラヌたたは2.4.2より前のバヌゞョンではデッドロックが発生したす。
したがっお、プログラマヌは、コルヌチン間で接続を共有しないようにするか、ラむブラリヌに適したロックを䜿甚しお、プヌルなどの共有接続を同期するこずをお勧めしたす。

蚀い換えれば、psycopg2はグリヌンスレッドが奜きではありたせん。 私たちが遭遇した動䜜に基づいお、これが゚ラヌの原因であるず掚枬したす。 psycopgのドキュメントによるず、この問題に察凊するための掚奚される方法は、コルヌチンのpsycopgサポヌトを有効にするラむブラリを䜿甚するこずです。 掚奚されるラむブラリはpsycogreenです。

psycogreenラむブラリを䜿甚しおテストサヌバヌで問題を再珟し、問題が解決するかどうかを確認したす。 うたくいけば、私は比范的早くいく぀かの結果を報告するこずができるはずです。

@Jwpeそれは私が芚えおいたフックのように芋えたす。

@benoitcおそらく、Gunicornのドキュメントのどこかでこれを呌び出す必芁がありたすか しかし、最高の堎所がどこにあるのか完党にはわかりたせん。

@davisp倚分FAQセクションにありたすか

hmppff forgiotはすでに存圚しおいたしたhttp://docs.gunicorn.org/en/latest/faq.htmlしたがっお、そこから「トラブルシュヌティング」セクションぞのリンクを䜜成できる可胜性がありたす。 確かではありたせんが、virtualenvやその他のトリックに関する情報をそのようなセクションに移動するこずもできたす。

たぶん、譊告たたは「グリヌンスレッドに関する泚意」ペヌゞ。 スヌパヌプレスではありたせん。

geventワヌカヌず他のいく぀かのgunicornを実行しおいるHerokuでほが同じ動䜜が芋られたので、このスレッドで掚奚されおいるように同期ワヌカヌに切り替えたしたが、基本的に同じ深刻な問題が発生しおいたした。 H12の30秒のHerokuカットオフを取埗し、dyno党䜓をリセットするたで堎合によっおは1時間以䞊埌、たたはmax-requestsがヒットするたで、H12ず[CRITICAL] Worker Timeout゚ラヌを繰り返したした。 そこで、gunicornのタむムアりトを28秒に調敎しお、Herokuがタむムアりトする前にタむムアりトするようにしたした。 同じたたは非垞によく䌌た問題が1日に1〜2回発生し、マスタヌプロセスが再起動されるたで続きたす。今回は、gunicornが切断しおいるため、H13接続が閉じられおいるで始たりたす。 これらの期間䞭、トラフィックに倧きなスパむクはありたせん。

これが私の珟圚のprocfile゚ントリです

web: newrelic-admin run-program gunicorn publisher.wsgi -b 0.0.0.0:$PORT -w 4 --max-requests 1000 --timeout 28 --preload

䞀連のむベントの詳现

最初に、非垞に長い時間5秒以䞊かかるように芋えるいく぀かのリク゚ストを受け取り、次にリク゚ストがH12タむムアりトで倱敗しワヌカヌタむムアりトがそれを遮断し、さらにいく぀かのリク゚ストが終了したすが、非垞に長い時間20秒。 それ以降は、dynoを再起動するたで、玔粋なH1130秒のherokuカットオフです。

Webサヌバヌpython / djangoを実行ずしおgunicornv 18.0を䜿甚したす。

newrelicを実行したす。これは、ダりンタむムずめちゃくちゃ高いリク゚ストキュヌむング時間を瀺しおいたすが、他の掞察は提䟛しおいたせん。 NRで確認できるスルヌプットの急䞊昇やその他の異垞な状態はありたせんでした。 ログ凊理ず゚ラヌメヌルの送信にはペヌパヌトレむルを䜿甚したす。

Oct 15 15:08:53 nutrislice-stockton heroku/router: at=info method=GET path=/marketingtools/api/slides/?format=json-p&callback=_jqjsp&_1381871332239= host=oldham.nutrislice.com fwd="74.138.24.95" dyno=web.2 connect=15ms service=216ms status=200 bytes=21 Oct 15 15:08:54 nutrislice-stockton heroku/router: at=info method=GET path=/menu/api/menutypes/?format=json-p&callback=_jqjsp&_1381871332232= host=oldham.nutrislice.com fwd="74.138.24.95" dyno=web.2 connect=2ms service=90ms status=200 bytes=231 Oct 15 15:08:56 nutrislice-stockton heroku/router: at=info method=GET path=/menu/api/schools/?format=json-p&callback=_jqjsp&_1381871323514= host=oldham.nutrislice.com fwd="74.138.24.95" dyno=web.2 connect=3ms service=94ms status=200 bytes=5986 Oct 15 15:09:03 nutrislice-stockton heroku/router: at=info method=HEAD path=/heartbeat/ host=stockton.nutrislice.com fwd="54.247.188.179" dyno=web.2 connect=3ms service=23ms status=200 bytes=0 Oct 15 15:09:13 nutrislice-stockton heroku/router: at=info method=GET path=/menu/api/settings/?format=json-p&callback=_jqjsp&_1381871237946= host=pcsb.nutrislice.com fwd="66.87.110.127" dyno=web.2 connect=5ms service=166ms status=200 bytes=468 Oct 15 15:09:20 nutrislice-stockton heroku/router: at=info method=GET path=/menu/api/settings/?format=json-p&callback=_jqjsp&_1381871323611= host=oldham.nutrislice.com fwd="74.138.24.95" dyno=web.2 connect=6ms service=183ms status=200 bytes=453 Oct 15 15:09:40 nutrislice-stockton heroku/router: at=info method=GET path=/ host=nps.nutrislice.com fwd="74.190.240.28" dyno=web.2 connect=1ms service=260ms status=200 bytes=35951 Oct 15 15:09:55 nutrislice-stockton heroku/router: at=info method=GET path=/menuwidgets/api/list/school-menu-profile/87/menu-type/43/?format=json-p&callback=jQuery18008709754704032093_1381871379465&_=1381871393589 host=nps.nutrislice.com fwd="74.190.240.28" dyno=web.2 connect=15ms service=129ms status=200 bytes=400 Oct 15 15:09:55 nutrislice-stockton heroku/router: at=info method=GET path=/menuwidgets/api/list/school-menu-profile/306/menu-type/187/?format=json-p&callback=jQuery180013075259909965098_1381873891397&_=1381873896600 host=sdhc.nutrislice.com fwd="72.186.96.121" dyno=web.2 connect=2ms service=33ms status=200 bytes=486 Oct 15 15:10:00 nutrislice-stockton heroku/router: at=info method=GET path=/menuwidgets/186/?smp=257 host=coppellisd.nutrislice.com fwd="76.199.114.157" dyno=web.2 connect=7ms service=103ms status=200 bytes=323 Oct 15 15:10:00 nutrislice-stockton app/web.2: INFO http://stockton.nutrislice.com/heartbeat/ Pinged from IP: 10.190.159.205 -- AGENT: NewRelicPinger/1.0 (269661) Oct 15 15:10:00 nutrislice-stockton heroku/router: at=info method=HEAD path=/heartbeat/ host=stockton.nutrislice.com fwd="50.112.95.211" dyno=web.2 connect=1ms service=10ms status=200 bytes=0 Oct 15 15:10:09 nutrislice-stockton heroku/router: at=info method=GET path=/menuwidgets/239/?smp=341 host=edenpr.nutrislice.com fwd="75.73.177.139" dyno=web.2 connect=8ms service=334ms status=200 bytes=277 Oct 15 15:10:16 nutrislice-stockton heroku/router: at=info method=GET path=/menuwidgets/395/?smp=306 host=sdhc.nutrislice.com fwd="72.186.96.121" dyno=web.2 connect=1ms service=96ms status=200 bytes=245 Oct 15 15:10:20 nutrislice-stockton heroku/router: at=info method=GET path=/menuwidgets/391/?smp=305 host=sdhc.nutrislice.com fwd="173.170.34.126" dyno=web.2 connect=32ms service=5207ms status=200 bytes=290 Oct 15 15:10:22 nutrislice-stockton heroku/router: at=info method=GET path=/menuwidgets/350/?smp=305 host=sdhc.nutrislice.com fwd="173.170.34.126" dyno=web.2 connect=60ms service=7676ms status=200 bytes=1147 Oct 15 15:10:31 nutrislice-stockton heroku/router: at=info method=GET path=/menuwidgets/258/?smp=341 host=edenpr.nutrislice.com fwd="75.73.177.139" dyno=web.2 connect=42ms service=517ms status=200 bytes=26974 Oct 15 15:10:43 nutrislice-stockton heroku/router: at=info method=GET path=/menu/api/schools/?format=json-p&callback=_jqjsp&_1381871432885= host=ocps.nutrislice.com fwd="71.47.21.97" dyno=web.2 connect=1490ms service=9883ms status=200 bytes=1565 Oct 15 15:10:52 nutrislice-stockton heroku/router: at=error code=H13 desc="Connection closed without response" method=GET path=/ host=jordandistrict.nutrislice.com fwd="71.199.48.37" dyno=web.2 connect=1959ms service=29230ms status=503 bytes=0 Oct 15 15:10:52 nutrislice-stockton app/web.2: 2013-10-15 21:10:50 [2] [CRITICAL] WORKER TIMEOUT (pid:12) Oct 15 15:10:52 nutrislice-stockton app/web.2: 2013-10-15 21:10:50 [2] [CRITICAL] WORKER TIMEOUT (pid:12) Oct 15 15:10:52 nutrislice-stockton app/web.2: 2013-10-15 21:10:50 [26] [INFO] Booting worker with pid: 26 Oct 15 15:10:52 nutrislice-stockton app/web.2: 2013-10-15 21:10:50,930 (26/MainThread) newrelic.core.agent INFO - New Relic Python Agent (2.0.0.1) Oct 15 15:10:54 nutrislice-stockton heroku/router: at=info method=GET path=/surveys/api/activesurveycount/?format=json-p&callback=_jqjsp&_1381871433429= host=henrico.nutrislice.com fwd="96.248.5.53" dyno=web.2 connect=1181ms service=20074ms status=200 bytes=32 Oct 15 15:10:55 nutrislice-stockton heroku/router: at=info method=GET path=/menu/api/schooltypes/?format=json-p&callback=_jqjsp&_1381871433374= host=henrico.nutrislice.com fwd="96.248.5.53" dyno=web.2 connect=1136ms service=20393ms status=200 bytes=142 Oct 15 15:11:01 nutrislice-stockton app/web.2: using heroku production settings Oct 15 15:11:01 nutrislice-stockton app/web.2: WARNING /app/.heroku/python/lib/python2.7/site-packages/django/utils/hashcompat.py:9: DeprecationWarning: django.utils.hashcompat is deprecated; use hashlib instead Oct 15 15:11:01 nutrislice-stockton app/web.2: DeprecationWarning) Oct 15 15:11:01 nutrislice-stockton heroku/router: at=info method=GET path=/menu/api/settings/?format=json-p&callback=_jqjsp&_1381871432922= host=ocps.nutrislice.com fwd="71.47.21.97" dyno=web.2 connect=1435ms service=23198ms status=200 bytes=486 Oct 15 15:11:03 nutrislice-stockton app/web.2: WARNING /app/.heroku/python/lib/python2.7/site-packages/django/conf/urls/defaults.py:3: DeprecationWarning: django.conf.urls.defaults is deprecated; use django.conf.urls instead Oct 15 15:11:03 nutrislice-stockton app/web.2: DeprecationWarning) Oct 15 15:11:05 nutrislice-stockton heroku/router: at=info method=GET path=/menu/api/schooltypes/?format=json-p&callback=_jqjsp&_1381871443300= host=martinschools.nutrislice.com fwd="99.114.229.202" dyno=web.2 connect=1089ms service=20040ms status=200 bytes=268 Oct 15 15:11:10 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/menu/api/weeks/school-menu-profile/135/menu-type/63/2013/10/14/?format=json-p&callback=_jqjsp&_1381871439548= host=henrico.nutrislice.com fwd="96.248.5.53" dyno=web.2 connect=1018ms service=30001ms status=503 bytes=0 Oct 15 15:11:15 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/menu/api/sales/?format=json-p&callback=_jqjsp&_1381871443267= host=martinschools.nutrislice.com fwd="99.114.229.202" dyno=web.2 connect=1096ms service=30001ms status=503 bytes=0 Oct 15 15:11:15 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/menu/api/schools/?format=json-p&callback=_jqjsp&_1381871443296= host=martinschools.nutrislice.com fwd="99.114.229.202" dyno=web.2 connect=1108ms service=30000ms status=503 bytes=0 Oct 15 15:11:23 nutrislice-stockton heroku/router: at=info method=GET path=/menu/api/weeks/school-menu-profile/48/menu-type/21/2013/10/14/?format=json-p&callback=_jqjsp&_1381871449451= host=martinschools.nutrislice.com fwd="99.114.229.202" dyno=web.2 connect=1114ms service=31756ms status=200 bytes=48771 Oct 15 15:11:26 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/menu/api/sales/?format=json-p&callback=_jqjsp&_1381871455129= host=pcsb.nutrislice.com fwd="66.87.110.127" dyno=web.2 connect=990ms service=30001ms status=503 bytes=0 Oct 15 15:11:26 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/menu/api/schools/?format=json-p&callback=_jqjsp&_1381871455291= host=pcsb.nutrislice.com fwd="66.87.110.127" dyno=web.2 connect=1028ms service=30008ms status=503 bytes=0 Oct 15 15:11:31 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/menuwidgets/179/?smp=6 host=cusdnutrition.nutrislice.com fwd="68.99.246.16" dyno=web.2 connect=2492ms service=30000ms status=503 bytes=0 Oct 15 15:11:32 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/menuwidgets/192/?smp=6 host=cusdnutrition.nutrislice.com fwd="68.99.246.16" dyno=web.2 connect=2713ms service=30003ms status=503 bytes=0 Oct 15 15:11:39 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/menu/ host=hebisd.nutrislice.com fwd="38.107.226.1" dyno=web.2 connect=2115ms service=30001ms status=503 bytes=0 Oct 15 15:11:45 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/menu/api/weeks/school-menu-profile/44/menu-type/19/2013/10/14/?format=json-p&callback=_jqjsp&_1381871472583= host=pcsb.nutrislice.com fwd="66.87.110.127" dyno=web.2 connect=2168ms service=30000ms status=503 bytes=0 Oct 15 15:11:48 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/marketingtools/api/active-announcements/?format=json-p&callback=_jqjsp&_1381871476287= host=sdhc.nutrislice.com fwd="65.34.72.116" dyno=web.2 connect=1927ms service=30000ms status=503 bytes=0 Oct 15 15:11:48 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/surveys/api/activesurveycount/?format=json-p&callback=_jqjsp&_1381871476543= host=sdhc.nutrislice.com fwd="65.34.72.116" dyno=web.2 connect=2117ms service=30000ms status=503 bytes=0 Oct 15 15:11:48 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/menu/api/schooltypes/?format=json-p&callback=_jqjsp&_1381871476481= host=sdhc.nutrislice.com fwd="65.34.72.116" dyno=web.2 connect=2111ms service=30009ms status=503 bytes=0 Oct 15 15:11:50 nutrislice-stockton app/web.2: 2013-10-15 15:11:32,597 (26/NR-Activate-Session/nutrislice-stockton) newrelic.core.data_collector INFO - Successfully registered New Relic Python agent where app_name='nutrislice-stockton', pid=26, redirect_host='collector-2.newrelic.com' and agent_run_id=474482914, in 40.26 seconds. Oct 15 15:11:50 nutrislice-stockton app/web.2: INFO Successfully registered New Relic Python agent where app_name='nutrislice-stockton', pid=26, redirect_host='collector-2.newrelic.com' and agent_run_id=474482914, in 40.26 seconds. Oct 15 15:11:52 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/marketingtools/api/active-announcements/?format=json-p&callback=_jqjsp&_1381871480294= host=sdhc.nutrislice.com fwd="65.34.72.116" dyno=web.2 connect=1689ms service=30006ms status=503 bytes=0 Oct 15 15:11:55 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/menu/api/settings/?format=json-p&callback=_jqjsp&_1381871482566= host=henrico.nutrislice.com fwd="72.84.233.45" dyno=web.2 connect=2067ms service=30004ms status=503 bytes=0 Oct 15 15:11:57 nutrislice-stockton app/web.2: 2013-10-15 21:11:41 [2] [CRITICAL] WORKER TIMEOUT (pid:26) Oct 15 15:11:57 nutrislice-stockton app/web.2: 2013-10-15 21:11:41 [2] [CRITICAL] WORKER TIMEOUT (pid:26) Oct 15 15:11:57 nutrislice-stockton app/web.2: 2013-10-15 21:11:41 [29] [INFO] Booting worker with pid: 29 Oct 15 15:11:57 nutrislice-stockton app/web.2: 2013-10-15 21:11:41,067 (29/MainThread) newrelic.core.agent INFO - New Relic Python Agent (2.0.0.1) Oct 15 15:11:57 nutrislice-stockton app/web.2: using heroku production settings Oct 15 15:11:57 nutrislice-stockton app/web.2: WARNING /app/.heroku/python/lib/python2.7/site-packages/django/utils/hashcompat.py:9: DeprecationWarning: django.utils.hashcompat is deprecated; use hashlib instead Oct 15 15:11:57 nutrislice-stockton app/web.2: DeprecationWarning) Oct 15 15:11:57 nutrislice-stockton app/web.2: 2013-10-15 21:11:44 [2] [CRITICAL] WORKER TIMEOUT (pid:23) Oct 15 15:11:57 nutrislice-stockton app/web.2: 2013-10-15 21:11:44 [2] [CRITICAL] WORKER TIMEOUT (pid:23) Oct 15 15:11:57 nutrislice-stockton app/web.2: 2013-10-15 21:11:44 [32] [INFO] Booting worker with pid: 32 Oct 15 15:11:57 nutrislice-stockton app/web.2: 2013-10-15 21:11:44,154 (32/MainThread) newrelic.core.agent INFO - New Relic Python Agent (2.0.0.1) Oct 15 15:11:57 nutrislice-stockton app/web.2: using heroku production settings Oct 15 15:11:57 nutrislice-stockton app/web.2: WARNING /app/.heroku/python/lib/python2.7/site-packages/django/utils/hashcompat.py:9: DeprecationWarning: django.utils.hashcompat is deprecated; use hashlib instead Oct 15 15:11:57 nutrislice-stockton app/web.2: DeprecationWarning) Oct 15 15:11:57 nutrislice-stockton app/web.2: 2013-10-15 21:11:48 [2] [CRITICAL] WORKER TIMEOUT (pid:14) Oct 15 15:11:57 nutrislice-stockton app/web.2: 2013-10-15 21:11:48 [2] [CRITICAL] WORKER TIMEOUT (pid:14) Oct 15 15:11:57 nutrislice-stockton app/web.2: 2013-10-15 21:11:48 [35] [INFO] Booting worker with pid: 35 Oct 15 15:11:57 nutrislice-stockton app/web.2: 2013-10-15 21:11:48,273 (35/MainThread) newrelic.core.agent INFO - New Relic Python Agent (2.0.0.1) Oct 15 15:11:57 nutrislice-stockton app/web.2: using heroku production settings Oct 15 15:11:57 nutrislice-stockton app/web.2: WARNING /app/.heroku/python/lib/python2.7/site-packages/django/utils/hashcompat.py:9: DeprecationWarning: django.utils.hashcompat is deprecated; use hashlib instead Oct 15 15:11:57 nutrislice-stockton app/web.2: DeprecationWarning) Oct 15 15:11:57 nutrislice-stockton heroku/router: at=info method=GET path=/menuwidgets/353/?smp=306 host=sdhc.nutrislice.com fwd="72.186.96.121" dyno=web.2 connect=21ms service=76ms status=200 bytes=255 Oct 15 15:12:00 nutrislice-stockton app/web.2: 2013-10-15 21:11:54 [2] [CRITICAL] WORKER TIMEOUT (pid:13) Oct 15 15:12:00 nutrislice-stockton app/web.2: 2013-10-15 21:11:54 [2] [CRITICAL] WORKER TIMEOUT (pid:13) Oct 15 15:12:00 nutrislice-stockton app/web.2: 2013-10-15 21:11:54 [38] [INFO] Booting worker with pid: 38 Oct 15 15:12:00 nutrislice-stockton app/web.2: 2013-10-15 21:11:54,388 (38/MainThread) newrelic.core.agent INFO - New Relic Python Agent (2.0.0.1) Oct 15 15:12:00 nutrislice-stockton app/web.2: using heroku production settings Oct 15 15:12:01 nutrislice-stockton app/web.2: WARNING /app/.heroku/python/lib/python2.7/site-packages/django/utils/hashcompat.py:9: DeprecationWarning: django.utils.hashcompat is deprecated; use hashlib instead Oct 15 15:12:01 nutrislice-stockton app/web.2: DeprecationWarning) Oct 15 15:12:02 nutrislice-stockton app/web.2: WARNING /app/.heroku/python/lib/python2.7/site-packages/django/conf/urls/defaults.py:3: DeprecationWarning: django.conf.urls.defaults is deprecated; use django.conf.urls instead Oct 15 15:12:02 nutrislice-stockton app/web.2: DeprecationWarning) Oct 15 15:12:03 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/menuwidgets/353/?smp=306 host=sdhc.nutrislice.com fwd="108.9.154.78" dyno=web.2 connect=3650ms service=30006ms status=503 bytes=0 Oct 15 15:12:03 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/menuwidgets/395/?smp=306 host=sdhc.nutrislice.com fwd="108.9.154.78" dyno=web.2 connect=3581ms service=30006ms status=503 bytes=0 Oct 15 15:12:06 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/menu/api/settings/?format=json-p&callback=_jqjsp&_1381871492466= host=canyonsdistrict.nutrislice.com fwd="174.52.155.49" dyno=web.2 connect=3582ms service=30001ms status=503 bytes=0 Oct 15 15:12:09 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/mobile/api_version/?deviceType=iphone host=pasco.nutrislice.com fwd="173.65.148.9" dyno=web.2 connect=3837ms service=30004ms status=503 bytes=0 Oct 15 15:12:11 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/mobile/api_version/?deviceType=iphone host=canyonsdistrict.nutrislice.com fwd="174.52.155.49" dyno=web.2 connect=3987ms service=30001ms status=503 bytes=0 Oct 15 15:12:11 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/menu/api/schools/?format=json-p&callback=_jqjsp&_1381871497105= host=canyonsdistrict.nutrislice.com fwd="174.52.155.49" dyno=web.2 connect=3962ms service=30001ms status=503 bytes=0 Oct 15 15:12:11 nutrislice-stockton heroku/router: at=error code=H12 desc="Request timeout" method=GET path=/menu/api/menutypes/?format=json-p&callback=_jqjsp&_1381871497128= host=canyonsdistrict.nutrislice.com fwd="174.52.155.49" dyno=web.2 connect=4020ms service=30007ms status=503 bytes=0
そしお、このH12タむムアりトず[CRITICAL] WORKER TIMEOUTの「死のスパむラル」は、マスタヌプロセスが再開されるたで続きたす。

これが同じ問題なのか、別の問題なのか、䜕か考えはありたすか 修正する提案はありたすか gunicornはタむムアりト埌にワヌカヌプロセスを匷制終了し、新しく開始するので、通垞どおり凊理を開始できるず思いたすが、その埌はリク゚ストが届かないようです。 倚分それはHerokuの問題です。

+1この問題も芋られたす。

Herokuでもこの問題が発生しおいたす

@sprynmr @richardkeen gunicornを起動する方法ず、できるログを共有できたすか 問題を解決するのに倧いに圹立ちたす。

@nebstreborリク゚ストの数を制限しない堎合はどうなりたすか

私たちは次のようにそれを立ち䞊げおいたした
web: newrelic-admin run-program python manage.py run_gunicorn -b "0.0.0.0:$PORT" --log-level=DEBUG -w 3 -k gevent --max-requests 250

ログレベルのDEBUGを䜿甚しおも、䜕が起こっおいるかに぀いおのログの邪魔になるこずはあたりありたせんでした。 geventを䜿甚しないこずで、今のずころ問題は解決したしたが、理想的ではありたせん。

@sprynmrリク゚ストの最倧数を削陀するずどうなりたすか たた、geventのどのバヌゞョンですか

私たちは1.0rc2 。 リク゚ストの最倧数がわからない。 今のずころ、本番環境で再びオンに切り替えたくはありたせん。

リク゚ストタむムアりトに関するHerokuペヌゞを読んで、アプリケヌションタむムアりトwell under 30 seconds, such as 10 or 15を蚭定するこずを提案しおいたす。 gunicornのtimeoutパラメヌタヌを䜿甚しお提案を詊したしたか

ずにかく、geventで発生する問題は、おそらく接続の凊理方法が原因です。 ワヌカヌの珟圚のバヌゞョンは、このグリヌンレットの実際の監芖なしに、グリヌンレット/受け入れられた接続を生成しおいたす。 おそらく発生するのは、受け入れられた゜ケットの1぀が長時間埅機し、他のむベントが凊理されないため、gunicornワヌカヌが再起動するこずです。 しかし、私はチェックする必芁がありたす。

面癜い。 いいえ、詊したせんでした。

+1これは私のアプリケヌションでも芋られたす。 @Jwpe / @sprynmrこの問題の解決策に到達したこずはありたすか この問題に関するアクティビティが発生しおから2か月以䞊経過しおいるようです。 問題に察凊するための䜕かを芋぀けた堎合は、ぜひお聞かせください。

ありがずう

@dencoldはhttps://github.com/benoitc/gunicorn/issues/588#issuecomment-29267541を詊したしたか

私はherokuにアカりントを持っおいないので、それが䜕をするのかわかりたせん。 たた、同じログがありたすか

こんにちは@benoitc 、迅速な察応に感謝したす。 ログは、 @ Jwpeおよび@nebstreborが報告したものずたったく同じです。 問題を特定するのに圹立぀堎合は、関連するビットを取り出しおここに远加しおください。お知らせください。

以前のコメントからアドバむスを受け取り、gunicornのタむムアりトをherokuルヌタヌのタむムアりトよりも䜎くなるように構成しお、それが圹立぀かどうかを確認したす。 提案をありがずう。

このカスケヌド障害の実際の原因を芋぀けるこずは圹に立ちたす。 1人のワヌカヌが倱敗し、gunicornサヌバヌ党䜓が完党に応答しなくなるのを芋るのは本圓に奇劙です。 蚺断に圹立぀こずがあれば教えおください。 このタむムアりトをロヌカルで再珟するこずはできたせん。 これは、herokuむンフラストラクチャでのみ発生するようです。

申し蚳ありたせんが@dencold私は解決策を芋぀けられたせん

@dencoldも新しい遺物を䜿甚しおいたすか

@benoitcうん、私たちは新しい遺物も䜿っおいたす。

@dencoldも同様に、この問題を正垞に解決するこずはできたせんでした。 ゚ラヌの原因を突き止めるために投資する時間がなく、元のリク゚ストの期間を短瞮するこずに集䞭する必芁がありたした。 ただし、゚ラヌの重倧な性質ナヌザヌが盎面しおいるためにより、暫定的に問題を回避するためにWSGIサヌバヌを切り替えるこずになりたした。 したがっお、問題をさらに分類するための実隓はこれ以䞊実行しおいたせん。

@Jwpeは、少なくずも提案された゜リュヌションを詊したしたか たた、結果は奇劙で、gunicornだけでそれを再珟するこずは決しおありたせん。

カットオフ時間が15秒に短瞮されたしたが、ただ問題が発生しおいたした

2014幎1月26日日曜日には、ブノワChesneau [email protected]
曞きたした

@Jwpehttps //github.com/Jwpe少なくずも提案されたものを詊したしたか
解決 たた、結果は奇劙で、gunicornでそれを再珟するこずはありたせん
それ自䜓で。

—
このメヌルに盎接返信するか、Gi tHubhttps//github.com/benoitc/gunicorn/issues/588#issuecomment-3331633で衚瀺しおください
。

ベンロバヌツ
CTO
Nutrislice、Inc。
866-524-3444内線702
[email protected]

@Jwpe / @nebstreborこの問題に぀いおご誠にありがずう

@benoitc提案されたタむムアりト゜リュヌションをherokuむンスタンスに実装したした。 今埌数日間、これを泚意深く監芖したす。 新しいタむムアりトが蚭定された埌に同じ問題がポップアップするのを確認した堎合は、投皿したす。

助けおくれたみんなにもう䞀床感謝したす。 この問題が発生しおいるのは私だけではないこずを知っおおくずよいでしょう。 私たちが原因の根底に到達できるこずを願っおいたす。

@benoitcは、タむムアりトが蚭定されおから玄2週間が経過したこずを報告したかっただけです。 ワヌカヌのタむムアりトがいく぀か芋られたしたが、gunicornプロセス党䜓が応答しなくなる原因はありたせん。 これで問題は解決したようですが、そもそもなぜ30秒のタむムアりトがカスケヌド゚ラヌを匕き起こしおいたのかはわかりたせん。

投皿を続けたかっただけです。 ここですべおの助けをありがずう

RaspberryPIでgunicornを䜿甚しおDjangoを実行するず同じ[CRITICAL] WORKERTIMEOUT゚ラヌが発生したす。

ニュヌスはありたせん。

同じ[クリティカル]ワヌカヌタむムアりトが発生したす。
問題は、ワヌカヌの実際のタむムアりト長いリク゚ストの埌、gunicornがワヌカヌを匷制終了しお新しいワヌカヌを生成しようずしたすが、新しいワヌカヌがTIMEOUT制限内で開始できず、芪プロセスに通知する堎所に到達しないこずです。ラむブなので、gunicornは䜕床も䜕床もそれを殺したす:(。私たちの堎合、問題はGeventずSentryに関連しおいたしたhttps://github.com/getsentry/raven-python/issues/305。Sentryは起動時にハングしたす。
ずころで、ワヌカヌの開始時間ず、「タむムアりト」時間内に開始できないワヌカヌ内のいく぀かの远加ログに別々のタむムアりトを蚭定するず䟿利です。

タむムアりトは、同期ワヌカヌを陀いお芁求タむムアりトではありたせん。 他のワヌカヌは、長いリク゚ストを凊理する堎合でも、アヌビタヌにハヌトビヌトを送りたす。 その堎合のタむムアりト時間は起動タむムアりト時間です。

ある意味で、gunicornには「リク゚ストタむムアりト」はありたせん。

はい、ワヌカヌタむムアりトは非同期のリク゚ストタむムアりトずは異なりたす。 ただし、非同期の「コンテキスト切り替え」「゜ケット-読み取り/曞き蟌み」などが発生する可胜性のある関数呌び出しのない長時間実行リク゚ストは、ワヌカヌタむムアりトの原因です。 さらに、ワヌカヌの起動時にタむムアりトが発生する可胜性がありたす芁求がたったくない堎合。 しかし、Gunicornのログでは、これら2぀の異なるケヌスを区別する方法はなく、「WORKERTIMEOUT」ずいうメッセヌゞが1぀だけありたす。

リク゚ストタむムアりト蚭定を远加する必芁がありたすか これにより、起動時間が長いアプリはワヌカヌのタむムアりトを増やすこずができたす。

そうは思わないでください。
1リク゚ストの実行時間を枬定するのは難しいため、リク゚ストの開始時ず終了時の時間差を䜿甚するこずはできたせん。
2私が知っおいるように、「実行ナニット」コンテキストスむッチ間で実行されるコヌドの量のタむムアりトをキャッチするこずは、geventでは䞍可胜です。

それでは䜕か提案はありたすか

この問題が正圓なタむムアりトず朜圚的なカスケヌドのみが原因である堎合
最初の実行時に存圚しないサヌバヌ負荷によるタむムアりトがありたす
ここで䜕かするこずはありたすか たたは、この問題は解決可胜であり、これはより適切に凊理されたす
異なるレベルのむンフラストラクチャで運甚䞊
2014幎7月30日午埌1時14分、「Mkrtich」 [email protected]は次のように曞いおいたす。

そうは思わないでください。
1リク゚ストの実行時間を枬定するのは難しいため、時間差を䜿甚するこずはできたせん。
物乞いずリク゚ストの終わりに。
2私が知っおいるように、「実行ナニット」のタむムアりトコヌドの量をキャッチする
コンテキストスむッチ間で実行されるはgeventでは䞍可胜です。

—
このメヌルに盎接返信するか、GitHubで衚瀺しおください
https://github.com/benoitc/gunicorn/issues/588#issuecomment-50673040 。

2぀のタむムアりトパラメヌタず2぀の異なるログを甚意するこずをお勧めしたす。
11぀は、リク゚スト凊理䞭にのみ機胜する珟圚のタむムアりトパラメヌタです。
22぀目は、ワヌカヌの起動タむムアりトです。

この問題も芋おいたす

最終的にHerokuをuWSGIに切り替えお、より良い成功を収めたした... Gunicornの修正ではありたせんが、本番サヌバヌでこの問題が発生し、早急に解決が必芁な人には、この提案が圹立぀かもしれないず思いたした。 。

@nebstreborよくタむムアりトを䞋げる提案を詊みたしたか

@CrazyPythonチケットはクロヌズされたした。 あなたが抱えおいる問題ずそれを再珟する方法を説明した新しいチケットを開くこずができたすか それが同じ問題であるかどうか、䜕か他のものであるかどうかを理解するこずは間違いなく圹立ちたす:)

はい、䞊蚘のように、違いはありたせんでした。 問題は散発的でした
十分に再珟できなかったそしお壊滅的で、私たちがしなければならなかった
その動きをするそれは1幎以䞊でした。 私はGunicornが本圓に奜きですが
Herokuの倖郚でも問題なく䜿甚しおいたす。

ベンロバヌツ
CTO兌共同創蚭者
Nutrislice、Inc。
[email protected]
セル-801-735-7845

8:08の火、2015幎6月30日には、ブノワChesneau [email protected]
曞きたした

@nebstrebor https://github.com/nebstreborよくやっおみたしたか
タむムアりトを䞋げる提案

@CrazyPythonhttps //github.com/CrazyPythonチケットはクロヌズされたした。
新しいチケットを開くこずができたすかあなたが抱えおいる問題ずその方法を説明しおください
それを再珟したすか それが同じ問題であるかどうかを理解するこずは間違いなく圹立ちたす、
他の䜕かず共同:)

—
このメヌルに盎接返信するか、GitHubで衚瀺しおください
https://github.com/benoitc/gunicorn/issues/588#issuecomment-117199066 。

この問題も発生しおいるず思いたす。 䞡方のワヌカヌ--workers 2は、長時間実行されおいる芁求でハングアップし、最終的には匷制終了され--timeout 20、すぐに2぀のH13が衚瀺され、H12ずWORKERTIMEOUTが再起動し始めたす。 次の10分間、これは続き、ワヌカヌはタむムアりトに達しお再起動する前にリク゚ストを正垞に凊理できたせんでした。 そこで、dynoを再起動するず、修正されたした。

他に誰もメモを芋おいないこずに気付いた興味深い点の1぀は、問題の開始時に2぀のH13接続が応答なしで閉じられたが衚瀺され、最終的にSIGTERMを発行したずきに、H13の措氎が発生したこずです-48正確には、これは私たちが芋たのず同じ数のWORKER TIMEOUTですすぐにH13を芋た最初の2぀を陀く。 それが䜕を意味するのか正確にはわかりたせんが、疑わしいようです。

H13たたはH12ずは䜕ですか これはherokuからのものですか gunicornがバむンドされるポヌトはどのように䞎えられたすか herokuプロキシが゜ケットが閉じおいるこずを怜出しおいないのではないかず思いたす。

たた、どのワヌカヌを䜿甚しおいたすか

はい、Heroku゚ラヌコヌドです
H12-リク゚ストのタむムアりト-通垞は30秒https://devcenter.heroku.com/articles/error-codes#h12-request-timeout
H13-応答なしで接続が閉じられたした-https://devcenter.heroku.com/articles/error-codes#h13-connection-closed-without-response

線集gunicornが環境倉数ずしお存圚する堎合はPORTを䜿甚するこずに気付いたので、このようにポヌトを構成したす。

同期ワヌカヌを䜿甚しおいたす。

そしお、私も蚀及するのを忘れたした、私たちはgunicorn19.3.0を実行しおいたす

久しぶりに掻動がなかったので、発行を締め切りたした。 タむムアりトを遅らせるこずは、アプリケヌションを長時間起動する堎合に適しおいるかもしれたせんが、必芁に応じお別のチケットで実行する必芁がありたす。

new-relic adminprocfileを䜿甚したherokuのgunicornuvicornでも同じ問題が発生しおいたす。

newrelic-admin run-program gunicorn -w 4 -k uvicorn.workers.UvicornWorker app.main:fastapi_app -b 0.0.0.0:${PORT:-5000} --log-level info --access-logfile=- --logger-class=gunicorn_color.Logger --preload

これにより、システムが起動するずすぐにこのログが衚瀺されたす。

2021-03-19T13:18:19.187532+00:00 heroku[web.1]: State changed from starting to up
2021-03-19T13:18:51.964740+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=api-app-clienti-pr-49.herokuapp.com request_id=8742009a-3e56-4f83-a147-97ff84d4e30b fwd="5.89.111.249" dyno=web.1 connect=1ms service=30003ms status=503 bytes=0 protocol=https
2021-03-19T13:19:04.292784+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/api" host=api-app-clienti-pr-49.herokuapp.com request_id=85b6320a-7728-4074-87eb-b0992e7c3f9d fwd="5.89.111.249" dyno=web.1 connect=3ms service=30001ms status=503 bytes=0 protocol=https
このペヌゞは圹に立ちたしたか
0 / 5 - 0 評䟡