小编Hri*_*kar的帖子

Uvicorn 不随机处理某些请求

我们正在运行一个 Fastapi + Uvicorn Web 应用程序,使用 Gunicorn 作为进程管理器,使用 Nginx 作为反向代理服务器。对于大多数 I/O 操作(数据库调用、Rest api),应用程序都以异步模式运行。整个设置在 Ubuntu 16.04 上的 Docker 容器内运行。

\n

该设置在大多数情况下都有效,但有时它根本不处理请求,并且在 Nginx 端超时。我们还尝试将 Nginx 从设置中删除,并观察到在很长一段时间(例如 15 分钟后)后很少有请求得到处理。这是非常随机的,但通常在一小时内发生 2-3 次。

\n

下面是我们使用的gunicorn配置\xe2\x80\x93

\n
host = os.getenv("HOST", "0.0.0.0")\nport = os.getenv("PORT", "80")\n\n# Gunicorn config variables\nworkers = web_concurrency\nbind = f"{host}:{port}"\nkeepalive = 2\n\ntimeout = 60  \ngraceful_timeout = 30\nthreads = 2\nworker_tmp_dir = "/dev/shm"\n# Logging mechanism\ncapture_output = True\nloglevel = os.getenv("LOG_LEVEL", "debug") \n
Run Code Online (Sandbox Code Playgroud)\n

并用命令调用gunicornexec gunicorn -k uvicorn.workers.UvicornWorker -c "$GUNICORN_CONF" "$APP_MODULE"

\n

我们尝试了一些配置更改,例如 \xe2\x80\x93

\n
    \n
  1. 改变worker数量、worker超时
  2. \n …

nginx gunicorn python-asyncio fastapi uvicorn

9
推荐指数
0
解决办法
2460
查看次数

标签 统计

fastapi ×1

gunicorn ×1

nginx ×1

python-asyncio ×1

uvicorn ×1