dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

ConsistentHashLoadBalance is unavaliable when using generic, because it always hit the same hash cycle

Open kirayunfei opened this issue 8 years ago • 3 comments

protected Invoker doSelect(List<Invoker> invokers, URL url, Invocation invocation) { String key = invokers.get(0).getUrl().getServiceKey() + "." + invocation.getMethodName(); ...... }

由于泛化调用时invocation.getMethodName()值始终为"$invoke",不会根据泛化调用真实信息构建hash环。修复代码可以尝试提交吗?

kirayunfei avatar Dec 26 '17 12:12 kirayunfei

Please pull request

mercyblitz avatar Dec 26 '17 15:12 mercyblitz

给出更详细的问题如下,帮助代码review的同学快速定位问题。

  1. 构建hash环的缓存使用interface+method作为key,泛化调用通过getMethodName()获得方法名始终为"$invoke",相当于混用了hash环。

  2. 使用argumentIndex针对指定参数的下标进行hash结点计算,但是由于泛化场景下,invocation.getArguments()得到的不是真实的参数,因此会导致计算错误,不是预期的hash结果。

  3. identityHashCode通过invoker的hashcode方法直接得到。但是invoker对象计算时会将url内容计算进去,url包含调用时间戳,每次都变,hash环每次都会失效重建。

  4. 虚拟节点hash环持有invoker对象引用,个人认为loadbalance作为一个策略tool,尽量不需持有对整个工作流具有重要意义的invoker。

已经提交了pull request,#1144

kirayunfei avatar Dec 29 '17 10:12 kirayunfei

I leaved some message in the PR #1144, please check.

chickenlj avatar Feb 17 '18 11:02 chickenlj