Re: [PR] bthread task group add tag (brpc)

2024-03-07 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1983043315

   > > 技术上是能实现的,但是做起来也有些复杂,同步的代码确实更好一些,否则execq里面就得调用callback了吧?
   > 
   > 确实还是有同步代码的需求。有些场景如果用callback,就会使callback里的逻辑很重,虽然技术上是可以的,但是代码看起来就很难看了。
   
   https://github.com/apache/brpc/pull/2551


-- 
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



Re: [PR] bthread task group add tag (brpc)

2024-02-29 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1972404251

   > @yanglimingcn 我有几个疑问。比如我有一个server,tag是tag1。
   > 
   > 1. 处理service请求的bthread是tag1?
   > 2. service的所有io bthread是tag1?
   > 3. 请求下游服务时创建的io bthread也是tag1吗?
   
   是的


-- 
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



Re: [PR] bthread task group add tag (brpc)

2024-02-29 Thread via GitHub


yyweii commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1972382498

   @yanglimingcn 我有几个疑问。比如我有一个server,tag是tag1。
   1. 处理service请求的bthread是tag1?
   2. service的所有io bthread是tag1?
   3.  请求下游服务时创建的io bthread也是tag1吗?


-- 
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



Re: [PR] bthread task group add tag (brpc)

2024-02-28 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1968576982

   https://github.com/apache/brpc/pull/2551


-- 
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



Re: [PR] bthread task group add tag (brpc)

2024-02-20 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1956004161

   > > 技术上是能实现的,但是做起来也有些复杂,同步的代码确实更好一些,否则execq里面就得调用callback了吧?
   > 
   > 确实还是有同步代码的需求。有些场景如果用callback,就会使callback里的逻辑很重,虽然技术上是可以的,但是代码看起来就很难看了。
   
   ok,这块后续可以支持。


-- 
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



Re: [PR] bthread task group add tag (brpc)

2024-02-20 Thread via GitHub


ketor commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1954409081

   > 技术上是能实现的,但是做起来也有些复杂,同步的代码确实更好一些,否则execq里面就得调用callback了吧?
   
   确实还是有同步代码的需求。有些场景如果用callback,就会使callback里的逻辑很重,虽然技术上是可以的,但是代码看起来就很难看了。
   


-- 
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



Re: [PR] bthread task group add tag (brpc)

2024-02-16 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1949464923

   > 
感觉ExecutionQueue这个用起来还是有点问题,比如in_place执行的场景,task是在当前bthread执行的,就有可与初始化execq时指定的attr的tag不一致,如果task里面用到了bthread_mutex,就可能存在跨线程池唤醒的问题。
   > 
   > 在我们的项目里面还有一个场景,感觉也有可能有问题,具体如下: 
对外服务是一个端口,braft使用的是另一个端口,期望对外服务和braft如果分别使用不同的tag调度。 
但是在业务流程中,存在对外服务的service函数中,要执行提交到braft状态机,然后阻塞到bthread_cond上,然后等待raft 
apply之后的在closure中对bthread_cond进行signal。这个操作就相当于是用bthread_cond实现了异步转同步的调用。
   > 
   > 
由于对外服务和braft使用了不同的tag,braft的on_apply调用是在execq中执行,按这个PR前面的讨论,会指定attr的tag为braft使用的tag,那么on_apply执行所使用的bthread就会是braft的tag,在on_apply中调用bthread_cond_signal,就会发生跨线程池使用bthread同步原语的问题了。
   > 
   > 如果是这种场景,根据前面的讨论,应该是不适合让对外服务和braft服务使用不同的tag来调度了。不知道这样的理解是否正确?
   
   划分线程池的目的是为了隔离,感觉你对外服务和braft已经在上层通过execq做了隔离,是不是就没必要再使用这个功能了呢?
   如果要使用可能要做一些改造,attribute可以按照你的情况制定,但是bthread原语确实不能跨线程池。


-- 
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



Re: [PR] bthread task group add tag (brpc)

2024-02-16 Thread via GitHub


ketor commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1948762864

   
感觉ExecutionQueue这个用起来还是有点问题,比如in_place执行的场景,task是在当前bthread执行的,就有可与初始化execq时指定的attr的tag不一致,如果task里面用到了bthread_mutex,就可能存在跨线程池唤醒的问题。
   在我们的项目里面还有一个场景,感觉也有可能有问题,具体如下:
   对外服务是一个端口,braft使用的是另一个端口,期望对外服务和braft如果分别使用不同的tag调度。
   但是在业务流程中,存在对外服务的service函数中,要执行提交到braft状态机,然后阻塞到bthread_cond上,然后等待raft 
apply之后的在closure中对bthread_cond进行signal。这个操作就相当于是用bthread_cond实现了异步转同步的调用。
   
   
由于对外服务和braft使用了不同的tag,braft的on_apply调用是在execq中执行,按这个PR前面的讨论,会指定attr的tag为braft使用的tag,那么on_apply执行所使用的bthread就会是braft的tag,在on_apply中调用bthread_cond_signal,就会发生跨线程池使用bthread同步原语的问题了。
   
   如果是这种场景,根据前面的讨论,应该是不适合让对外服务和braft服务使用不同的tag来调度了。不知道这样的理解是否正确?
   
   


-- 
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



Re: [PR] bthread task group add tag (brpc)

2024-02-14 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1945183040

   > > > 
请问这个PR的改动,如果使用了bthread::ExecutionQueue,ExecutionQueue里面的任务如何区分按照哪个tag去调度的呢? 
还是整个ExecutionQueue对应于一个tag呢?
   > > 
   > > 
   > > 最好还是一个tag启动一个execq比较合适
   > > 谢谢!
   > 
   > 启动ExecutionQueue的时候,在attr里面指定上tag,就是整个ExecutionQueue都会在这个tag所在的线程池里执行了是么? 
另外现在的实现,如果使用了bthread_mutex/cond这些同步原语,跨线程池的时候,这些同步原语的工作是否会有问题呢? 
看了2个PR里的discussion,似乎没有给出明确的答案,所以请教一下。
   
   1、execq会启动协程,这个协程设置好attribute的tag就可以了
   2、跨线程池不要使用bthread原语会有问题,可以使用pthread原语。


-- 
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



Re: [PR] bthread task group add tag (brpc)

2024-02-14 Thread via GitHub


ketor commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1943846669

   > > 
请问这个PR的改动,如果使用了bthread::ExecutionQueue,ExecutionQueue里面的任务如何区分按照哪个tag去调度的呢? 
还是整个ExecutionQueue对应于一个tag呢?
   > 
   > 最好还是一个tag启动一个execq比较合适
   谢谢!
   
   启动ExecutionQueue的时候,在attr里面指定上tag,就是整个ExecutionQueue都会在这个tag所在的线程池里执行了是么?
   另外现在的实现,如果使用了bthread_mutex/cond这些同步原语,跨线程池的时候,这些同步原语的工作是否会有问题呢? 
看了2个PR里的discussion,似乎没有给出明确的答案,所以请教一下。


-- 
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



Re: [PR] bthread task group add tag (brpc)

2024-02-13 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1942746416

   > 
请问这个PR的改动,如果使用了bthread::ExecutionQueue,ExecutionQueue里面的任务如何区分按照哪个tag去调度的呢? 
还是整个ExecutionQueue对应于一个tag呢?
   
   最好还是一个tag启动一个execq比较合适


-- 
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



Re: [PR] bthread task group add tag (brpc)

2024-02-13 Thread via GitHub


ketor commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1942070918

   请问这个PR的改动,如果使用了bthread::ExecutionQueue,ExecutionQueue里面的任务如何区分按照哪个tag去调度的呢? 
还是整个ExecutionQueue对应于一个tag呢?


-- 
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



Re: [PR] bthread task group add tag (brpc)

2024-01-19 Thread via GitHub


vinllen commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1900046696

   @yanglimingcn 
我知道问题所在了,的确是done的调用问题,我们用了另外一个braft的库,里面调用done是塞入到bthread::ExecutionQueue里面,这个你是不是也得修改?


-- 
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



Re: [PR] bthread task group add tag (brpc)

2024-01-18 Thread via GitHub


vinllen commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1897980232

   done我感觉应该没问题的,是跑在对应tag的bthread里面,这个func_cp就是调用服务端的代码了。我合一下 #2476 这个PR再试试


-- 
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



Re: [PR] bthread task group add tag (brpc)

2024-01-17 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1895586701

   > @yanglimingcn 
大佬请教个问题,我在你代码基础上修改了一下,一个server内部分service,然后每个service绑定一个bthread group 
tag,收到消息后根据tag进行分发。现在有一个问题,发现bthread_count监控数值不对,比如3个tag,总和是对的,但是有些group 
tag不对,看起来应该是task原来在group1上运行,但是退出是跑到group2上:
   > 
   > ```
   > # curl -s 127.0.0.1:47791/vars | grep bthread_count
   > bthread_count : 14
   > bthread_count_0 : 118431
   > bthread_count_1 : 1
   > bthread_count_2 : -118418
   > ```
   > 
   > 我的处理是在`void ProcessRpcRequest(InputMessageBase* 
msg_base)`函数中,在`svc->CallMethod`之前判断tag,然后进行分发到对应的tag:
   > 
   > ```
   > void ProcessRpcRequest(InputMessageBase* msg_base) {
   > 
   > if (!FLAGS_usercode_in_pthread) {
   > // check bthread worker tag
   > LOG(WARNING) << "bthread tag: " << mp->bthread_worker_tag << 
", service_name:" << svc_name << ", method_name:" << mp->method->name() << 
std::endl;
   > if (mp->bthread_worker_tag != BTHREAD_TAG_DEFAULT) {
   > bthread_t th;
   > bthread_attr_t attr = BTHREAD_ATTR_NORMAL;
   > attr.tag = mp->bthread_worker_tag;
   > 
   > bthread::CountdownEvent event(1);
   > auto func = [method, , , , done, svc, 
]() {
   > svc->CallMethod(method, cntl.release(),
   > req.release(), res.release(), done);
   > event.signal();
   > };
   > std::function func_cp(func);
   > LOG(WARNING) << "BthreadCallMethodRun before";
   > int ret = bthread_start_background(, , 
BthreadCallMethodRun, _cp);
   > // int ret = 0;
   > // (*BthreadCallMethodRun)(_cp);
   > LOG(WARNING) << "BthreadCallMethodRun ret: " << ret;
   > event.wait();
   > LOG(WARNING) << "BthreadCallMethodRun after wait: " << ret;
   > if (ret != 0) {
   > LOG(FATAL) << "Fail to start bthread_worker_tag";
   > // return svc->CallMethod(method, cntl.release(),
   > //req.release(), 
res.release(), done);
   > }
   > return;
   > } else {
   > return svc->CallMethod(method, cntl.release(),
   >req.release(), res.release(), done);
   > }
   > }
   > }
   > ```
   > 
   > tag是service注册时打上的。 大佬帮忙看看是我修改的问题哪里没考虑到吗?
   
   
你这个func_cp里面执行什么内容了呢,如果执行done->Run可能会有tag切换吧,因为你这么改的话,epoll_wait这个线程只能属于tag0吧,所以它的执行上下文都是tag0的。
   https://github.com/apache/brpc/pull/2476 这个PR你代码里面合入了吗?


-- 
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



Re: [PR] bthread task group add tag (brpc)

2024-01-16 Thread via GitHub


vinllen commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1895121010

   @yanglimingcn 
大佬请教个问题,我在你代码基础上修改了一下,一个server内部分service,然后每个service绑定一个bthread group 
tag,收到消息后根据tag进行分发。现在有一个问题,发现bthread_count监控数值不对,比如3个tag,总和是对的,但是有些group 
tag不对,看起来应该是task原来在group1上运行,但是退出是跑到group2上:
   ```
   # curl -s 127.0.0.1:47791/vars | grep bthread_count
   bthread_count : 14
   bthread_count_0 : 118431
   bthread_count_1 : 1
   bthread_count_2 : -118418
   ```
   
   我的处理是在`void ProcessRpcRequest(InputMessageBase* 
msg_base)`函数中,在`svc->CallMethod`之前判断tag,然后进行分发到对应的tag:
   ```
   void ProcessRpcRequest(InputMessageBase* msg_base) {
   
   if (!FLAGS_usercode_in_pthread) {
   // check bthread worker tag
   LOG(WARNING) << "bthread tag: " << mp->bthread_worker_tag << ", 
service_name:" << svc_name << ", method_name:" << mp->method->name() << 
std::endl;
   if (mp->bthread_worker_tag != BTHREAD_TAG_DEFAULT) {
   bthread_t th;
   bthread_attr_t attr = BTHREAD_ATTR_NORMAL;
   attr.tag = mp->bthread_worker_tag;
   
   bthread::CountdownEvent event(1);
   auto func = [method, , , , done, svc, ]() 
{
   svc->CallMethod(method, cntl.release(),
   req.release(), res.release(), done);
   event.signal();
   };
   std::function func_cp(func);
   LOG(WARNING) << "BthreadCallMethodRun before";
   int ret = bthread_start_background(, , 
BthreadCallMethodRun, _cp);
   // int ret = 0;
   // (*BthreadCallMethodRun)(_cp);
   LOG(WARNING) << "BthreadCallMethodRun ret: " << ret;
   event.wait();
   LOG(WARNING) << "BthreadCallMethodRun after wait: " << ret;
   if (ret != 0) {
   LOG(FATAL) << "Fail to start bthread_worker_tag";
   // return svc->CallMethod(method, cntl.release(),
   //req.release(), res.release(), 
done);
   }
   return;
   } else {
   return svc->CallMethod(method, cntl.release(),
  req.release(), res.release(), done);
   }
   }
   }
   ```
   tag是service注册时打上的。
   大佬帮忙看看是我修改的问题哪里没考虑到吗?


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-12-19 Thread via GitHub


wwbmmm merged PR #2358:
URL: https://github.com/apache/brpc/pull/2358


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-12-14 Thread via GitHub


justmao945 commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1857199286

   > > 大佬们这个现在有啥合并 master 的计划吗?有了 tag 也好支持 NUMA 分组了,不然大机型搞起来还有点费劲
   > 
   > @justmao945 @yanglimingcn @wwbmmm 我请教个小问题,大机型下,如果划分容器时直接绑定numa,这样就没有 
remote access 了。在软件层面实现 numa aware 
似乎只能逼近这个状态。所以为什么不直接用容器绑定numa?是因为内存的限制吗?还是因为有些场景不能接受使用容器,必须要用物理整机?
   
   大内存应用  


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-12-13 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1854982265

   > > 大佬们这个现在有啥合并 master 的计划吗?有了 tag 也好支持 NUMA 分组了,不然大机型搞起来还有点费劲
   > 
   > @justmao945 @yanglimingcn @wwbmmm 我请教个小问题,大机型下,如果划分容器时直接绑定numa,这样就没有 
remote access 了。在软件层面实现 numa aware 
似乎只能逼近这个状态。所以为什么不直接用容器绑定numa?是因为内存的限制吗?还是因为有些场景不能接受使用容器,必须要用物理整机?
   
   
的确有些场景不能或者不方便使用容器,我所接触的,比如,一些使用了dpdk、spdk、rdma等等这些对性能要求比较极致的应用,都绕过了内核,相当于自己直接管理硬件了。


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-12-13 Thread via GitHub


huntinux commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1853514284

   > 大佬们这个现在有啥合并 master 的计划吗?有了 tag 也好支持 NUMA 分组了,不然大机型搞起来还有点费劲
   
   @justmao945 @yanglimingcn @wwbmmm 我请教个小问题,大机型下,如果划分容器时直接绑定numa,这样就没有 remote 
access 了。在软件层面实现 numa aware 
似乎只能逼近这个状态。所以为什么不直接用容器绑定numa?是因为内存的限制吗?还是因为有些场景不能接受使用容器,必须要用物理整机?


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-12-13 Thread via GitHub


vinllen commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1853485155

   坐等合入


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-12-11 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1850986734

   > 大佬们这个现在有啥合并 master 的计划吗?有了 tag 也好支持 NUMA 分组了,不然大机型搞起来还有点费劲
   
   @wwbmmm 在review评估一下吧,看起来有需求的用户还挺多的。


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-12-11 Thread via GitHub


justmao945 commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1849848011

   大佬们这个现在有啥合并 master 的计划吗?有了 tag 也好支持 NUMA 分组了,不然大机型搞起来还有点费劲


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-11-02 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1790599380

   > > int bthread_set_tagged_worker_startfn(void (*start_fn)(bthread_tag_t)); 
我觉得这样的函数使用上有点受限,很多时候需要给这个startfn传递一个参数,去做一些thread local的初始化工作。 改成 int 
bthread_set_tagged_worker_startfn(void (*start_fn)(void *)) 你觉得可行吗?@wwbmmm
   > 
   > 是指这样吗?
   > 
   > ```
   > int bthread_set_tagged_worker_startfn(void (*start_fn)(void *), void* 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



Re: [PR] bthread task group add tag (brpc)

2023-11-02 Thread via GitHub


wwbmmm commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1790492064

   > int bthread_set_tagged_worker_startfn(void (*start_fn)(bthread_tag_t)); 
我觉得这样的函数使用上有点受限,很多时候需要给这个startfn传递一个参数,去做一些thread local的初始化工作。 改成 int 
bthread_set_tagged_worker_startfn(void (*start_fn)(void *)) 你觉得可行吗?@wwbmmm
   
   是指这样吗?
   int bthread_set_tagged_worker_startfn(void (*start_fn)(void *), void* 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



Re: [PR] bthread task group add tag (brpc)

2023-11-01 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1788869486

   int bthread_set_tagged_worker_startfn(void (*start_fn)(bthread_tag_t)); 
我觉得这样的函数使用上有点受限,很多时候需要给这个startfn传递一个参数,去做一些thread local的初始化工作。
   改成
   int bthread_set_tagged_worker_startfn(void (*start_fn)(void *))
   你觉得可行吗?
   


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-10-31 Thread via GitHub


wwbmmm commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1788374501

   LGTM


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-10-31 Thread via GitHub


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


##
example/bthread_tag_echo_c++/server.cpp:
##
@@ -0,0 +1,133 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// A server to receive EchoRequest and send back EchoResponse.
+
+#include 
+#include 
+#include 
+#include 
+#include "echo.pb.h"
+
+DEFINE_bool(echo_attachment, true, "Echo attachment as well");
+DEFINE_int32(port1, 8002, "TCP Port of this server");
+DEFINE_int32(port2, 8003, "TCP Port of this server");
+DEFINE_int32(tag1, 0, "Server1 tag");
+DEFINE_int32(tag2, 1, "Server2 tag");
+DEFINE_int32(idle_timeout_s, -1,
+ "Connection will be closed if there is no "
+ "read/write operations during the last `idle_timeout_s'");
+DEFINE_int32(max_concurrency, 0, "Limit of request processing in parallel");
+DEFINE_int32(internal_port, -1, "Only allow builtin services at this port");
+
+namespace example {
+// Your implementation of EchoService
+class EchoServiceImpl : public EchoService {
+public:
+EchoServiceImpl() {}
+~EchoServiceImpl() {}
+void Echo(google::protobuf::RpcController* cntl_base, const EchoRequest* 
request,
+  EchoResponse* response, google::protobuf::Closure* done) {
+brpc::ClosureGuard done_guard(done);
+brpc::Controller* cntl = static_cast(cntl_base);
+
+// Echo request and its attachment
+response->set_message(request->message());
+if (FLAGS_echo_attachment) {
+cntl->response_attachment().append(cntl->request_attachment());
+}
+}
+};
+}  // namespace example
+
+DEFINE_bool(h, false, "print help information");
+
+static void my_tagged_worker_start_fn(bthread_tag_t tag) {
+LOG(INFO) << "run tagged worker start function tag=" << tag;
+}
+
+int main(int argc, char* argv[]) {
+std::string help_str = "dummy help infomation";
+GFLAGS_NS::SetUsageMessage(help_str);
+
+// Parse gflags. We recommend you to use gflags as well.
+GFLAGS_NS::ParseCommandLineFlags(, , true);
+
+if (FLAGS_h) {
+fprintf(stderr, "%s\n%s\n%s", help_str.c_str(), help_str.c_str(), 
help_str.c_str());
+return 0;
+}
+
+// Set tagged worker function
+bthread_set_tagged_worker_startfn(my_tagged_worker_start_fn);
+
+// Generally you only need one Server.
+brpc::Server server1;
+
+// Instance of your service.
+example::EchoServiceImpl echo_service_impl1;
+
+// Add the service into server. Notice the second parameter, because the
+// service is put on stack, we don't want server to delete it, otherwise
+// use brpc::SERVER_OWNS_SERVICE.
+if (server1.AddService(_service_impl1, 
brpc::SERVER_DOESNT_OWN_SERVICE) != 0) {
+LOG(ERROR) << "Fail to add service";
+return -1;
+}
+
+// Start the server.
+brpc::ServerOptions options1;
+options1.idle_timeout_sec = FLAGS_idle_timeout_s;
+options1.max_concurrency = FLAGS_max_concurrency;
+options1.internal_port = FLAGS_internal_port;
+options1.bthread_tag = FLAGS_tag1;
+if (server1.Start(FLAGS_port1, ) != 0) {
+LOG(ERROR) << "Fail to start EchoServer";
+return -1;
+}
+
+// Generally you only need one Server.
+brpc::Server server2;
+
+// Instance of your service.
+example::EchoServiceImpl echo_service_impl2;
+
+// Add the service into server. Notice the second parameter, because the
+// service is put on stack, we don't want server to delete it, otherwise
+// use brpc::SERVER_OWNS_SERVICE.
+if (server2.AddService(_service_impl2, 
brpc::SERVER_DOESNT_OWN_SERVICE) != 0) {
+LOG(ERROR) << "Fail to add service";
+return -1;
+}
+
+// Start the server.
+brpc::ServerOptions options2;
+options2.idle_timeout_sec = FLAGS_idle_timeout_s;
+options2.max_concurrency = FLAGS_max_concurrency;
+options2.internal_port = FLAGS_internal_port;

Review Comment:
   两个server的internal_port是同一个,不会冲突吗?



##
example/bthread_tag_echo_c++/server.cpp:
##
@@ -0,0 +1,133 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file

Re: [PR] bthread task group add tag (brpc)

2023-10-25 Thread via GitHub


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(arg);
-TaskGroup* g = c->create_group();
+
+auto dummy = static_cast(arg);

Review Comment:
   用std::unique_ptr?



##
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(arg);
-TaskGroup* g = c->create_group();
+
+auto dummy = static_cast(arg);

Review Comment:
   用std::unique_ptr?



##
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



Re: [PR] bthread task group add tag (brpc)

2023-10-22 Thread via GitHub


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


##
src/bthread/bthread.cpp:
##
@@ -111,38 +135,49 @@ static bool validate_bthread_min_concurrency(const char*, 
int32_t val) {
 BAIDU_SCOPED_LOCK(g_task_control_mutex);
 int concurrency = c->concurrency();
 if (val > concurrency) {
-int added = c->add_workers(val - concurrency);
+int added = bthread::add_workers_for_each_tag(val - concurrency);
 return added == (val - concurrency);
 } else {
 return true;
 }
 }
 
+static bool validate_bthread_tag_to_set(const char*, int32_t val) {
+return val >= BTHREAD_TAG_INVALID && val < FLAGS_task_group_ntags;
+}
+
 __thread TaskGroup* tls_task_group_nosignal = NULL;
 
 BUTIL_FORCE_INLINE int
 start_from_non_worker(bthread_t* __restrict tid,
   const bthread_attr_t* __restrict attr,
-  void * (*fn)(void*),
+  void* (*fn)(void*),
   void* __restrict arg) {
 TaskControl* c = get_or_new_task_control();
 if (NULL == c) {
 return ENOMEM;
 }
+TaskGroup* g = NULL;
 if (attr != NULL && (attr->flags & BTHREAD_NOSIGNAL)) {
 // Remember the TaskGroup to insert NOSIGNAL tasks for 2 reasons:
 // 1. NOSIGNAL is often for creating many bthreads in batch,
 //inserting into the same TaskGroup maximizes the batch.
 // 2. bthread_flush() needs to know which TaskGroup to flush.
-TaskGroup* g = tls_task_group_nosignal;
+g = tls_task_group_nosignal;
 if (NULL == g) {
-g = c->choose_one_group();
+g = c->choose_one_group_with_tag(attr->tag);
 tls_task_group_nosignal = g;
 }
 return g->start_background(tid, attr, fn, arg);
 }
-return c->choose_one_group()->start_background(
-tid, attr, fn, arg);
+g = c->choose_one_group_with_tag(attr ? attr->tag : BTHREAD_TAG_DEFAULT);
+return g->start_background(tid, attr, fn, arg);
+}
+
+// if tag is default or equal to thread local use thread local task group
+BUTIL_FORCE_INLINE bool can_run_thread_local(const bthread_attr_t* __restrict 
attr) {
+return attr == nullptr || attr->tag == BTHREAD_TAG_DEFAULT ||

Review Comment:
   "用户启动的bthread,如果attr为null的话,会自然继承父bthread的属性。"
   bthread没这个逻辑吧?如果attr为null,则使用BTHREAD_ATTR_NORMAL



-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-10-22 Thread via GitHub


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


##
src/bthread/bthread.cpp:
##
@@ -111,38 +135,49 @@ static bool validate_bthread_min_concurrency(const char*, 
int32_t val) {
 BAIDU_SCOPED_LOCK(g_task_control_mutex);
 int concurrency = c->concurrency();
 if (val > concurrency) {
-int added = c->add_workers(val - concurrency);
+int added = bthread::add_workers_for_each_tag(val - concurrency);
 return added == (val - concurrency);
 } else {
 return true;
 }
 }
 
+static bool validate_bthread_tag_to_set(const char*, int32_t val) {
+return val >= BTHREAD_TAG_INVALID && val < FLAGS_task_group_ntags;
+}
+
 __thread TaskGroup* tls_task_group_nosignal = NULL;
 
 BUTIL_FORCE_INLINE int
 start_from_non_worker(bthread_t* __restrict tid,
   const bthread_attr_t* __restrict attr,
-  void * (*fn)(void*),
+  void* (*fn)(void*),
   void* __restrict arg) {
 TaskControl* c = get_or_new_task_control();
 if (NULL == c) {
 return ENOMEM;
 }
+TaskGroup* g = NULL;
 if (attr != NULL && (attr->flags & BTHREAD_NOSIGNAL)) {
 // Remember the TaskGroup to insert NOSIGNAL tasks for 2 reasons:
 // 1. NOSIGNAL is often for creating many bthreads in batch,
 //inserting into the same TaskGroup maximizes the batch.
 // 2. bthread_flush() needs to know which TaskGroup to flush.
-TaskGroup* g = tls_task_group_nosignal;
+g = tls_task_group_nosignal;
 if (NULL == g) {
-g = c->choose_one_group();
+g = c->choose_one_group_with_tag(attr->tag);
 tls_task_group_nosignal = g;
 }
 return g->start_background(tid, attr, fn, arg);
 }
-return c->choose_one_group()->start_background(
-tid, attr, fn, arg);
+g = c->choose_one_group_with_tag(attr ? attr->tag : BTHREAD_TAG_DEFAULT);
+return g->start_background(tid, attr, fn, arg);
+}
+
+// if tag is default or equal to thread local use thread local task group
+BUTIL_FORCE_INLINE bool can_run_thread_local(const bthread_attr_t* __restrict 
attr) {
+return attr == nullptr || attr->tag == BTHREAD_TAG_DEFAULT ||

Review Comment:
   "用户启动的bthread,如果attr为null的话,会自然继承父bthread的属性。"
   bthread没这个逻辑吧?如果attr为null,则使用BTHREAD_ATTR_NORMAL



##
src/bthread/bthread.cpp:
##
@@ -111,38 +135,49 @@ static bool validate_bthread_min_concurrency(const char*, 
int32_t val) {
 BAIDU_SCOPED_LOCK(g_task_control_mutex);
 int concurrency = c->concurrency();
 if (val > concurrency) {
-int added = c->add_workers(val - concurrency);
+int added = bthread::add_workers_for_each_tag(val - concurrency);
 return added == (val - concurrency);
 } else {
 return true;
 }
 }
 
+static bool validate_bthread_tag_to_set(const char*, int32_t val) {
+return val >= BTHREAD_TAG_INVALID && val < FLAGS_task_group_ntags;
+}
+
 __thread TaskGroup* tls_task_group_nosignal = NULL;
 
 BUTIL_FORCE_INLINE int
 start_from_non_worker(bthread_t* __restrict tid,
   const bthread_attr_t* __restrict attr,
-  void * (*fn)(void*),
+  void* (*fn)(void*),
   void* __restrict arg) {
 TaskControl* c = get_or_new_task_control();
 if (NULL == c) {
 return ENOMEM;
 }
+TaskGroup* g = NULL;
 if (attr != NULL && (attr->flags & BTHREAD_NOSIGNAL)) {
 // Remember the TaskGroup to insert NOSIGNAL tasks for 2 reasons:
 // 1. NOSIGNAL is often for creating many bthreads in batch,
 //inserting into the same TaskGroup maximizes the batch.
 // 2. bthread_flush() needs to know which TaskGroup to flush.
-TaskGroup* g = tls_task_group_nosignal;
+g = tls_task_group_nosignal;
 if (NULL == g) {
-g = c->choose_one_group();
+g = c->choose_one_group_with_tag(attr->tag);
 tls_task_group_nosignal = g;
 }
 return g->start_background(tid, attr, fn, arg);
 }
-return c->choose_one_group()->start_background(
-tid, attr, fn, arg);
+g = c->choose_one_group_with_tag(attr ? attr->tag : BTHREAD_TAG_DEFAULT);
+return g->start_background(tid, attr, fn, arg);
+}
+
+// if tag is default or equal to thread local use thread local task group
+BUTIL_FORCE_INLINE bool can_run_thread_local(const bthread_attr_t* __restrict 
attr) {
+return attr == nullptr || attr->tag == BTHREAD_TAG_DEFAULT ||

Review Comment:
   "用户启动的bthread,如果attr为null的话,会自然继承父bthread的属性。"
   bthread没这个逻辑吧?如果attr为null,则使用BTHREAD_ATTR_NORMAL



-- 
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


Re: [PR] bthread task group add tag (brpc)

2023-10-22 Thread via GitHub


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


##
src/bthread/bthread.cpp:
##
@@ -306,8 +345,14 @@ int bthread_setconcurrency(int num) {
 }
 if (num > bthread::FLAGS_bthread_concurrency) {
 // Create more workers if needed.
-bthread::FLAGS_bthread_concurrency +=
-c->add_workers(num - bthread::FLAGS_bthread_concurrency);
+auto tag = bthread::FLAGS_bthread_tag_to_set;
+auto add = num - bthread::FLAGS_bthread_concurrency;
+if (tag == BTHREAD_TAG_INVALID) {
+add = bthread::add_workers_for_each_tag(add);

Review Comment:
   bthread_setconcurrency_by_tag(int num, bthread_tag_t tag) 这样?



##
src/bthread/bthread.cpp:
##
@@ -306,8 +345,14 @@ int bthread_setconcurrency(int num) {
 }
 if (num > bthread::FLAGS_bthread_concurrency) {
 // Create more workers if needed.
-bthread::FLAGS_bthread_concurrency +=
-c->add_workers(num - bthread::FLAGS_bthread_concurrency);
+auto tag = bthread::FLAGS_bthread_tag_to_set;
+auto add = num - bthread::FLAGS_bthread_concurrency;
+if (tag == BTHREAD_TAG_INVALID) {
+add = bthread::add_workers_for_each_tag(add);

Review Comment:
   bthread_setconcurrency_by_tag(int num, bthread_tag_t tag) 这样?



-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-10-20 Thread via GitHub


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


##
src/bthread/bthread.cpp:
##
@@ -111,38 +135,49 @@ static bool validate_bthread_min_concurrency(const char*, 
int32_t val) {
 BAIDU_SCOPED_LOCK(g_task_control_mutex);
 int concurrency = c->concurrency();
 if (val > concurrency) {
-int added = c->add_workers(val - concurrency);
+int added = bthread::add_workers_for_each_tag(val - concurrency);
 return added == (val - concurrency);
 } else {
 return true;
 }
 }
 
+static bool validate_bthread_tag_to_set(const char*, int32_t val) {
+return val >= BTHREAD_TAG_INVALID && val < FLAGS_task_group_ntags;
+}
+
 __thread TaskGroup* tls_task_group_nosignal = NULL;
 
 BUTIL_FORCE_INLINE int
 start_from_non_worker(bthread_t* __restrict tid,
   const bthread_attr_t* __restrict attr,
-  void * (*fn)(void*),
+  void* (*fn)(void*),
   void* __restrict arg) {
 TaskControl* c = get_or_new_task_control();
 if (NULL == c) {
 return ENOMEM;
 }
+TaskGroup* g = NULL;
 if (attr != NULL && (attr->flags & BTHREAD_NOSIGNAL)) {
 // Remember the TaskGroup to insert NOSIGNAL tasks for 2 reasons:
 // 1. NOSIGNAL is often for creating many bthreads in batch,
 //inserting into the same TaskGroup maximizes the batch.
 // 2. bthread_flush() needs to know which TaskGroup to flush.
-TaskGroup* g = tls_task_group_nosignal;
+g = tls_task_group_nosignal;
 if (NULL == g) {
-g = c->choose_one_group();
+g = c->choose_one_group_with_tag(attr->tag);
 tls_task_group_nosignal = g;
 }
 return g->start_background(tid, attr, fn, arg);
 }
-return c->choose_one_group()->start_background(
-tid, attr, fn, arg);
+g = c->choose_one_group_with_tag(attr ? attr->tag : BTHREAD_TAG_DEFAULT);
+return g->start_background(tid, attr, fn, arg);
+}
+
+// if tag is default or equal to thread local use thread local task group
+BUTIL_FORCE_INLINE bool can_run_thread_local(const bthread_attr_t* __restrict 
attr) {
+return attr == nullptr || attr->tag == BTHREAD_TAG_DEFAULT ||

Review Comment:
   
这块感觉可以把BTHREAD_TAG_DEFAULT的校验去掉,因为现在brpc内部启动的bthread,要么是NULL,要么是默认的BTHREAD_ATTR_XXX,attr.tag都会被设置成BTHREAD_TAG_DEFAULT。
   
网络上来的请求启动的bthread都已经是设置好了tag的,用户启动的bthread,如果attr为null的话,会自然继承父bthread的属性。如果用户想要设置attr的话,tag也必须设置合理,可以使用bthread_self_tag()来获取当前tag上下文。



##
src/bthread/bthread.cpp:
##
@@ -111,38 +135,49 @@ static bool validate_bthread_min_concurrency(const char*, 
int32_t val) {
 BAIDU_SCOPED_LOCK(g_task_control_mutex);
 int concurrency = c->concurrency();
 if (val > concurrency) {
-int added = c->add_workers(val - concurrency);
+int added = bthread::add_workers_for_each_tag(val - concurrency);
 return added == (val - concurrency);
 } else {
 return true;
 }
 }
 
+static bool validate_bthread_tag_to_set(const char*, int32_t val) {
+return val >= BTHREAD_TAG_INVALID && val < FLAGS_task_group_ntags;
+}
+
 __thread TaskGroup* tls_task_group_nosignal = NULL;
 
 BUTIL_FORCE_INLINE int
 start_from_non_worker(bthread_t* __restrict tid,
   const bthread_attr_t* __restrict attr,
-  void * (*fn)(void*),
+  void* (*fn)(void*),
   void* __restrict arg) {
 TaskControl* c = get_or_new_task_control();
 if (NULL == c) {
 return ENOMEM;
 }
+TaskGroup* g = NULL;
 if (attr != NULL && (attr->flags & BTHREAD_NOSIGNAL)) {
 // Remember the TaskGroup to insert NOSIGNAL tasks for 2 reasons:
 // 1. NOSIGNAL is often for creating many bthreads in batch,
 //inserting into the same TaskGroup maximizes the batch.
 // 2. bthread_flush() needs to know which TaskGroup to flush.
-TaskGroup* g = tls_task_group_nosignal;
+g = tls_task_group_nosignal;
 if (NULL == g) {
-g = c->choose_one_group();
+g = c->choose_one_group_with_tag(attr->tag);
 tls_task_group_nosignal = g;
 }
 return g->start_background(tid, attr, fn, arg);
 }
-return c->choose_one_group()->start_background(
-tid, attr, fn, arg);
+g = c->choose_one_group_with_tag(attr ? attr->tag : BTHREAD_TAG_DEFAULT);
+return g->start_background(tid, attr, fn, arg);
+}
+
+// if tag is default or equal to thread local use thread local task group
+BUTIL_FORCE_INLINE bool can_run_thread_local(const bthread_attr_t* __restrict 
attr) {
+return attr == nullptr || attr->tag == BTHREAD_TAG_DEFAULT ||

Review Comment:
   
这块感觉可以把BTHREAD_TAG_DEFAULT的校验去掉,因为现在brpc内部启动的bthread,要么是NULL,要么是默认的BTHREAD_ATTR_XXX,attr.tag都会被设置成BTHREAD_TAG_DEFAULT。
   

Re: [PR] bthread task group add tag (brpc)

2023-10-20 Thread via GitHub


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


##
src/bthread/bthread.cpp:
##
@@ -306,8 +345,14 @@ int bthread_setconcurrency(int num) {
 }
 if (num > bthread::FLAGS_bthread_concurrency) {
 // Create more workers if needed.
-bthread::FLAGS_bthread_concurrency +=
-c->add_workers(num - bthread::FLAGS_bthread_concurrency);
+auto tag = bthread::FLAGS_bthread_tag_to_set;
+auto add = num - bthread::FLAGS_bthread_concurrency;
+if (tag == BTHREAD_TAG_INVALID) {
+add = bthread::add_workers_for_each_tag(add);

Review Comment:
   这块有啥建议怎么搞吗



##
src/bthread/bthread.cpp:
##
@@ -306,8 +345,14 @@ int bthread_setconcurrency(int num) {
 }
 if (num > bthread::FLAGS_bthread_concurrency) {
 // Create more workers if needed.
-bthread::FLAGS_bthread_concurrency +=
-c->add_workers(num - bthread::FLAGS_bthread_concurrency);
+auto tag = bthread::FLAGS_bthread_tag_to_set;
+auto add = num - bthread::FLAGS_bthread_concurrency;
+if (tag == BTHREAD_TAG_INVALID) {
+add = bthread::add_workers_for_each_tag(add);

Review Comment:
   这块有啥建议怎么搞吗



-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-10-19 Thread via GitHub


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


##
src/bthread/bthread.cpp:
##
@@ -306,8 +345,14 @@ int bthread_setconcurrency(int num) {
 }
 if (num > bthread::FLAGS_bthread_concurrency) {
 // Create more workers if needed.
-bthread::FLAGS_bthread_concurrency +=
-c->add_workers(num - bthread::FLAGS_bthread_concurrency);
+auto tag = bthread::FLAGS_bthread_tag_to_set;
+auto add = num - bthread::FLAGS_bthread_concurrency;
+if (tag == BTHREAD_TAG_INVALID) {
+add = bthread::add_workers_for_each_tag(add);

Review Comment:
   这块有点纠结,感觉一个gflags没法操作某个tag的数量,bthread_setconcurrency(int num, bthread_tag_t 
tag)这个函数也是希望能用gflags来控制吧。



##
src/bthread/bthread.cpp:
##
@@ -306,8 +345,14 @@ int bthread_setconcurrency(int num) {
 }
 if (num > bthread::FLAGS_bthread_concurrency) {
 // Create more workers if needed.
-bthread::FLAGS_bthread_concurrency +=
-c->add_workers(num - bthread::FLAGS_bthread_concurrency);
+auto tag = bthread::FLAGS_bthread_tag_to_set;
+auto add = num - bthread::FLAGS_bthread_concurrency;
+if (tag == BTHREAD_TAG_INVALID) {
+add = bthread::add_workers_for_each_tag(add);

Review Comment:
   这块有点纠结,感觉一个gflags没法操作某个tag的数量,bthread_setconcurrency(int num, bthread_tag_t 
tag)这个函数也是希望能用gflags来控制吧。



-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-10-19 Thread via GitHub


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


##
src/bthread/bthread.cpp:
##
@@ -306,8 +345,14 @@ int bthread_setconcurrency(int num) {
 }
 if (num > bthread::FLAGS_bthread_concurrency) {
 // Create more workers if needed.
-bthread::FLAGS_bthread_concurrency +=
-c->add_workers(num - bthread::FLAGS_bthread_concurrency);
+auto tag = bthread::FLAGS_bthread_tag_to_set;
+auto add = num - bthread::FLAGS_bthread_concurrency;
+if (tag == BTHREAD_TAG_INVALID) {
+add = bthread::add_workers_for_each_tag(add);

Review Comment:
   这块的函数声明都是extern "C"的,是不是不能同名啊?



##
src/bthread/bthread.cpp:
##
@@ -306,8 +345,14 @@ int bthread_setconcurrency(int num) {
 }
 if (num > bthread::FLAGS_bthread_concurrency) {
 // Create more workers if needed.
-bthread::FLAGS_bthread_concurrency +=
-c->add_workers(num - bthread::FLAGS_bthread_concurrency);
+auto tag = bthread::FLAGS_bthread_tag_to_set;
+auto add = num - bthread::FLAGS_bthread_concurrency;
+if (tag == BTHREAD_TAG_INVALID) {
+add = bthread::add_workers_for_each_tag(add);

Review Comment:
   这块的函数声明都是extern "C"的,是不是不能同名啊?



-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-10-18 Thread via GitHub


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


##
example/bthread_tag_echo_c++/cert.pem:
##
@@ -0,0 +1,26 @@
+-BEGIN CERTIFICATE-
+MIIEUTCCAzmgAwIBAgIBADANBgkqhkiG9w0BAQQFADB9MQswCQYDVQQGEwJDTjER

Review Comment:
   这个不需要吧



##
example/bthread_tag_echo_c++/CMakeLists.txt:
##
@@ -0,0 +1,150 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+cmake_minimum_required(VERSION 2.8.10)
+project(multi_threaded_echo_c++ C CXX)

Review Comment:
   名字改一下



##
src/brpc/acceptor.h:
##
@@ -112,6 +112,9 @@ friend class Server;
 
 // Whether to use rdma or not
 bool _use_rdma;
+
+// Acceptor belongs to this tag
+bthread_tag_t _tag;

Review Comment:
   命名: _bthread_tag



##
src/brpc/socket.h:
##
@@ -750,6 +752,7 @@ friend void DereferenceSocket(Socket*);
 
 // [ Set in ResetFileDescriptor ]
 butil::atomic _fd;  // -1 when not connected.
+bthread_tag_t _tag;   // tag of this socket

Review Comment:
   命名: _bthread_tag



##
example/bthread_tag_echo_c++/client.cpp:
##
@@ -0,0 +1,164 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// A client sending requests to server by multiple threads.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "echo.pb.h"
+#include 
+
+DEFINE_int32(thread_num, 50, "Number of threads to send requests");
+DEFINE_bool(use_bthread, false, "Use bthread to send requests");
+DEFINE_int32(attachment_size, 0, "Carry so many byte attachment along with 
requests");
+DEFINE_int32(request_size, 16, "Bytes of each request");
+DEFINE_string(protocol, "baidu_std", "Protocol type. Defined in 
src/brpc/options.proto");
+DEFINE_string(connection_type, "", "Connection type. Available values: single, 
pooled, short");
+DEFINE_string(server, "0.0.0.0:8002", "IP Address of server");
+DEFINE_string(load_balancer, "", "The algorithm for load balancing");
+DEFINE_int32(timeout_ms, 100, "RPC timeout in milliseconds");
+DEFINE_int32(max_retry, 3, "Max retries(not including the first RPC)"); 
+DEFINE_bool(dont_fail, false, "Print fatal when some call failed");
+DEFINE_bool(enable_ssl, false, "Use SSL connection");
+DEFINE_int32(dummy_port, -1, "Launch dummy server at this port");
+DEFINE_string(connection_group, "", "Connection group for channel");
+DEFINE_int32(bthread_tag, BTHREAD_TAG_DEFAULT, "bthread used tag");
+
+std::string g_request;
+std::string g_attachment;
+
+bvar::LatencyRecorder g_latency_recorder("client");
+bvar::Adder g_error_count("client_error_count");
+
+static void* sender(void* arg) {
+// Normally, you should not call a Channel directly, but instead construct
+// a stub Service wrapping it. stub can be shared by all threads as well.
+example::EchoService_Stub 
stub(static_cast(arg));
+
+int log_id = 0;
+while (!brpc::IsAskedToQuit()) {
+// We will receive response synchronously, safe to put variables
+// on stack.
+example::EchoRequest request;
+example::EchoResponse response;
+brpc::Controller cntl;
+
+request.set_message(g_request);
+cntl.set_log_id(log_id++);  // set by user
+// Set attachment which is wired to network directly instead of 
+// being serialized into protobuf messages.
+cntl.request_attachment().append(g_attachment);
+
+// Because `done'(last parameter) is NULL, this function waits 

Re: [PR] bthread task group add tag (brpc)

2023-10-17 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1766263407

   > 
关于这个MR我有个疑问:现在server端tag都是绑定的端口吗?客户端通过设置bthread_attr_t中的tag,发到server对应的不同线程池。对server端来说,也就是说一个bthread线程池对应的一个端口,没办法做到一个端口内根据某个tag转发到不同线程池,是吧?
 我们目前对控制链路(braft)和数据链路(brpc server)都是用的同一个端口,这种情况下如果要拆分线程池的话,在不修改代码前提下,只能拆端口吧?
   
   现在一个tag对应一组线程池,也对应着一个独立的端口。所以客户端是通过访问不同端口做到线程池的隔离的。控制链路(braft)和数据链路(brpc 
server)都是用的同一个端口这种情况,只能将控制链路和数据链路拆分到两个不同Server中,每个Server使用一个端口。


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-10-17 Thread via GitHub


vinllen commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1766244600

   
关于这个MR我有个疑问:现在server端tag都是绑定的端口吗?客户端通过设置bthread_attr_t中的tag,发到server对应的不同线程池。对server端来说,也就是说一个bthread线程池对应的一个端口,没办法做到一个端口内根据某个tag转发到不同线程池,是吧?
   我们目前对控制链路(braft)和数据链路(brpc server)都是用的同一个端口,这种情况下如果要拆分线程池的话,在不修改代码前提下,只能拆端口吧?


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-10-16 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1765470300

   > @yanglimingcn 大佬 这个MR什么时候ready,坐等~
   
   
这个MR已经按照上边的讨论改完了,动态修改某个tag的worker数量也支持了,可以看这个MR里面的wiki,现在就是等社区同学review,看是否还有啥问题。


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-10-13 Thread via GitHub


vinllen commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1761095330

   @yanglimingcn 大佬 这个MR什么时候ready,坐等~


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-09-28 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1740211874

   > > * 如果能用端口比较灵活的做到请求处理逻辑的隔离和IO的隔离,我觉得是可以的,这块能做到吗?
   > 
   > 我觉得可以,创建Acceptor时可以指定tag,然后listen 
fd对应的Socket指定这个tag,后面这个Socket产生的事件都会在这个tag的worker中处理。这样对性能也没什么损失
   
   我觉得这个方式很合理,我按照这个方式修改一下。


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-09-27 Thread via GitHub


wwbmmm commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1738331446

   > > * 如果能用端口比较灵活的做到请求处理逻辑的隔离和IO的隔离,我觉得是可以的,这块能做到吗?
   我觉得可以,创建Acceptor时可以指定tag,然后listen 
fd对应的Socket指定这个tag,后面这个Socket产生的事件都会在这个tag的worker中处理。这样对性能也没什么损失
   
   


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-09-27 Thread via GitHub


wwbmmm commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1738331310

   > * 如果能用端口比较灵活的做到请求处理逻辑的隔离和IO的隔离,我觉得是可以的,这块能做到吗?
   我觉得可以,创建Acceptor时可以指定tag,然后listen 
fd对应的Socket指定这个tag,后面这个Socket产生的事件都会在这个tag的worker中处理。这样对性能也没什么损失
   
   


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-09-27 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1738307112

   > > > ```
   > > >  
这块其实现在是能兼容原有协议的,只是新Client能交互tag信息,server端拿到信息可以用来区分不同tag的woker组。如果旧的Client发送消息,因为没有PTAG这个包,请求就会在默认的那个worker池子里面执行,就像现在只有一个woker组一样。
   > > > ```
   > 
   > 
   > 虽然旧的Client也能处理,但是只能放在默认的worker组里处理。无法做到所有Client一视同仁,按照请求的业务性质来决定worker组。
   > 
另外,新Client发给旧Server是不兼容的。好像只要用户升级了这个版本的brpc,client端发出来的包就都会带上这个头?那旧server就处理不了了。
   > 
   > 
   > > > ```
   > > >  
这块其实不是让Client决定Server的tag数量,Server根据自身服务的接口来决定tag的数量,Client端要是想把请求按照预期划分开到Server不同的worker组处理,就需要按照Server的规则去设置connection_group去访问Server。
   > > > ```
   > 
   > 
   > 嗯,我的意思是让Client来决定哪些请求进哪个worker组,不太合理。因为这个属于server内部实现的细节,client不应该关注。
   > 
   > 
   > > > ```
   > > >  
其实一开始也想要这么去做的,但是感觉性能上会有些损失,bthread_start_xxx将任务发送到指定的worker上会有线程间的交互,不如现在这种任务解析出来到放到thread
 local的worker上去了。最终其实还是希望能做到Run To Complete。
   > > > ```
   > 
   > 
   > 如果用端口来区分,应该不会有性能损失吧?
   > 
   > 
   > > > 2. 
关于bthread支持多tag,是否考虑支持不同的tag指定不同的worker数量呢?毕竟不同tag执行的业务逻辑性质会有较大的差异,对worker数量的需求应该是不一样的
   > > >这个不太好做,目前就是依赖把bthread_min_concurrency配置成非0,让服务自动调整worker线程的数量。
   > 
   > 
   > 不太好做可以放到后面再实现。不过设计上,最好考虑未来实现这个功能是否好做,以免后面要大改。
   
   


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-09-27 Thread via GitHub


yanglimingcn closed pull request #2358: bthread task group add tag
URL: https://github.com/apache/brpc/pull/2358


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-09-27 Thread via GitHub


wwbmmm commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1737317632

   > >  
这块其实现在是能兼容原有协议的,只是新Client能交互tag信息,server端拿到信息可以用来区分不同tag的woker组。如果旧的Client发送消息,因为没有PTAG这个包,请求就会在默认的那个worker池子里面执行,就像现在只有一个woker组一样。
   虽然旧的Client也能处理,但是只能放在默认的worker组里处理。无法做到所有Client一视同仁,按照请求的业务性质来决定worker组。
   
另外,新Client发给旧Server是不兼容的。好像只要用户升级了这个版本的brpc,client端发出来的包就都会带上这个头?那旧server就处理不了了。
   
   > >  
这块其实不是让Client决定Server的tag数量,Server根据自身服务的接口来决定tag的数量,Client端要是想把请求按照预期划分开到Server不同的worker组处理,就需要按照Server的规则去设置connection_group去访问Server。
   嗯,我的意思是让Client来决定哪些请求进哪个worker组,不太合理。因为这个属于server内部实现的细节,client不应该关注。
   
   > >  
其实一开始也想要这么去做的,但是感觉性能上会有些损失,bthread_start_xxx将任务发送到指定的worker上会有线程间的交互,不如现在这种任务解析出来到放到thread
 local的worker上去了。最终其实还是希望能做到Run To Complete。
   如果用端口来区分,应该不会有性能损失吧?
   
   > > 2. 
关于bthread支持多tag,是否考虑支持不同的tag指定不同的worker数量呢?毕竟不同tag执行的业务逻辑性质会有较大的差异,对worker数量的需求应该是不一样的
   > >这个不太好做,目前就是依赖把bthread_min_concurrency配置成非0,让服务自动调整worker线程的数量。
   
   不太好做可以放到后面再实现。不过设计上,最好考虑未来实现这个功能是否好做,以免后面要大改。
   


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-09-27 Thread via GitHub


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


##
src/bthread/butex.cpp:
##
@@ -273,15 +273,16 @@ void butex_destroy(void* butex) {
 }
 
 inline TaskGroup* get_task_group(TaskControl* c, bool nosignal = false) {
-TaskGroup* g;
+TaskGroup* g = tls_task_group;
 if (nosignal) {
-g = tls_task_group_nosignal;
-if (NULL == g) {
-g = c->choose_one_group();
+if (NULL == tls_task_group_nosignal) {
+g = g ? g : c->choose_one_group();

Review Comment:
   这块是尽量选择thread local,感觉更合理。



##
src/bthread/butex.cpp:
##
@@ -273,15 +273,16 @@ void butex_destroy(void* butex) {
 }
 
 inline TaskGroup* get_task_group(TaskControl* c, bool nosignal = false) {
-TaskGroup* g;
+TaskGroup* g = tls_task_group;
 if (nosignal) {
-g = tls_task_group_nosignal;
-if (NULL == g) {
-g = c->choose_one_group();
+if (NULL == tls_task_group_nosignal) {
+g = g ? g : c->choose_one_group();

Review Comment:
   这块是尽量选择thread local,感觉更合理。



-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-09-27 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1737255624

   > 上面提了一些小问题。 另外想探讨一下整体的设计:
   > 
   > 1. 
目前看来Server端分tag需要依赖于Client端设置connection_group,在Socket中把tag相关信息传过来。但是这样的话存在问题:
   >
   >* 修改了通信协议,强依赖于支持该特性的Client,无法兼容以前的Client

这块其实现在是能兼容原有协议的,只是新Client能交互tag信息,server端拿到信息可以用来区分不同tag的woker组。如果旧的Client发送消息,因为没有PTAG这个包,请求就会在默认的那个worker池子里面执行,就像现在只有一个woker组一样。
   >* 让Client来决定Server的worker tag是否合理?按理说worker 
tag应该由server端的业务逻辑决定。如果server想要调整worker tag,还需要修改所有的Client,这也不方便吧

这块其实不是让Client决定Server的tag数量,Server根据自身服务的接口来决定tag的数量,Client端要是想把请求按照预期划分开到Server不同的worker组处理,就需要按照Server的规则去设置connection_group去访问Server。
   >  针对这个问题,我的建议是这样:
   >* 对于请求处理逻辑中的隔离,可以在用户callback里,自己指定tag调用bthread_start_xxx来将任务发送到指定的worker
   >* 对于IO的隔离,可以考虑按照端口来隔离,不同端口的Server指定不同的tag。
   
其实一开始也想要这么去做的,但是感觉性能上会有些损失,bthread_start_xxx将任务发送到指定的worker上会有线程间的交互,不如现在这种任务解析出来到放到thread
 local的worker上去了。最终其实还是希望能做到Run To Complete。
   >* 可以把bthread支持多tag和brpc支持多tag的PR分成两个,我理解前者更没有争议一些
   这个可以的
   > 2. 
关于bthread支持多tag,是否考虑支持不同的tag指定不同的worker数量呢?毕竟不同tag执行的业务逻辑性质会有较大的差异,对worker数量的需求应该是不一样的
  这个不太好做,目前就是依赖把bthread_min_concurrency配置成非0,让服务自动调整worker线程的数量。
   


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-09-26 Thread via GitHub


wwbmmm commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1735415459

   上面提了一些小问题。
   另外想探讨一下整体的设计:
   1. 
目前看来Server端分tag需要依赖于Client端设置connection_group,在Socket中把tag相关信息传过来。但是这样的话存在问题:
  * 修改了通信协议,强依赖于支持该特性的Client,无法兼容以前的Client
  * 让Client来决定Server的worker tag是否合理?按理说worker 
tag应该由server端的业务逻辑决定。如果server想要调整worker tag,还需要修改所有的Client,这也不方便吧
  针对这个问题,我的建议是这样:
  * 对于请求处理逻辑中的隔离,可以在用户callback里,自己指定tag调用bthread_start_xxx来将任务发送到指定的worker
  * 对于IO的隔离,可以考虑按照端口来隔离,不同端口的Server指定不同的tag。
  * 可以把bthread支持多tag和brpc支持多worker池的PR分成两个,我理解前者更没有争议一些
   2. 
关于bthread支持多tag,是否考虑支持不同的tag指定不同的worker数量呢?毕竟不同tag执行的业务逻辑性质会有较大的差异,对worker数量的需求应该是不一样的


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-09-26 Thread via GitHub


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


##
docs/cn/bthread_tagged_task_group.md:
##
@@ -0,0 +1,34 @@
+
+# Bthread tagged task group
+
+在很多应用开发过程中都会有线程资源隔离的需求,比如服务分为控制层和数据层,数据层的请求压力大,不需要控制层受到影响;再比如,服务有多个磁盘,希望磁盘之间没有什么影响资源上的影响等。bthread的任务组打标签就是实现bthread的worker线程池按照tag分组,让不同分组之间达到没有互相影响的目的。客户端需要配合服务端使用,客户端配置channel的connection_group选项将请求分类,这些分类请求将自然的分配到服务端不同的线程池tag分组里面去。
+
+# 使用方式
+
+在example/bthread_tag_echo_c++里面有一个实例代码,分别启动服务端和客户端,服务端将worker划分成3个tag(分组),客户端可以设置不同的connection_group来访问不同的分组,例子里面设置为Test1、Test2、Test3。
+
+```c++
+服务端启动
+./echo_server -task_group_ntags 3 -bthread_concurrency 20 
-bthread_min_concurrency 12 -event_dispatcher_num 2
+
+客户端启动
+./echo_client -dummy_port   -use_bthread true -connection_group="Test1"
+./echo_client -dummy_port   -use_bthread true -connection_group="Test2"
+./echo_client -dummy_port   -use_bthread true -connection_group="Test3"
+```
+
+一般情况应用创建的bthread并需要设置bthread_attr_t的tag字段,创建的bthread会在当前tag上下文中执行,如果希望创建的bthread不在当前tag上下文中执行,可以设置bthread_attr_t的tag字段为希望的值。
+
+# 监控
+
+目前监控上按照tag划分的指标有,线程的数量、线程的使用量、bthread_count、连接信息
+
+线程使用量:![img](../images/bthread_tag_worker_usage.png)
+
+worker线程动态调整,使用该功能需要将bthread_min_concurrency配置成非0。![img](../images/bthread_tag_add_worker.png)
+
+connections:![img](../images/bthread_tag_connections.png)

Review Comment:
   这个图里哪里体现tag了



##
example/bthread_tag_echo_c++/server.cpp:
##
@@ -0,0 +1,99 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// A server to receive EchoRequest and send back EchoResponse.
+
+#include 
+#include 
+#include 
+#include "echo.pb.h"
+
+DEFINE_bool(echo_attachment, true, "Echo attachment as well");
+DEFINE_int32(port, 8002, "TCP Port of this server");
+DEFINE_int32(idle_timeout_s, -1, "Connection will be closed if there is no "
+ "read/write operations during the last `idle_timeout_s'");
+DEFINE_int32(max_concurrency, 0, "Limit of request processing in parallel");
+DEFINE_int32(internal_port, -1, "Only allow builtin services at this port");

Review Comment:
   没有看到bthread tag相关的参数



##
src/bthread/task_control.cpp:
##
@@ -202,8 +247,11 @@ int TaskControl::add_workers(int num) {
 // Worker will add itself to _idle_workers, so we have to add
 // _concurrency before create a worker.
 _concurrency.fetch_add(1);
+auto tag = (_add_workers_with_tag != BTHREAD_TAG_INVALID) ? 
_add_workers_with_tag

Review Comment:
   这个add_workers(int num)的行为应该是为每个tag都增加num个worker?



##
docs/cn/bthread_tagged_task_group.md:
##
@@ -0,0 +1,34 @@
+
+# Bthread tagged task group
+
+在很多应用开发过程中都会有线程资源隔离的需求,比如服务分为控制层和数据层,数据层的请求压力大,不需要控制层受到影响;再比如,服务有多个磁盘,希望磁盘之间没有什么影响资源上的影响等。bthread的任务组打标签就是实现bthread的worker线程池按照tag分组,让不同分组之间达到没有互相影响的目的。客户端需要配合服务端使用,客户端配置channel的connection_group选项将请求分类,这些分类请求将自然的分配到服务端不同的线程池tag分组里面去。
+
+# 使用方式
+
+在example/bthread_tag_echo_c++里面有一个实例代码,分别启动服务端和客户端,服务端将worker划分成3个tag(分组),客户端可以设置不同的connection_group来访问不同的分组,例子里面设置为Test1、Test2、Test3。
+
+```c++
+服务端启动
+./echo_server -task_group_ntags 3 -bthread_concurrency 20 
-bthread_min_concurrency 12 -event_dispatcher_num 2
+
+客户端启动
+./echo_client -dummy_port   -use_bthread true -connection_group="Test1"
+./echo_client -dummy_port   -use_bthread true -connection_group="Test2"
+./echo_client -dummy_port   -use_bthread true -connection_group="Test3"
+```
+
+一般情况应用创建的bthread并需要设置bthread_attr_t的tag字段,创建的bthread会在当前tag上下文中执行,如果希望创建的bthread不在当前tag上下文中执行,可以设置bthread_attr_t的tag字段为希望的值。

Review Comment:
   并需要->不需要



##
docs/cn/bthread_tagged_task_group.md:
##
@@ -0,0 +1,34 @@
+
+# Bthread tagged task group
+
+在很多应用开发过程中都会有线程资源隔离的需求,比如服务分为控制层和数据层,数据层的请求压力大,不需要控制层受到影响;再比如,服务有多个磁盘,希望磁盘之间没有什么影响资源上的影响等。bthread的任务组打标签就是实现bthread的worker线程池按照tag分组,让不同分组之间达到没有互相影响的目的。客户端需要配合服务端使用,客户端配置channel的connection_group选项将请求分类,这些分类请求将自然的分配到服务端不同的线程池tag分组里面去。
+
+# 使用方式
+
+在example/bthread_tag_echo_c++里面有一个实例代码,分别启动服务端和客户端,服务端将worker划分成3个tag(分组),客户端可以设置不同的connection_group来访问不同的分组,例子里面设置为Test1、Test2、Test3。
+
+```c++
+服务端启动
+./echo_server -task_group_ntags 3 -bthread_concurrency 20 
-bthread_min_concurrency 12 -event_dispatcher_num 2
+
+客户端启动

Re: [PR] bthread task group add tag (brpc)

2023-09-11 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1713481049

   这个feature我们也是有强需求,所以我才开发的,我们内部很快也要线上使用。


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-09-11 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1713478018

   > 赞PR,存在共性需求, #2374
   > 
不过这个PR是不是缺少对应的测试代码。另外理论上不同tag的类似bthread_worker_usage在监控上应该拆开?进一步如果做的更完备的话,不同的tag线程池大小应该可以不一样。
   
   
不同tag的bthead_worker_usage是有的,然后tag的线程池也是可以不一样的,我给的使用文档吧。测试代码我得后续补充了,因为这个是改变了很多原有代码,这个测试代码我还没想好怎么去写。


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-09-07 Thread via GitHub


vinllen commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1710994542

   存在共性需求,不过这个PR是不是缺少对应的测试代码。 #2374 


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-08-22 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1687799776

   > 进一步,是不是可以像flare一样支持NUMA架构?
   > https://github.com/Tencent/flare/blob/master/flare/doc/scheduling-group.md
   嗯,如果这个思路大家觉得没问题,可以往这个方向迭代。


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-08-22 Thread via GitHub


chenBright commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1687528133

   进一步,是不是可以像flare一样支持NUMA架构?
   https://github.com/Tencent/flare/blob/master/flare/doc/scheduling-group.md


-- 
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



Re: [PR] bthread task group add tag (brpc)

2023-08-17 Thread via GitHub


yanglimingcn commented on PR #2358:
URL: https://github.com/apache/brpc/pull/2358#issuecomment-1683315828

   这个是划分线程池的一个新的想法,我觉得这样实现对性能损失最少,现在提上来的代码是一个DEMO,总结一下:
   1、在brpc worker层面给worker线程打标签的方式划分了线程池。
   2、使用bthread的时候可以指定tag,就会把bthread调度到相应的worker池子。
   3、只需要给epoll协程打上tag,正常处理请求不需要指定tag,自然就在epoll所在的worker池子上运行。
   
这个改的比较底层,不知道是否社区能接受。另外请求要想在指定的worker池子运行也需要带上标签,我现在想的是给socket打标签,这样请求就不用每个请求打标签了,连接打标签需要建立连接的时候发送一个标识,这块又对客户端、服务端交互有改变。不知道是否有更好的方式。
   @wwbmmm 辛苦有时间看一下,给点建议。
   


-- 
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