当前位置:网站首页>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);
边栏推荐
- Linux install redis database
- 【websocket】
- 2022年PMP报考指南
- Successfully resolved raise TypeError('Unexpected feature_names type')TypeError: Unexpected feature_names type
- 如何开展性能测试,你知道吗?
- 软件测试面试题:什么是Negative测试?
- MSTP - Multiple Spanning Tree (Case + Configuration)
- Ambari Migrates Spark2 to Other Machines (Graphic and Text Tutorial)
- MySQL advanced query
- 划分字母区间[贪心->空间换时间->数组hash优化]
猜你喜欢
随机推荐
连流量染色都没有,你说要搞微服务?
Qt 中的隐式共享
软件测试面试题:什么是α测试,β测试?
zerorpc:async=True can be written as **{“async“: True}
Lianshengde W801 series 6-Analyze the Bluetooth communication source code of W801 from the perspective of WeChat applet (indicate method)
深度解析:什么是太爱速M抢单模式?
测试3年,开口就要25k?面试完最多给15k...
QT+VTK+PCL拟合圆柱并计算起始点、中止点
loop word
[The method of calling the child page from the parent page of the iframe] Stepping on the pit: It is the key to use `[x]` when getting elements. You cannot use `.eq(x)`, otherwise it will not be obtai
Section 4-6 of the first week of the second lesson: Appreciation of medical prognosis cases + homework analysis
如何防止离职员工把企业文件拷贝带走?法律+技术,4步走
备战“金九银十”,软件测试功能 / 数据库 /linux/ 接口 / 自动化 / 测试开发面试真题解析
【iframe父页面调用子页面的方法】踩坑:获取元素的时候需要用 `[x]`是关键,不能用`.eq(x)`否则获取不到。
The concept of services
【微波工程学习记录1】功率分配器和定向耦合器
C# WebBrower1控件可编辑模式保存时会提示“该文档已被修改,是否保存修改结果”
Shengxin experiment record (part2)--tf.reduce_sum() usage introduction
Alibaba 最新神作!耗时 182 天肝出来 1015 页分布式全栈手册太香了
Tomca启动闪退问题如何解决









