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

epoll bthread deal first #2819

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix scale workers
jiazheng.jia committed Mar 12, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 95e5b8453bd5fefce568628163c4d932e99ce9a4
12 changes: 12 additions & 0 deletions src/bthread/task_control.cpp
Original file line number Diff line number Diff line change
@@ -482,6 +482,18 @@ void TaskControl::signal_task(int num_task, bthread_tag_t tag) {
if (num_task > 2) {
num_task = 2;
}
if (ParkingLot::_waiting_count.load(std::memory_order_acquire) == 0) {
if (FLAGS_bthread_min_concurrency > 0 &&
_concurrency.load(butil::memory_order_relaxed) < FLAGS_bthread_concurrency) {
// TODO: Reduce this lock
BAIDU_SCOPED_LOCK(g_task_control_mutex);
if (_concurrency.load(butil::memory_order_acquire) < FLAGS_bthread_concurrency) {
add_workers(1, tag);
}
} else {
return;
}
}
auto& pl = tag_pl(tag);
int start_index = butil::fmix64(pthread_numeric_id()) % PARKING_LOT_NUM;
num_task -= pl[start_index].signal(1);
16 changes: 4 additions & 12 deletions src/bthread/task_group.cpp
Original file line number Diff line number Diff line change
@@ -726,9 +726,7 @@ void TaskGroup::ready_to_run(TaskMeta* meta, bool nosignal) {
const int additional_signal = _num_nosignal;
_num_nosignal = 0;
_nsignaled += 1 + additional_signal;
if (ParkingLot::_waiting_count.load(std::memory_order_acquire) > 0) {
_control->signal_task(1 + additional_signal, _tag);
}
_control->signal_task(1 + additional_signal, _tag);
}
}

@@ -737,9 +735,7 @@ void TaskGroup::flush_nosignal_tasks() {
if (val) {
_num_nosignal = 0;
_nsignaled += val;
if (ParkingLot::_waiting_count.load(std::memory_order_acquire) > 0) {
_control->signal_task(val, _tag);
}
_control->signal_task(val, _tag);
}
}

@@ -763,9 +759,7 @@ void TaskGroup::ready_to_run_remote(TaskMeta* meta, bool nosignal) {
_remote_num_nosignal = 0;
_remote_nsignaled += 1 + additional_signal;
_remote_rq._mutex.unlock();
if (ParkingLot::_waiting_count.load(std::memory_order_acquire) > 0) {
_control->signal_task(1 + additional_signal, _tag);
}
_control->signal_task(1 + additional_signal, _tag);
}
}

@@ -778,9 +772,7 @@ void TaskGroup::flush_nosignal_tasks_remote_locked(butil::Mutex& locked_mutex) {
_remote_num_nosignal = 0;
_remote_nsignaled += val;
locked_mutex.unlock();
if (ParkingLot::_waiting_count.load(std::memory_order_acquire) > 0) {
_control->signal_task(val, _tag);
}
_control->signal_task(val, _tag);
}

void TaskGroup::ready_to_run_general(TaskMeta* meta, bool nosignal) {