我们正在运行一个 Fastapi + Uvicorn Web 应用程序,使用 Gunicorn 作为进程管理器,使用 Nginx 作为反向代理服务器。对于大多数 I/O 操作(数据库调用、Rest api),应用程序都以异步模式运行。整个设置在 Ubuntu 16.04 上的 Docker 容器内运行。
\n该设置在大多数情况下都有效,但有时它根本不处理请求,并且在 Nginx 端超时。我们还尝试将 Nginx 从设置中删除,并观察到在很长一段时间(例如 15 分钟后)后很少有请求得到处理。这是非常随机的,但通常在一小时内发生 2-3 次。
\n下面是我们使用的gunicorn配置\xe2\x80\x93
\nhost = 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") \nRun Code Online (Sandbox Code Playgroud)\n并用命令调用gunicornexec gunicorn -k uvicorn.workers.UvicornWorker -c "$GUNICORN_CONF" "$APP_MODULE"
我们尝试了一些配置更改,例如 \xe2\x80\x93
\n