Jam*_*son 5 python google-app-engine google-app-engine-python
我在谷歌应用程序引擎上使用python,并不断接收google.appengine.api.urlfetch_errors.DeadlineExceededError从进行一些后端处理的机器发出的请求。这些请求大约需要 60 秒,有时会更长一些,因此我尝试延长截止日期。
请求被包装在重试中,从日志中我可以看到重试之间的时间始终约为 60 秒。我认为这要么是因为我配置不正确,要么误解了截止日期的限制。
机器配置为:
instance_class: B8
basic_scaling:
max_instances: 1
idle_timeout: 10m
Run Code Online (Sandbox Code Playgroud)
我正在使用的代码是(为简单起见进行了编辑):
from google.appengine.api import urlfetch
from retrying import retry
timeout = 600
retries = 10
@retry(
stop_max_attempt_number=retries,
wait_exponential_multiplier=1000,
wait_exponential_max=1000*60*5
)
def fetch(url):
"""Fetch remote data, retrying as necessary"""
urlfetch.set_default_fetch_deadline(timeout)
result = urlfetch.fetch(url)
if result.status_code != 200:
raise IOError("Did not receive OK response from server")
return result.content
data = fetch(config['url'])
Run Code Online (Sandbox Code Playgroud)
我尝试过明确设置截止日期,urlfetch.fetch(url, deadline=timeout)但设置默认值似乎是大多数人建议的方法。
谁能澄清是否可以设置最大值deadline?
请求计时器
Google App Engine 请求计时器 (Java/Python/Go) 确保请求具有有限的生命周期,并且不会陷入无限循环。目前,向前端实例发出请求的截止时间为 60 秒。(后端实例没有相应的限制。)每个请求,包括预热(对 /_ah/warmup 的请求)和加载请求(“loading_request=1”日志头),都受此限制。
如果请求未能在 60 秒内返回,并且抛出 DeadlineExceededError 且未被捕获,则请求将中止并返回 500 内部服务器错误。如果捕获了 DeadlineExceededError 但没有足够快地生成响应(您的时间不到一秒),则请求将中止并返回 500 内部服务器错误。
据我阅读该文档,我认为应用程序引擎中的最大请求超时为 60 秒。 这是文档的链接