欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Unary模式下客户端创建 default-executor 和 resolver-executor 线程和从启动到执行grpc_connector_connect的主要流程

程序员文章站 2022-04-15 09:08:00
(原创)C/C++语言, 平台是debian10, grpc版本:grpc c++/1.25.0 dev grpc c/8.0.0, 使用的例子是自带的例子GreeterClient 创建 default executor 和 resolver executor 线程的主要流程,创建channel时 ......

(原创)c/c/1.25.0-dev grpc-c/8.0.0, 使用的例子是自带的例子greeterclient

创建 default-executor 和 resolver-executor 线程的主要流程,创建channel时会创建这2个线程

graph td; 000(grpc::insecurechannelcredentials #credentials.h:91 调用insecurechannelcredentials)-->001(grpc_impl::insecurechannelcredentials #insecure_credentials.cc:59 创建一个共享的insecurechannelcredentialsimpl对象) 001-->002(grpc_impl::insecurechannelcredentialsimpl::insecurechannelcredentialsimpl #insecure_credentials.cc:30 调用父类channelcredentials构造函数) 002-->003(grpc_impl::channelcredentials::channelcredentials #credentials_cc.cc:25 调用父类grpclibrarycodegen构造函数) 003-->004(grpc::grpclibrarycodegen::grpclibrarycodegen #grpc_library.h:45 调用grpclibraryinterface的init) 004-->005(grpc::internal::grpclibrary::init #grpc_library.h:34 调用grpc_init) 005-->006(grpc_init #init.cc:146 调用grpc_iomgr_init) 006-->007(grpc_iomgr_init #iomgr.cc:60 调用grpc_core::executor::initall) 007-->008(创建 default-executor 和 resolver-executor 线程) 008-->009(grpc_iomgr_start #iomgr.cc:69 调用grpc_timer_manager_init) 009-->010(grpc_timer_manager_init #timer_manager.cc:311 调用start_threads) 010-->011(start_threads #timer_manager.cc:293 调用start_timer_thread_and_unlock) 011-->012(start_timer_thread_and_unlock #timer_manager.cc:91 启动grpc_global_timer线程)

grpc unary模式下客户端启动到执行grpc_connector_connect的主要流程

graph td; 000(grpc::internal::blockingunarycall #client_unary_call.h:43)-->001(grpc::internal::blockingunarycallimpl::blockingunarycallimpl #client_unary_call.h:71 创建completionqueue, call, callopset对象, 设置callopset对象参数, 调用performops) 001-->002(grpc::internal::call::performops #call.h:69 调用performopsoncall) 002-->003(grpc_impl::channel::performopsoncall #channel_cc.cc:164 调用fillops) 003-->004(grpc::internal::callopset::fillops #call_op_set.h:874 调用continuefillopsafterinterception) 004-->005(grpc::internal::callopset::continuefillopsafterinterception #call_op_set.h:943 调用6个op的addop并调用grpc_call_start_batch) 005-->006(grpc::corecodegen::grpc_call_start_batch #core_codegen.cc:113 调用grpc_call_start_batch) 006-->007(grpc_call_start_batch #call.cc:1974 调用call_start_batch) 007-->008(call_start_batch #call.cc:1929 根据6个ops的op->op, 设置stream_op, ops, call的参数, 最后调用execute_batch) 008-->009(execute_batch #call.cc:639 调用start_batch_closure的callback函数 execute_batch_in_call_combiner) 009-->010(execute_batch_in_call_combiner #call.cc:628 调用 elem->filter->start_transport_stream_op_batch) 010-->011(grpc_call_next_op #channel_stack.cc:227 调用 next_elem->filter->start_transport_stream_op_batch) 011-->012(grpc_core::calldata::starttransportstreamopbatch #client_channel.cc:2140 把batch加入pending:pendingbatchesadd并调用picksubchannel) 012-->013(grpc_core::calldata::picksubchannel #client_channel.cc:3853 调用picksubchannellocked返回false) 013-->014(grpc_core::calldata::picksubchannellocked #client_channel.cc:3870 picker_是nullptr, 调用checkconnectivitystate, 参数设定为尝试连接) 014-->015(grpc_core::channeldata::checkconnectivitystate #client_channel.cc:1956 创建closure并调用它的callback函数 trytoconnectlocked) 015-->016(closure_impl::closure_wrapper #closure.h:156 创建closure是callback函数是closure_impl::closure_wrapper, 真正的callback是 trytoconnectlocked) 016-->017(grpc_core::channeldata::trytoconnectlocked #client_channel.cc:1946 调用createresolvingloadbalancingpolicylocked) 017-->018(grpc_core::channeldata::createresolvingloadbalancingpolicylocked #client_channel.cc:1596 调用resolvingloadbalancingpolicy构造函数) 018-->019(grpc_core::resolvingloadbalancingpolicy #resolving_lb_policy.cc:199 创建createresolver, updatestate并调用startlocked开始解析) 019-->020(grpc_core::aresdnsresolver::startlocked #dns_resolver_ares.cc:177 调用maybestartresolvinglocked) 020-->021(grpc_core::aresdnsresolver::maybestartresolvinglocked #dns_resolver_ares.cc:409 调用startresolvinglocked) 021-->022(grpc_core::aresdnsresolver::startresolvinglocked #dns_resolver_ares.cc:420 调用grpc_dns_lookup_ares_locked) 022-->023(grpc_dns_lookup_ares_locked_impl #grpc_ares_wrapper.cc:625 调用grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked) 023-->024(grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked #grpc_ares_wrapper.cc:446 使用c-ares通过dns查找ip地址, 最后调用grpc_ares_request_unref_locked) 024-->025(grpc_ares_request_unref_locked #grpc_ares_wrapper.cc:135 如果延迟的查询为0, 调用grpc_ares_ev_driver_on_queries_complete_locked) 025-->026(grpc_ares_ev_driver_on_queries_complete_locked #grpc_ares_ev_driver.cc:191 停止查询,调用grpc_timer_cancel, 参数是query_timeout) 026-->027(grpc_timer_cancel #timer.cc:35 调用grpc_timer_impl->cancel) 027-->028(timer_cancel #timer_generic.cc:474 调用 timer->closure对应的callback函数) 028-->029(on_ares_backup_poll_alarm_locked #grpc_ares_ev_driver.cc:288 调用grpc_ares_ev_driver_unref) 029-->030(grpc_ares_ev_driver_unref #grpc_ares_ev_driver.cc:112 释放资源并调用grpc_ares_complete_request_locked) 030-->031(grpc_ares_complete_request_locked #grpc_ares_wrapper.cc:151 调用on_done对应的callback函数) 031-->032(grpc_core::aresdnsresolver::onresolvedlocked #dns_resolver_ares.cc:347 解析完成, 调用returnresult) 032-->033(grpc_core::resolvingloadbalancingpolicy::resolverresulthandler::returnresult #resolving_lb_policy.cc:87 调用onresolverresultchangedlocked) 033-->034(onresolverresultchangedlocked #resolving_lb_policy.cc:479 获得lb_policy_name,默认pick_first, 如果lb_policy_name不为空, 则创建或者更新lb policy, 调用的是createorupdatelbpolicylocked) 034-->035(createorupdatelbpolicylocked #resolving_lb_policy.cc:364 创建或者更新lb_policy, 调用updatelocked) 035-->036(pickfirst::updatelocked #pick_first.cc:280 调用attempttoconnectusinglatestupdateargslocked) 036-->037(pickfirst::attempttoconnectusinglatestupdateargslocked #pick_first.cc:236 用latest_update_args_创建 subchannel列表, 如果列表中的subchannel有状态是grpc_channel_ready, 则选中此subchannel, 否则选中第0个subchannel) 037-->038(attempttoconnect #client_channel.cc:921 调用subchannel_->attempttoconnect) 038-->039(subchannel::attempttoconnect #subchannel.cc:823 调用maybestartconnectinglocked) 039-->040(subchannel::maybestartconnectinglocked #subchannel.cc:930 调用continueconnectinglocked) 040-->041(subchannel::continueconnectinglocked #subchannel.cc:983 设置grpc_connect_in_args参数并调用grpc_connector_connect, 通过connector->vtable->connect最后调用chttp2_connector_connect)