You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by "Eviltuzki (via GitHub)" <gi...@apache.org> on 2023/04/11 08:19:23 UTC

[I] 多次调用能使server用同一个线程处理么? (brpc)

Eviltuzki opened a new issue, #2203:
URL: https://github.com/apache/brpc/issues/2203

   **Is your feature request related to a problem? (你需要的功能是否与某个问题有关?)**
   是否有办法使得server端处理client请求的时候,始终使用的是同一个线程,也就是调用bthread_self()返回的值保持不变
   
   我这边现在有需求依赖上下文(是另外一个lib提供的),如果不同请求的线程切换了,上下文信息就丢失了,后续请求都会失败
   上下文对我这边调用是黑盒的,无法直接干预,只能通过保障我这边线程不切换
   
   或者是否能指定一个单线程的线程池来提供服务?
   
   
   


-- 
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-unsubscribe@brpc.apache.org.apache.org

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


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


Re: [I] 多次调用能使server用同一个线程处理么? (brpc)

Posted by "TousakaRin (via GitHub)" <gi...@apache.org>.
TousakaRin commented on issue #2203:
URL: https://github.com/apache/brpc/issues/2203#issuecomment-3139081952

   > > > [@wwbmmm](https://github.com/wwbmmm) 想问下,如果 bthread 只调用了阻塞 pthread 的函数(read、write、mutex_lock
   > 当前维护的一个 brpc 老项目用到了 thread_local,如果向下游发起 rpc 会触发当前 bthread 切换 pthread,应该早就出问题了。但看文档和一些 issue 中提到会切换。所以这里不确定:(
   
   可以在rpc前后保存thread id对比一下


-- 
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: issues-unsubscribe@brpc.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@brpc.apache.org
For additional commands, e-mail: issues-help@brpc.apache.org


Re: [I] 多次调用能使server用同一个线程处理么? (brpc)

Posted by "jinshuai86 (via GitHub)" <gi...@apache.org>.
jinshuai86 commented on issue #2203:
URL: https://github.com/apache/brpc/issues/2203#issuecomment-3139005685

   > > [@wwbmmm](https://github.com/wwbmmm) 想问下,如果 bthread 只调用了阻塞 pthread 的函数(read、write、mutex_lock等)或者发起了一次 RPC ,在 bthread 和 pthread 等待期间或者被唤醒后,会触发当前 bthread 切换到其它 pthread 执行吗?
   > 
   > 阻塞的pthread函数不会切换, 发起rpc或者bthread::join等操作可能会触发切换
   
   当前维护的一个 brpc 老项目用到了 thread_local,如果向下游发起 rpc 会触发当前 bthread 切换 pthread,应该早就出问题了。但看文档和一些 issue 中提到会切换。所以这里不确定:(


-- 
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: issues-unsubscribe@brpc.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@brpc.apache.org
For additional commands, e-mail: issues-help@brpc.apache.org


Re: [I] 多次调用能使server用同一个线程处理么? (brpc)

Posted by "ehds (via GitHub)" <gi...@apache.org>.
ehds commented on issue #2203:
URL: https://github.com/apache/brpc/issues/2203#issuecomment-1502936336

   可以尝试开启 `usercode_in_pthread`, 
   > 代码中广泛地使用pthread local传递session级别全局数据,在RPC前后均使用了相同的pthread local的数据,且数据有前后依赖性。比如在RPC前往pthread-local保存了一个值,RPC后又读出来希望和之前保存的相等,就会有问题。而像tcmalloc虽然也使用了pthread/LWP local,但每次使用之间没有直接的依赖,是安全的。
   对于这些情况,brpc提供了pthread模式,开启**-usercode_in_pthread**后,用户代码均会在pthread中运行,原先阻塞bthread的函数转而阻塞pthread。
   
   参考这个文档 https://github.com/apache/brpc/blob/master/docs/cn/server.md#pthread%E6%A8%A1%E5%BC%8F
   
   如果在 server 处理用户请求的代码中,如果没有发生能导致 bthread 阻塞的函数,例如 bthread::usleep、 bthread::bthread_start_urgent 等这些函数,线程是不会发生切换的。


-- 
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-unsubscribe@brpc.apache.org

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


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


Re: [I] 多次调用能使server用同一个线程处理么? (brpc)

Posted by "jinshuai86 (via GitHub)" <gi...@apache.org>.
jinshuai86 commented on issue #2203:
URL: https://github.com/apache/brpc/issues/2203#issuecomment-3138945314

   @wwbmmm 想问下,如果 bthread 只调用了阻塞 pthread 的函数(read、write、mutex_lock等)或者发起了一次 RPC ,在 bthread 和 pthread 等待期间或者被唤醒后,会触发当前 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: issues-unsubscribe@brpc.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@brpc.apache.org
For additional commands, e-mail: issues-help@brpc.apache.org


Re: [I] 多次调用能使server用同一个线程处理么? (brpc)

Posted by "wwbmmm (via GitHub)" <gi...@apache.org>.
wwbmmm commented on issue #2203:
URL: https://github.com/apache/brpc/issues/2203#issuecomment-1511197353

   可以把请求丢到bthread execution_queue去处理


-- 
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-unsubscribe@brpc.apache.org

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


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


Re: [I] 多次调用能使server用同一个线程处理么? (brpc)

Posted by "TousakaRin (via GitHub)" <gi...@apache.org>.
TousakaRin commented on issue #2203:
URL: https://github.com/apache/brpc/issues/2203#issuecomment-3138975419

   > [@wwbmmm](https://github.com/wwbmmm) 想问下,如果 bthread 只调用了阻塞 pthread 的函数(read、write、mutex_lock等)或者发起了一次 RPC ,在 bthread 和 pthread 等待期间或者被唤醒后,会触发当前 bthread 切换到其它 pthread 执行吗?
   
   阻塞的pthread函数不会切换, 发起rpc或者bthread::join等操作可能会触发切换 


-- 
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: issues-unsubscribe@brpc.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@brpc.apache.org
For additional commands, e-mail: issues-help@brpc.apache.org