【发布时间】:2020-08-17 04:11:48
【问题描述】:
由于实例限制。所以有一个请求,它在队列中的等待时间足够长,但 App Engine 自动缩放无法启动新实例。
这个请求会发生什么?它是无限期地保留在队列中还是在一段时间后中止?
【问题讨论】:
标签: google-app-engine instance autoscaling
由于实例限制。所以有一个请求,它在队列中的等待时间足够长,但 App Engine 自动缩放无法启动新实例。
这个请求会发生什么?它是无限期地保留在队列中还是在一段时间后中止?
【问题讨论】:
标签: google-app-engine instance autoscaling
它会向用户返回一条消息“Rate exceeded.”,并在日志中出现以下错误“Request was aborted after waiting too long to try to service your request."
这是我的测试方法:
我创建了一个类来计算经过的时间,以确保我确实在执行多个并发请求。还有一个基本的 Python 应用程序,它具有 20 秒的睡眠功能。 然后在 app.yaml 中,我将 max-instances 设置为 1,将 max-concurrent requests 设置为 1。 然后只需打开 5 个带有应用程序 URL 的选项卡并同时运行它们,其中至少有一个会因上述错误而失败。
根据 GAE 标准测试
timer.py:
import time
class TimerError(Exception):
"""A custom exception used to report errors in use of Timer class"""
class Timer:
def __init__(self):
self._start_time = None
def start(self):
"""Start a new timer"""
if self._start_time is not None:
raise TimerError(f"Timer is running. Use .stop() to stop it")
self._start_time = time.perf_counter()
def stop(self):
"""Stop the timer, and report the elapsed time"""
if self._start_time is None:
raise TimerError(f"Timer is not running. Use .start() to start it")
elapsed_time = time.perf_counter() - self._start_time
self._start_time = None
print(f"Elapsed time: {elapsed_time:0.4f} seconds")
main.py:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
import time
from timer import Timer
t = Timer()
t.start()
print('Started')
time.sleep(20)
t.stop()
return 'Hello World!'
if __name__ == '__main__':
requirements.txt:
Flask==1.1.2
codetiming
app.yaml:
service: scaling
runtime: python37
instance_class: F1
automatic_scaling:
target_cpu_utilization: 0.65
min_instances: 1
max_instances: 1
min_pending_latency: 30ms # default value
max_pending_latency: automatic
max_concurrent_requests: 1
部署:
gcloud app deploy
然后:同时打开 5 个标签页,其中包含已部署应用的链接。
结果: 用户得到:“速率超出。” GAE 日志显示:错误“请求在等待太长时间以尝试处理您的请求后被中止。”
【讨论】: