当前位置:网站首页>gRPC闭包调度器
gRPC闭包调度器
2022-08-11 01:44:00 【real沛林】
ExecCtx
代码中对这个结构的作用说明是在调用栈上收集数据信息。
考虑下面的场景:
A,B,C,D为4个依次调用的函数,B执行过程中调度了一个闭包1,并希望其在返回到A时执行。D同样调度了闭包2,也希望返回到A时再执行。这个时候就要使用这个调度器了grpc_schedule_on_exec_ctx.
要达到这种目的,我们要做的就是在A中声明ExecCtx,然后在B,D中调度绑定给grpc_schedule_on_exec_ctx调度器的闭包,然后在返回A时调用ExecCtx的Flush方法,这样就能达到目的了.ExecCtx内部维护了一个队列,用于存放调度给它的闭包。调用Flush方法时再依次从队列中取出闭包并运行。
在最新的gRPC版本中,简化了这种调度器的使用方法。gRPC框架为每个线程创建了这个ExecCtx,并存放在线程私有变量中,当需要时,只需要调用grpc_core::ExecCtx::Get()即可获取并使用。
链接:https://blog.csdn.net/happyAnger6/article/details/102753742
Flush
图14-2演示了Flush是如何调度任务的
1、2箭头过后,已经把readable或者writable的任务放入了closure_list中3箭头开始for循环执行Flush操作,Flush会执行closure_list的任务,当closure_list为空后,会执行combiner_data中的任务
- 第一种场景:执行closure_list中的job1,又生成了新的job1-1放入了closure_list中,见路径:4-4.1-4.2-4.3
- 第二种场景:执行closure_list中的job1,又生成了新的job1-1放入了combiner_data中,见路径:4-4.1-4.4-4.5
- 第三中场景:执行combiner_data中的job2,又生成了新的job2-1放入了combiner_data中,见路径:5-5.1-5.2-5.3
- 第四种场景:执行combiner_data中的job2,又生成了新的job2-1放入了closure_list中,见路径:5-5.1-5.4-5.5
链接:https://zhuanlan.zhihu.com/p/63817217
combiner
// Note that the 'write_action_begin_locked' closure is being scheduled
// on the 'finally_scheduler' of t->combiner. This means that
// 'write_action_begin_locked' is called only *after* all the other
// closures (some of which are potentially initiating more writes on the
// transport) are executed on the t->combiner.
//
// The reason for scheduling on finally_scheduler is to make sure we batch
// as many writes as possible. 'write_action_begin_locked' is the function
// that gathers all the relevant bytes (which are at various places in the
// grpc_chttp2_transport structure) and append them to 'outbuf' field in
// grpc_chttp2_transport thereby batching what would have been potentially
// multiple write operations.
//
// Also, 'write_action_begin_locked' only gathers the bytes into outbuf.
// It does not call the endpoint to write the bytes. That is done by the
// 'write_action' (which is scheduled by 'write_action_begin_locked')
t->combiner->FinallyRun(
GRPC_CLOSURE_INIT(&t->write_action_begin_locked,
write_action_begin_locked, t, nullptr),
GRPC_ERROR_NONE);
边栏推荐
- #yyds Dry Goods Inventory#[Yugong Series] August 2022 Go Teaching Course 008-Integer of Data Types
- 联盛德W801系列6-从微信小程序的角度来分析W801的蓝牙通信源码(indicate方式)
- This Thursday evening at 19:00, Lesson 5 of the sixth phase of knowledge empowerment丨OpenHarmony WiFi subsystem
- 进程间通信方式(1)无名管道(全CSDN最用心的博主)
- 英伟达 GPU 架构简史
- 软件测试面试题:在频繁的版本发布中,如何回归测试?
- 第二课第一周第4-6节 医学预后案例欣赏+作业解析
- 软件测试面试题:测试用例与测试脚本?
- 单面PCB布线阻抗的工程设计
- 【视频】报告分享|2021年保险行业数字化洞察
猜你喜欢
MSTP - Multiple Spanning Tree (Case + Configuration)
The latest domestic power supply manufacturers and pin-to-pin replacement manuals for specific models are released
MySQL基础篇【第一篇】| 数据库概述及数据准备、常用命令、查看表结构步骤
【Video】Report Sharing | 2021 Insurance Industry Digital Insights
Oops Framework模板项目新手引导
WinForm (5) control and its members
21. Aliyun oss
nvidia-smi详解
FPGA learning column (xinlinx) serial communication -
【备战“金九银十”】2022年软件测试面试题最新汇总
随机推荐
Still using Xshell?You are out, recommend a more modern terminal connection tool, easy to use!
This Thursday evening at 19:00, Lesson 5 of the sixth phase of knowledge empowerment丨OpenHarmony WiFi subsystem
OpenWrt之opkg详解
js原型和原型链及原型继承
软件测试面试题:缺陷等级应如何划分?
HCIP-R&S By Wakin自用笔记(3)OSPF之引入外部路由、Forwarding-Address、汇总、特殊区域
划分字母区间[贪心->空间换时间->数组hash优化]
如何实现FPGA的可重复性设计
88Q2110 通过C22方式访问C45 phy地址
【服务器数据恢复】raid5崩溃导致lvm信息和VXFS文件系统损坏的数据恢复案例
【开源】壁纸软件,给自己电脑设计专属特效
The concept of services
络达开发---串口日志&日志过滤
软件测试面试题:性能测试工作?
dump_stack ()
SystemVerilog: Verifying knowledge bits and pieces
Detailed explanation of the opkg of OpenWrt
从键入网址到网页显示的详细过程
QT+VTK+PCL拟合圆柱并计算起始点、中止点
第二课第一周第4-6节 医学预后案例欣赏+作业解析