Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bthread_worker_usage这个统计值为何有时候会超时bthread #2640

Open
zc08291161 opened this issue May 10, 2024 · 2 comments
Open

bthread_worker_usage这个统计值为何有时候会超时bthread #2640

zc08291161 opened this issue May 10, 2024 · 2 comments
Labels
bug the code does not work as expected

Comments

@zc08291161
Copy link

Describe the bug (描述bug)
在brpc的统计页面上,很容易就发现bthread_worker_usage的值
超过bthread_worker_count,理论上根据代码,bthread_worker_usage
的值不会超过TaskGroup的个数,因为代码
double TaskControl::get_cumulated_worker_time() {
int64_t cputime_ns = 0;
BAIDU_SCOPED_LOCK(_modify_group_mutex);
const size_t ngroup = _ngroup.load(butil::memory_order_relaxed);
for (size_t i = 0; i < ngroup; ++i) {
if (_groups[i]) {
cputime_ns += _groups[i]->_cumulated_cputime_ns;
}
}
return cputime_ns / 1000000000.0;
}

这个函数是一秒钟统计一次,如果定时器完全准的话,一定不会超过ngroup的个数
因此这个值是否强依赖定时器,因而不一定完全准确,是否应该将
cputime_ns / 1000000000.0;
更改为 cputime_ns / (real_elapse_time);其中real_elapse_time是这个函数两次
调用的时间差。

To Reproduce (复现方法)

Expected behavior (期望行为)

Versions (各种版本)
OS:
Compiler:
brpc: 1.0.0
protobuf:

Additional context/screenshots (更多上下文/截图)
image

@yanglimingcn
Copy link
Contributor

yanglimingcn commented May 11, 2024

听上去这么修改更合理些,你能否简单改一下验证一下呢?

@zc08291161
Copy link
Author

ok,I will try

@yanglimingcn yanglimingcn added the bug the code does not work as expected label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug the code does not work as expected
Projects
None yet
Development

No branches or pull requests

2 participants