@@ -51,6 +51,8 @@ DEFINE_string(cpu_set, "",
5151 " Set of CPUs to which cores are bound. "
5252 " for example, 0-3,5,7; default: disable" );
5353
54+ namespace brpc { DECLARE_int32(event_dispatcher_num); }
55+
5456namespace bthread {
5557
5658DEFINE_bool (parking_lot_no_signal_when_no_waiter, false ,
@@ -205,7 +207,8 @@ TaskControl::TaskControl()
205207 , _status(print_rq_sizes_in_the_tc, this )
206208 , _nbthreads(" bthread_count" )
207209 , _enable_priority_queue(FLAGS_enable_bthread_priority_queue)
208- , _priority_queues(FLAGS_task_group_ntags)
210+ , _pq_num_of_each_tag(brpc::FLAGS_event_dispatcher_num)
211+ , _priority_queues(FLAGS_task_group_ntags * brpc::FLAGS_event_dispatcher_num)
209212 , _pl_num_of_each_tag(FLAGS_bthread_parking_lot_of_each_tag)
210213 , _tagged_pl(FLAGS_task_group_ntags)
211214{}
@@ -238,9 +241,14 @@ int TaskControl::init(int concurrency) {
238241 _tagged_worker_usage_second.push_back (new bvar::PerSecond<bvar::PassiveStatus<double >>(
239242 " bthread_worker_usage" , tag_str, _tagged_cumulated_worker_time[i], 1 ));
240243 _tagged_nbthreads.push_back (new bvar::Adder<int64_t >(" bthread_count" , tag_str));
241- if (_priority_queues[i].init (BTHREAD_MAX_CONCURRENCY) != 0 ) {
242- LOG (ERROR) << " Fail to init _priority_q" ;
243- return -1 ;
244+ if (_enable_priority_queue) {
245+ for (int j = 0 ; j < _pq_num_of_each_tag; ++j) {
246+ if (priority_queue (i, j).init (4096 ) != 0 ) {
247+ LOG (ERROR) << " Fail to init priority queue for tag=" << i
248+ << " ed=" << j;
249+ return -1 ;
250+ }
251+ }
244252 }
245253 }
246254
@@ -445,7 +453,7 @@ TaskControl::~TaskControl() {
445453 _switch_per_second.hide ();
446454 _signal_per_second.hide ();
447455 _status.hide ();
448-
456+
449457 stop_and_join ();
450458}
451459
@@ -528,8 +536,12 @@ int TaskControl::_destroy_group(TaskGroup* g) {
528536bool TaskControl::steal_task (bthread_t * tid, size_t * seed, size_t offset) {
529537 auto tag = tls_task_group->tag ();
530538
531- if (_priority_queues[tag].steal (tid)) {
532- return true ;
539+ if (_enable_priority_queue) {
540+ for (int i = 0 ; i < _pq_num_of_each_tag; ++i) {
541+ if (priority_queue (tag, i).steal (tid)) {
542+ return true ;
543+ }
544+ }
533545 }
534546
535547 // 1: Acquiring fence is paired with releasing fence in _add_group to
@@ -689,4 +701,5 @@ std::vector<bthread_t> TaskControl::get_living_bthreads() {
689701 return living_bthread_ids;
690702}
691703
704+
692705} // namespace bthread
0 commit comments