Python中的uWSGI请求超时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24127601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 04:03:37  来源:igfitidea点击:

uWSGI request timeout in Python

pythonuwsgi

提问by Juan Carlos Coto

Trying to set the timeout for requests in uWSGI, I'm not sure of the correct setting. There seem to be multiple timeout options (socket, interface, etc.) and it's not readily evident which setting to configure or where to set it.

尝试为 uWSGI 中的请求设置超时,我不确定设置是否正确。似乎有多个超时选项(套接字、接口等),而且要配置哪个设置或在哪里设置它并不容易。

The behavior I'm looking for is to extend the time a request to the resource layer of a REST application can take.

我正在寻找的行为是延长对 REST 应用程序资源层的请求可能需要的时间。

采纳答案by Tombart

You're propably looking for the harakiriparameter - if request takes longer than specified harakiri time (in seconds), the request will be dropped and the corresponding worker recycled.

您可能正在寻找harakiri参数 - 如果请求花费的时间超过指定的 harakiri 时间(以秒为单位),则该请求将被丢弃并回收相应的工作人员。

For standalone uwsgi (ini config):

对于独立的 uwsgi(ini 配置):

[uwsgi]
http = 0.0.0.0:80
harakiri = 30
...

If you have nginx proxy before uwsgi you have to increase timeout as well:

如果在 uwsgi 之前有 nginx 代理,则还必须增加超时时间:

  location / {
    proxy_pass http://my_uwsgi_upstream;
    proxy_read_timeout 30s;
    proxy_send_timeout 30s;
  }

If you want (for some strange reason) higher timeout than 60s, you might consider communication over uwsgiprotocol. Configuration is quite similar nginx site:

如果您想要(出于某种奇怪的原因)超过 60 秒的超时时间,您可以考虑通过uwsgi协议进行通信。nginx站点的配置很相似:

location / {
    uwsgi_read_timeout 120s;
    uwsgi_send_timeout 120s;
    uwsgi_pass  my_upstream;
    include     uwsgi_params;
}

uwsgi:

uwsgi:

[uwsgi]
socket = 0.0.0.0:80
protocol = uwsgi
harakiri = 120
...

回答by iurii

Setting http-timeoutworked for me. I have http = :8080, so I assume if you use file system socket, you have to use socket-timeout.

设置http-timeout对我有用。我有http = :8080,所以我假设如果你使用文件系统套接字,你必须使用socket-timeout.