Commit ·
dcfc9ea
1
Parent(s): 0032c7c
gunicorn本番運用設定を統一・強化
Browse filesDockerfileにworkerクラスをgthreadへThreads4を追加して
Procfile/render.yamlと揃え、全環境で--max-requests/
--max-requests-jitterによるワーカー定期再起動と
--access-logfile/--error-logfileによる標準出力ログ出力を追加。
- CLAUDE.md +2 -1
- Dockerfile +1 -1
- Procfile +1 -1
- render.yaml +1 -1
CLAUDE.md
CHANGED
|
@@ -38,8 +38,9 @@ python web_app.py
|
|
| 38 |
|
| 39 |
### 本番相当
|
| 40 |
```bash
|
| 41 |
-
gunicorn 'web_app:create_app()' --bind 0.0.0.0:$PORT --workers 1 --worker-class gthread --threads 4 --timeout 120
|
| 42 |
```
|
|
|
|
| 43 |
※ Flask-Caching の `SimpleCache` はプロセスローカルのため、`workers` を2以上にすると
|
| 44 |
ワーカー間でキャッシュ無効化(`delete_memoized`)が伝播せず古いデータが表示される(#37)。
|
| 45 |
並列度はワーカー数ではなく `--threads` で確保すること。
|
|
|
|
| 38 |
|
| 39 |
### 本番相当
|
| 40 |
```bash
|
| 41 |
+
gunicorn 'web_app:create_app()' --bind 0.0.0.0:$PORT --workers 1 --worker-class gthread --threads 4 --timeout 120 --max-requests 500 --max-requests-jitter 50 --access-logfile - --error-logfile -
|
| 42 |
```
|
| 43 |
+
`--max-requests`はワーカーを一定リクエスト数ごとに再起動させ、メモリ肥大やキャッシュの蓄積をリセットする(`--max-requests-jitter`で再起動タイミングをずらす)。`--access-logfile -`/`--error-logfile -`で標準出力にログを出し、Render/HF Spacesのログビューアで追跡できるようにする。
|
| 44 |
※ Flask-Caching の `SimpleCache` はプロセスローカルのため、`workers` を2以上にすると
|
| 45 |
ワーカー間でキャッシュ無効化(`delete_memoized`)が伝播せず古いデータが表示される(#37)。
|
| 46 |
並列度はワーカー数ではなく `--threads` で確保すること。
|
Dockerfile
CHANGED
|
@@ -14,4 +14,4 @@ COPY . .
|
|
| 14 |
ENV PORT=8080
|
| 15 |
EXPOSE 8080
|
| 16 |
|
| 17 |
-
CMD ["sh", "-c", "gunicorn 'web_app:create_app()' --bind 0.0.0.0:$PORT --workers 1 --timeout 120"]
|
|
|
|
| 14 |
ENV PORT=8080
|
| 15 |
EXPOSE 8080
|
| 16 |
|
| 17 |
+
CMD ["sh", "-c", "gunicorn 'web_app:create_app()' --bind 0.0.0.0:$PORT --workers 1 --worker-class gthread --threads 4 --timeout 120 --max-requests 500 --max-requests-jitter 50 --access-logfile - --error-logfile -"]
|
Procfile
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
web: gunicorn 'web_app:create_app()' --bind 0.0.0.0:$PORT --workers 1 --worker-class gthread --threads 4 --timeout 120
|
|
|
|
| 1 |
+
web: gunicorn 'web_app:create_app()' --bind 0.0.0.0:$PORT --workers 1 --worker-class gthread --threads 4 --timeout 120 --max-requests 500 --max-requests-jitter 50 --access-logfile - --error-logfile -
|
render.yaml
CHANGED
|
@@ -5,7 +5,7 @@ services:
|
|
| 5 |
buildCommand: pip install -r requirements.txt
|
| 6 |
# SimpleCache(プロセスローカル)のキャッシュ無効化を全ワーカーに伝播させるため、
|
| 7 |
# workers=1 + gthread のマルチスレッド構成にする(#37)
|
| 8 |
-
startCommand: gunicorn "web_app:create_app()" --bind 0.0.0.0:$PORT --workers 1 --worker-class gthread --threads 4 --timeout 120
|
| 9 |
envVars:
|
| 10 |
- key: SECRET_KEY
|
| 11 |
generateValue: true
|
|
|
|
| 5 |
buildCommand: pip install -r requirements.txt
|
| 6 |
# SimpleCache(プロセスローカル)のキャッシュ無効化を全ワーカーに伝播させるため、
|
| 7 |
# workers=1 + gthread のマルチスレッド構成にする(#37)
|
| 8 |
+
startCommand: gunicorn "web_app:create_app()" --bind 0.0.0.0:$PORT --workers 1 --worker-class gthread --threads 4 --timeout 120 --max-requests 500 --max-requests-jitter 50 --access-logfile - --error-logfile -
|
| 9 |
envVars:
|
| 10 |
- key: SECRET_KEY
|
| 11 |
generateValue: true
|