wwbmmm commented on issue #2833: URL: https://github.com/apache/brpc/issues/2833#issuecomment-2547695006
> 之前在#1822 讨论过这个需求,看起来自定义callback不太满足这个需求: > > 1. 用户能知道第一次调度,但是不知道最后一次调度。 > 2. 用户需要熟悉bthread内部调度原理才能用好callback。 > > 自定义callback结合#2851 中的bthread状态,应该会好用些。 > > [#1822 (comment)](https://github.com/apache/brpc/issues/1822#issuecomment-1202082072) > > > 考虑扩展一下bthread::TaskStatistics,加个cpu消耗的统计项,并且在bthread切换时更新该值。 > > 我认为这个方案更合适。clock_gettime是系统调用,会影响bthread调度性能,所以在此方案的基础上补充两点: > > 1. 在bthread_attrflags_t加个开关,默认不统计纯cpu消耗。用户有需要可以通过bthread_attrflags_t启用该功能。 > 2. server bthread是由框架创建的,用户没法干预。通过ServerOptions/gflag来启用该功能。 > > @wwbmmm 有什么建议吗? 用户可能是想针对每一个请求获取具体的cpu时间,那么得给用户提供一个获取的接口,用户在执行完Server callback的最后调用这个接口,这个时候bthread实际上还没有结束。 不过,通过这种方式来统计请求消耗的cpu并不准确,因为请求相关的cpu计算并不仅仅发生在请求所在的那个bthread,还可能出现在其它后台线程、epoll线程、异步callback线程之中,这个取决于具体的业务逻辑。统计bthread的cpu时间只能提供一个参考。 -- 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