lhsoft commented on issue #3030:
URL: https://github.com/apache/brpc/issues/3030#issuecomment-3096493727
@zhengJade @chenBright 确实有可能提交多个priority task的,原因如下:
在start_foreground函数里会根据当前bthread的属性来决定是否高优先级,这会导致BTHREAD_GLOBAL_PRIORITY有一定的传递性
```
auto& cur_attr = g->_cur_meta->attr;
if (cur_attr.flags & BTHREAD_GLOBAL_PRIORITY) {
fn = priority_to_run;
} else if (g->current_task()->about_to_quit) {
fn = ready_to_run_in_worker_ignoresignal;
} else {
fn = ready_to_run_in_worker;
}
ReadyToRunArgs args = {
g->tag(),
g->_cur_meta,
(bool)(using_attr.flags & BTHREAD_NOSIGNAL)
};
g->set_remained(fn, &args);
TaskGroup::sched_to(pg, m->tid);
```
我们代码里用了braft,Socket::ProcessEvent函数最终在braft里调用bthread_start_urgent,导致新的的priority
task被提交
```
LogManager::WaitId LogManager::notify_on_new_log(
int64_t expected_last_log_index, WaitMeta* wm) {
std::unique_lock<raft_mutex_t> lck(_mutex);
if (expected_last_log_index != _last_log_index || _stopped) {
wm->error_code = _stopped ? ESTOP : 0;
lck.unlock();
bthread_t tid;
if (bthread_start_urgent(&tid, NULL, run_on_new_log, wm) != 0) {
PLOG(ERROR) << "Fail to start bthread";
run_on_new_log(wm);
}
return 0; // Not pushed into _wait_map
}
if (_next_wait_id == 0) { // skip 0
++_next_wait_id;
}
const int wait_id = _next_wait_id++;
_wait_map[wait_id] = wm;
return wait_id;
}
```
我觉得很难避免业务层在ProcessEvent函数里调用bthread_start_urgent,只要调用了,就会有更多的priority task被提交
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]