Python Passenger 上的 Flask 无法处理少量并发请求

Python Flask on Passenger cannot handle small numbers of concurrent requests

我在 Passenger 上有一个 Flask (Python) 应用程序 运行,当我测试它时它工作得非常好,而且我是唯一的用户。

但是一旦我尝试建立多个并发连接,每个客户端就会永远等待响应。我试过50个并发用户,应该很容易支持。

该应用程序非常简单,读取和写入 SQLite 数据库一次或两次。 (这一小部分用户并发访问 SQLite is not a problem。)

我错过了什么?

Passenger docs中提出以下建议:

Passenger also supports the magic file 'tmp/always_restart.txt'. If this file exists, Passenger will restart your application after every request. This way you do not have to invoke the restart command often.

Activate this mechanism by creating the file:

$ mkdir -p tmp

$ touch tmp/always_restart.txt

这对开​​发非常有用,因为这意味着您只需保存 Python 文件,即可为客户提供最新版本的应用程序。

但这对生产来说很糟糕,因为每个客户端都会发出自己的请求并重新启动 Python 应用程序。这对服务器来说是一个非常大的开销,因此用户很可能在收到响应之前超时。

删除文件 tmp/always_restart.txt,您的并发限制将会激增。