如果自动缩放无法创建新实例,App Engine 请求会怎样?
What happens to an App Engine request if autoscaling can't create a new instance?
因为实例限制。所以有一个请求,它在队列中的时间足够长,但 App Engine 自动缩放无法启动新实例。
这个请求会怎样?它是无限期地保留在队列中还是在一段时间后中止?
它 returns 向用户发送消息“Rate exceeded.”,日志中出现以下错误“Request was aborted after waited too很想尝试满足您的请求。"
我是这样测试的:
我创建了一个 class 来计算经过的时间,以确保我确实在执行多个并发请求。还有一个具有 20 秒休眠功能的基本 Python 应用程序。
然后在 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
然后:同时打开部署的应用程序link的5个选项卡。
结果:
用户得到:“超出速率。”
GAE 日志显示:错误“请求在等待太长时间尝试服务您的请求后被中止。”
因为实例限制。所以有一个请求,它在队列中的时间足够长,但 App Engine 自动缩放无法启动新实例。
这个请求会怎样?它是无限期地保留在队列中还是在一段时间后中止?
它 returns 向用户发送消息“Rate exceeded.”,日志中出现以下错误“Request was aborted after waited too很想尝试满足您的请求。"
我是这样测试的:
我创建了一个 class 来计算经过的时间,以确保我确实在执行多个并发请求。还有一个具有 20 秒休眠功能的基本 Python 应用程序。 然后在 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
然后:同时打开部署的应用程序link的5个选项卡。
结果: 用户得到:“超出速率。” GAE 日志显示:错误“请求在等待太长时间尝试服务您的请求后被中止。”