当前位置:网站首页>函数计算异步任务能力介绍 - 任务触发去重
函数计算异步任务能力介绍 - 任务触发去重
2022-07-04 03:40:00 【InfoQ】
前言
浅谈任务去重

- At-Most-Once:保证消息最多被传递一次。当出现网络分区、系统组件宕机时,可能出现消息丢失;
- At-Least-Once:保证消息至少被传递一次。消息传递链路支持错误重试,利用消息重发机制保证下游一定收到上游消息,但是在宕机或者网络分区的场景下,可能导致相同消息传递多次。
- Exactly-Once 机制则可以保证消息精确被传送一次,精确一次并不是意味着在宕机或网络分区的场景下没有重传,而是重传对于接受方的状态不产生任何改变,与传送一次的结果一样。在实际生产中,往往是依赖重传机制 & 接收方去重(幂等)来做到 Exactly Once。
- 系统侧保障:任务调度系统自身的 failover 不影响消息的传递正确性及唯一性;
- 提供给用户一种机制,可以结合业务场景,做到整个业务逻辑的触发+执行去重。
函数计算异步任务触发去重的实现背景

- 系统侧保障:在步骤 2.1 - 3.1 中,任何一个中间过程的 Failover 只能触发一次步骤 3.2 的执行,即只会调度一次用户实例的运行;
- 用户侧应用级别去重能力:能够支持用户多次反复执行步骤 1,但实际只会触发一次 步骤 3.2 的执行。
系统侧优雅升级 & Failover 时的任务分发去重保证
- 消费的唯一性:每一个队列中的每一条消息当被消费后,会进入“不可见模式”。在此模式下,其他消费者无法获取该消息;
- 每条消息的实际消费者需要实时更新该模式的不可见时间;当消费者消费完成后,需要显示的删除该消息。

- 根据函数计算负载均衡模块的调度策略,监听自身所负责的队列;
- 当队列中出现消息后,拉取消息,并在内存中维持一个状态:直到消息消费完成(用户实例返回函数执行结果)前,不断更新消息的可见时间,确保消息不会再次在队列中出现;
- 当任务执行完成后,显示删除该消息。

- 如果消息还未传递到用户的执行实例中(图 2 中的步骤 3.1 ~ 3.2),那么当这台 Scheduler 负责的队列被其他 Scheduler 拾起后,消息将在消费可见期后再次出现,因此 Scheduler 2 将再次获取该消息,做到后续的触发。
- 如果消息已经开始执行(步骤 3.2),当消息在 Scheduler 2 中再次出现后,我们依赖用户 VM 中的 Agent 进行状态管理。此时 Scheduler 2 将向对应的 Agent 发送执行请求;此时 Agent 发现该消息已经存在于内存中,那么将直接忽略执行请求,并将执行的结果在执行后通过此链接告知 Scheduler 2,进而完成 Failover 的恢复。
用户侧业务级别的分发去重实现
- 消息未到达函数计算系统,任务未成功提交;
- 消息已经到达函数计算并入队,任务提交成功,但由于超时用户无法得知提交成功的信息。
import fc "github.com/aliyun/fc-go-sdk"
func SubmitJob() {
invokeInput := fc.NewInvokeFunctionInput("ServiceName", "FunctionName")
invokeInput = invokeInput.WithAsyncInvocation().WithStatefulAsyncInvocationID("TaskUUID")
invokeOutput, err := fcClient.InvokeFunction(invokeInput)
...
}
总结
1 分钟 Serverless 极速搭建真网站


点击
此处
,直达体验!
边栏推荐
- Learning video website
- PHP database connection succeeded, but data cannot be inserted
- [Valentine's Day confession code] - Valentine's Day is approaching, and more than 10 romantic love effects are given to the one you love
- SQL語句加强練習(MySQL8.0為例)
- Rhcsa day 3
- 2006 translation
- super_ Subclass object memory structure_ Inheritance tree traceability
- Solve the problems encountered by the laravel framework using mongodb
- Katalon框架测试web(二十一)获取元素属性断言
- Which product is better for 2022 annual gold insurance?
猜你喜欢
What are the virtual machine software? What are their respective functions?
SQL injection (1) -- determine whether there are SQL injection vulnerabilities
Redis notes (I) Linux installation process of redis
Dare to climb here, you're not far from prison, reptile reverse actual combat case
SQL statement strengthening exercise (MySQL 8.0 as an example)
Katalon框架测试web(二十六)自动发邮件
Contest3145 - the 37th game of 2021 freshman individual training match_ 1: Origami
The 37 year old programmer was laid off, and he didn't find a job for 120 days. He had no choice but to go to a small company. As a result, he was confused
Tsinghua University product: penalty gradient norm improves generalization of deep learning model
渗透实战-guest账户-mimikatz-向日葵-sql提权-离线解密
随机推荐
CSP drawing
Baijia forum the founding of the Eastern Han Dynasty
Explain AI accelerator in detail: why is this the golden age of AI accelerator?
What is cloud primordial?
[PaddleSeg 源码阅读] PaddleSeg计算Dice
[development team follows] API specification
数据库SQL语句汇总,持续更新......
[Valentine's Day confession code] - Valentine's Day is approaching, and more than 10 romantic love effects are given to the one you love
The property of judging odd or even numbers about XOR.
Examination question bank of constructor decoration direction post skills (constructor) and examination data of constructor decoration direction post skills (constructor) in 2022
Database SQL statement summary, continuous update
Object oriented -- encapsulation, inheritance, polymorphism
Add token validation in swagger
Command Execution Vulnerability - command execution - vulnerability sites - code injection - vulnerability exploitation - joint execution - bypass (spaces, keyword filtering, variable bypass) - two ex
Audio and video technology development weekly | 232
Es network layer
機器學習基礎:用 Lasso 做特征選擇
If you have just joined a new company, don't be fired because of your mistakes
AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving
Is online futures account opening safe and reliable? Which domestic futures company is better?