在 Heroku 上使用 Gunicorn 的 Falcon 应用

Falcon app using Gunicorn on Heroku stalls

我正在尝试使用 gunicorn 在 Heroku 上提供一个 falcon 应用程序。

我几乎按照 falcon 文档创建了一个基本应用程序。

我正在使用 psycopg2 在处理请求时向每个资源添加连接游标。

web: gunicorn app:api --log-level=DEBUG --worker-class=gevent

但是现在每个请求都会导致超时:

Feb 06 18:10:01 d.19db00e4-faf8-47bc-aaea-c78a52163a24 heroku/router:  at=error code=H12 desc="Request timeout" method=GET path="/" host=falcon-raptor-api.herokuapp.com request_id=3b29350f-8990-430c-92e8-02458d91a2f9 fwd="54.91.242.125" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0 

我认为这是 psycopg2 或 gunicorn 或两者的问题。

有什么建议吗?

听起来好像在 gevent greenthead 中进行了阻塞调用。确保在申请期间尽早手动修补或猴子修补相关网络库(套接字、psycopg2 等)。

Using gevent monkey patching with threading makes thread work serially

我在 Heroku 上使用 Gunicorn 部署 Falcon API 时遇到了类似的问题。我的问题是我没有使用 Gunicorn 的 bind 参数,所以没有可监听的套接字。 Heroku 使用动态端口号,所以最好只使用 $PORT 变量。在您的 Procfile 中尝试这样的事情:

web: gunicorn -b 0.0.0.0:$PORT app:api --log-level=DEBUG --worker-class=gevent

我在 Heroku 中使用 Falcon。

在 proc 文件中使用以下内容

web: gunicorn api:app --log-level=DEBUG --worker-class=gevent

这里我假设您想 运行 "api.py" 在 Heroku 中使用 Gunicorn 文件。

希望这能解决您的问题。