如何计算 Google AppEngine 中失败任务的百分比?
How to compute the percentage of failed tasks in Google AppEngine?
我正在使用来自 GAE (python) 的 push task queue。有时 X 分钟后,Y% 的任务失败了。
对于这种情况,我想清除任务队列(没有必要执行它们,最终很多都会失败)。
我可以将任务配置为在重试超过 2 次时停止执行,但是如果我有 100 个任务失败(300 次运行 = 100 + 200 次重试),我该如何停止剩余的任务执行?
queue.yaml:
queue:
- name: my-queue
mode: push
rate: 1/s
bucket_size: 10
max_concurrent_requests: 10
retry_parameters:
task_retry_limit: 2
我会在内存缓存中存储一些值,例如 number of tasks in queue
和 timestamps of tasks that failed
。
每个任务都需要执行这些任务:
- 开始时,计算滚动百分比(在最后 X 分钟内),如果百分比太高则退出,或者增加
number of tasks
计数器并继续。
- 失败时,
减少
number of tasks
计数器并向
failed tasks
列表。
- 成功后,减少
number of tasks
柜台.
要计算滚动百分比,请获取 failed tasks
的整个列表并过滤掉那些太旧的时间戳(超过 X 分钟前)。将新列表放回内存缓存中。然后,使用 number of tasks
计数器并计算 100.0 * (number of failed tasks) / (number of tasks)
以获得您的百分比。如果超过 Y% 阈值,请立即退出您的任务。
我正在使用来自 GAE (python) 的 push task queue。有时 X 分钟后,Y% 的任务失败了。 对于这种情况,我想清除任务队列(没有必要执行它们,最终很多都会失败)。
我可以将任务配置为在重试超过 2 次时停止执行,但是如果我有 100 个任务失败(300 次运行 = 100 + 200 次重试),我该如何停止剩余的任务执行?
queue.yaml:
queue:
- name: my-queue
mode: push
rate: 1/s
bucket_size: 10
max_concurrent_requests: 10
retry_parameters:
task_retry_limit: 2
我会在内存缓存中存储一些值,例如 number of tasks in queue
和 timestamps of tasks that failed
。
每个任务都需要执行这些任务:
- 开始时,计算滚动百分比(在最后 X 分钟内),如果百分比太高则退出,或者增加
number of tasks
计数器并继续。 - 失败时,
减少
number of tasks
计数器并向failed tasks
列表。 - 成功后,减少
number of tasks
柜台.
要计算滚动百分比,请获取 failed tasks
的整个列表并过滤掉那些太旧的时间戳(超过 X 分钟前)。将新列表放回内存缓存中。然后,使用 number of tasks
计数器并计算 100.0 * (number of failed tasks) / (number of tasks)
以获得您的百分比。如果超过 Y% 阈值,请立即退出您的任务。