yanglimingcn commented on PR #2358: URL: https://github.com/apache/brpc/pull/2358#issuecomment-1895586701
> @yanglimingcn 大佬请教个问题,我在你代码基础上修改了一下,一个server内部分service,然后每个service绑定一个bthread group tag,收到消息后根据tag进行分发。现在有一个问题,发现bthread_count监控数值不对,比如3个tag,总和是对的,但是有些group tag不对,看起来应该是task原来在group1上运行,但是退出是跑到group2上: > > ``` > # curl -s 127.0.0.1:47791/vars | grep bthread_count > bthread_count : 14 > bthread_count_0 : 118431 > bthread_count_1 : 1 > bthread_count_2 : -118418 > ``` > > 我的处理是在`void ProcessRpcRequest(InputMessageBase* msg_base)`函数中,在`svc->CallMethod`之前判断tag,然后进行分发到对应的tag: > > ``` > void ProcessRpcRequest(InputMessageBase* msg_base) { > .... > if (!FLAGS_usercode_in_pthread) { > // check bthread worker tag > LOG(WARNING) << "bthread tag: " << mp->bthread_worker_tag << ", service_name:" << svc_name << ", method_name:" << mp->method->name() << std::endl; > if (mp->bthread_worker_tag != BTHREAD_TAG_DEFAULT) { > bthread_t th; > bthread_attr_t attr = BTHREAD_ATTR_NORMAL; > attr.tag = mp->bthread_worker_tag; > > bthread::CountdownEvent event(1); > auto func = [method, &cntl, &req, &res, done, svc, &event]() { > svc->CallMethod(method, cntl.release(), > req.release(), res.release(), done); > event.signal(); > }; > std::function<void()> func_cp(func); > LOG(WARNING) << "BthreadCallMethodRun before"; > int ret = bthread_start_background(&th, &attr, BthreadCallMethodRun, &func_cp); > // int ret = 0; > // (*BthreadCallMethodRun)(&func_cp); > LOG(WARNING) << "BthreadCallMethodRun ret: " << ret; > event.wait(); > LOG(WARNING) << "BthreadCallMethodRun after wait: " << ret; > if (ret != 0) { > LOG(FATAL) << "Fail to start bthread_worker_tag"; > // return svc->CallMethod(method, cntl.release(), > // req.release(), res.release(), done); > } > return; > } else { > return svc->CallMethod(method, cntl.release(), > req.release(), res.release(), done); > } > } > } > ``` > > tag是service注册时打上的。 大佬帮忙看看是我修改的问题哪里没考虑到吗? 你这个func_cp里面执行什么内容了呢,如果执行done->Run可能会有tag切换吧,因为你这么改的话,epoll_wait这个线程只能属于tag0吧,所以它的执行上下文都是tag0的。 https://github.com/apache/brpc/pull/2476 这个PR你代码里面合入了吗? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org