brpc icon indicating copy to clipboard operation
brpc copied to clipboard

Bugfix: bthread_worker_usage would be greater than bthread_worker_count

Open chenBright opened this issue 6 months ago • 1 comments

What problem does this PR solve?

Issue Number: resolve #1231 , resolve #2640 , resolve #2972

Problem Summary:

What is changed and the side effects?

Changed:

bthread_worker_usage should consist of _cumulated_cputime_ns and the CPU time of the task currently run by the worker.

Side effects:

  • Performance effects:

  • Breaking backward compatibility:


Check List:

chenBright avatar Jun 28 '25 02:06 chenBright

@wwbmmm @yanglimingcn Please take a look.

chenBright avatar Jun 30 '25 10:06 chenBright

@wwbmmm @yanglimingcn Friendly ping!

chenBright avatar Jul 14 '25 09:07 chenBright

void* test(void*) {
    while (!brpc::IsAskedToQuit()) {
        sleep(2);
        bthread_yield();
    }
}

for (int i = 0; i < 3; ++i) {
    bthread_t tid;
    bthread_start_background(&tid, NULL, test, NULL);
}
image

Start 3 bthreads and loop sleep for 2s. The value of bthread_worker_usage is correct, and the extra 1 comes from the epoll bthread.

chenBright avatar Jul 18 '25 14:07 chenBright

LGTM

wwbmmm avatar Jul 21 '25 02:07 wwbmmm