当前位置:网站首页>函数计算异步任务能力介绍 - 任务触发去重
函数计算异步任务能力介绍 - 任务触发去重
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 极速搭建真网站


点击
此处
,直达体验!
边栏推荐
- The property of judging odd or even numbers about XOR.
- Defensive programming skills
- Setting methods, usage methods and common usage scenarios of environment variables in postman
- [Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- logistic regression
- ctf-pikachu-CSRF
- Simple dialogue system -- text classification using transformer
- JVM family -- monitoring tools
- 2022 attached lifting scaffold worker (special type of construction work) free test questions and attached lifting scaffold worker (special type of construction work) examination papers 2022 attached
猜你喜欢

Summary of Chinese remainder theorem

No clue about the data analysis report? After reading this introduction of smartbi, you will understand!

1289_FreeRTOS中vTaskSuspend()接口实现分析

ctf-pikachu-CSRF

What is cloud primordial?

Third party login initial version

Webhook triggers Jenkins for sonar detection

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

Reduce function under functools

微信公众号网页授权
随机推荐
2022 Guangxi provincial safety officer a certificate examination materials and Guangxi provincial safety officer a certificate simulation test questions
SQL statement strengthening exercise (MySQL 8.0 as an example)
用于TCP协议交互的TCPClientDemo
Leetcode51.n queen
1day vulnerability pushback skills practice (3)
Recent learning fragmentation (14)
How about the ratings of 2022 Spring Festival Gala in all provinces? Map analysis helps you show clearly!
Recursive structure
[untitled]
Handler source code analysis
Baijia forum the founding of the Eastern Han Dynasty
system information
Learning video website
PMP 考試常見工具與技術點總結
GUI Graphical user interface programming (XIV) optionmenu - what do you want your girlfriend to wear on Valentine's day
[Valentine's Day confession code] - Valentine's Day is approaching, and more than 10 romantic love effects are given to the one you love
Want to do something in production? Then try these redis commands
Rhcsa day 2
Defensive programming skills
Have you entered the workplace since the first 00???