You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2020/11/12 12:43:55 UTC

[GitHub] [servicecomb-java-chassis] xhanthow opened a new issue #2054: ClientPoolManager#findClientPool(boolean sync, Context targetContext)方法求解

xhanthow opened a new issue #2054:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2054


   ```java
   HttpClientWithContext httpClientWithContext = findHttpClientPool(currentClientMgr, invocation);
   ```
   ```java
       public CLIENT_POOL findClientPool(boolean sync, Context targetContext) {
           if (sync) {
               return findThreadBindClientPool();
           }
   
           // reactive mode
           return findByContext(targetContext);
       }
   ```
   我们用`RestTemplate`调用微服务接口的时候,最终会触发以上代码,然后`invocation`的`sync`默认为`true`,所以最终会执行到`findThreadBindClientPool()`方法,现在就是有点搞不清楚`findThreadBindClientPool()`和`findByContext(targetContext)`的区别,感觉它们都是返回一个`context`呀


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

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



[GitHub] [servicecomb-java-chassis] xhanthow commented on issue #2054: ClientPoolManager#findClientPool(boolean sync, Context targetContext)方法求解

Posted by GitBox <gi...@apache.org>.
xhanthow commented on issue #2054:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2054#issuecomment-726473721


   还是有点难理解。因为我跟源码的时候发现注册中心和配置中心对应的`verticle`调用的都是`findThreadBindClientPool`,然后客户端的`verticle`调用的是`findClientPool`,但是默认还是会调用`findThreadBindClientPool`这个方法,它们是不会绑定特定的`context`?然后`findByContext`会绑定特定的`context`,不知道理解的对不对。


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

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



[GitHub] [servicecomb-java-chassis] wujimin commented on issue #2054: ClientPoolManager#findClientPool(boolean sync, Context targetContext)方法求解

Posted by GitBox <gi...@apache.org>.
wujimin commented on issue #2054:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2054#issuecomment-731765189


   1. 业务代码发起同步调用(绝对不可能在网络线程中),肯定是在一个普通线程中,此时将这个普通线程与某个特定的网络线程建立绑定关系,以后这个普通线程发起的调用,都走这个绑定的网络线程发出去,以降低多个普通线程发起调用时的锁冲突概率  
   2. 业务代码在普通线程中发起异步调用,任意选择一个网络线程将请求发送出去,不建立绑定关系(避免在一个普通线程中发起多个异步调用时,只能使用一个网络线程)   
   3. 业务代码在网线线程中发起异步调用,直接使用本线程将请求发出去


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

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



[GitHub] [servicecomb-java-chassis] xhanthow commented on issue #2054: ClientPoolManager#findClientPool(boolean sync, Context targetContext)方法求解

Posted by GitBox <gi...@apache.org>.
xhanthow commented on issue #2054:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2054#issuecomment-726550447


   它们的主要区别就是是否会绑定特定的`context`?


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

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



[GitHub] [servicecomb-java-chassis] xhanthow commented on issue #2054: ClientPoolManager#findClientPool(boolean sync, Context targetContext)方法求解

Posted by GitBox <gi...@apache.org>.
xhanthow commented on issue #2054:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2054#issuecomment-731894276


   > 1. 业务代码发起同步调用(绝对不可能在网络线程中),肯定是在一个普通线程中,此时将这个普通线程与某个特定的网络线程建立绑定关系,以后这个普通线程发起的调用,都走这个绑定的网络线程发出去,以降低多个普通线程发起调用时的锁冲突概率
   > 2. 业务代码在普通线程中发起异步调用,任意选择一个网络线程将请求发送出去,不建立绑定关系(避免在一个普通线程中发起多个异步调用时,只能使用一个网络线程)
   > 3. 业务代码在网线线程中发起异步调用,直接使用本线程将请求发出去
   
   很清楚的解释!谢谢了。(回复时间亮了


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

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



[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #2054: ClientPoolManager#findClientPool(boolean sync, Context targetContext)方法求解

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #2054:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2054#issuecomment-726450720


   代码头有段注释, 虽然有点难理解,还是能够帮助理解这么写的意图:
   
   ```
   /**
    * CLIENT_POOL是一个完备的连接池,支持向同一个目标建立一个或多个连接
    * 之所以再包装一层,是因为多个线程使用一个连接池的场景下
    * 会导致多个线程抢连接池的同一把锁
    * 包装之后,允许使用m个网络线程,每个线程中有1个连接池
    *
    * support both sync and reactive invoke.
    * 1.sync invoke, bind to a net thread
    * 2.async but not in eventloop, select but not bind to a net thread
    * 3.async and in eventloop, use clientPool in self thread
    *
    * sync/async is not about net operation, just about consumer invoke mode.
    */
   ```


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

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



[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #2054: ClientPoolManager#findClientPool(boolean sync, Context targetContext)方法求解

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #2054:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2054#issuecomment-726544516


   是的。 注册中心、配置中心、客户端其实工作方式是一样的。 不同的在于 edge service 等异步场景, 会走 findByContext


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

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



[GitHub] [servicecomb-java-chassis] xhanthow closed issue #2054: ClientPoolManager#findClientPool(boolean sync, Context targetContext)方法求解

Posted by GitBox <gi...@apache.org>.
xhanthow closed issue #2054:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2054


   


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

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