chenBright commented on code in PR #2358:
URL: https://github.com/apache/brpc/pull/2358#discussion_r1371474894


##########
src/bthread/task_control.cpp:
##########
@@ -56,28 +58,44 @@ void run_worker_startfn() {
     }
 }
 
+void run_tagged_worker_startfn(bthread_tag_t tag) {
+    if (g_tagged_worker_startfn) {
+        g_tagged_worker_startfn(tag);
+    }
+}
+
+struct WorkerThreadArgs {
+    WorkerThreadArgs(TaskControl* _c, bthread_tag_t _t) : c(_c), tag(_t) {}
+    TaskControl* c;
+    bthread_tag_t tag;
+};
+
 void* TaskControl::worker_thread(void* arg) {
-    run_worker_startfn();    
+    run_worker_startfn();
 #ifdef BAIDU_INTERNAL
     logging::ComlogInitializer comlog_initializer;
 #endif
-    
-    TaskControl* c = static_cast<TaskControl*>(arg);
-    TaskGroup* g = c->create_group();
+
+    auto dummy = static_cast<WorkerThreadArgs*>(arg);

Review Comment:
   用std::unique_ptr<WorkerThreadArgs>?



##########
docs/cn/bthread_tagged_task_group.md:
##########
@@ -0,0 +1,29 @@
+
+# Bthread tagged task group
+
+在很多应用开发过程中都会有线程资源隔离的需求,比如服务分为控制层和数据层,数据层的请求压力大,不需要控制层受到影响;再比如,服务有多个磁盘,希望磁盘之间没有什么影响资源上的影响等。bthread的任务组打标签就是实现bthread的worker线程池按照tag分组,让不同分组之间达到没有互相影响的目的。服务端程序是按照server级别做tag分组的,用户需要将service安排到不同server,不同server将使用不同端口。

Review Comment:
   希望磁盘之间没有什么影响资源上的影响 -> 希望磁盘之间没有什么资源上的影响?



##########
src/bthread/task_control.cpp:
##########
@@ -168,7 +211,8 @@ int TaskControl::init(int concurrency) {
     
     _workers.resize(_concurrency);   
     for (int i = 0; i < _concurrency; ++i) {
-        const int rc = pthread_create(&_workers[i], NULL, worker_thread, this);
+        auto arg = new WorkerThreadArgs(this, i % FLAGS_task_group_ntags);

Review Comment:
   pthread_create != 0时,arg会泄露吧?



##########
docs/cn/bthread_tagged_task_group.md:
##########
@@ -0,0 +1,29 @@
+
+# Bthread tagged task group
+
+在很多应用开发过程中都会有线程资源隔离的需求,比如服务分为控制层和数据层,数据层的请求压力大,不需要控制层受到影响;再比如,服务有多个磁盘,希望磁盘之间没有什么影响资源上的影响等。bthread的任务组打标签就是实现bthread的worker线程池按照tag分组,让不同分组之间达到没有互相影响的目的。服务端程序是按照server级别做tag分组的,用户需要将service安排到不同server,不同server将使用不同端口。

Review Comment:
   希望磁盘之间没有什么影响资源上的影响 -> 希望磁盘之间没有什么资源上的影响?



##########
src/bthread/task_control.cpp:
##########
@@ -56,28 +58,44 @@ void run_worker_startfn() {
     }
 }
 
+void run_tagged_worker_startfn(bthread_tag_t tag) {
+    if (g_tagged_worker_startfn) {
+        g_tagged_worker_startfn(tag);
+    }
+}
+
+struct WorkerThreadArgs {
+    WorkerThreadArgs(TaskControl* _c, bthread_tag_t _t) : c(_c), tag(_t) {}
+    TaskControl* c;
+    bthread_tag_t tag;
+};
+
 void* TaskControl::worker_thread(void* arg) {
-    run_worker_startfn();    
+    run_worker_startfn();
 #ifdef BAIDU_INTERNAL
     logging::ComlogInitializer comlog_initializer;
 #endif
-    
-    TaskControl* c = static_cast<TaskControl*>(arg);
-    TaskGroup* g = c->create_group();
+
+    auto dummy = static_cast<WorkerThreadArgs*>(arg);

Review Comment:
   用std::unique_ptr<WorkerThreadArgs>?



##########
src/bthread/task_control.cpp:
##########
@@ -168,7 +211,8 @@ int TaskControl::init(int concurrency) {
     
     _workers.resize(_concurrency);   
     for (int i = 0; i < _concurrency; ++i) {
-        const int rc = pthread_create(&_workers[i], NULL, worker_thread, this);
+        auto arg = new WorkerThreadArgs(this, i % FLAGS_task_group_ntags);

Review Comment:
   pthread_create != 0时,arg会泄露吧?



-- 
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: dev-unsubscr...@brpc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to