You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@dubbo.apache.org by Ian Luo <ia...@gmail.com> on 2018/10/24 06:50:12 UTC

pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Hi Jason,

I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
selection) [1] today. It is an awesome implementation and I like it.

There's one particular issue you may need to consider further is I think we
should avoid synchronized block. I have drop review comments on the pull
request. Would you mind to consider this further. After that, I think this
change is ready to go.

Thanks,
-Ian.

1. https://github.com/apache/incubator-dubbo/pull/2647

Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Ian Luo <ia...@gmail.com>.
got it, did not notice this pull request :p
On Thu, Oct 25, 2018 at 10:38 AM Jason Joo <hb...@163.com> wrote:
>
> hi, luo
>
> The patch is in PR #2586 which improves the performance of round robin in versions 2.6.x.
>
> Link is: https://github.com/apache/incubator-dubbo/pull/2586
> Issue: https://github.com/apache/incubator-dubbo/issues/2578
>
> best regards,
>
> Jason
>
> > On Oct 25, 2018, at 10:19, Ian Luo <ia...@gmail.com> wrote:
> >
> > The data seems convincing. What's meaning of 'before patch' and 'after patch'?
> >
> >
> > Thanks,
> > -Ian.
> > On Thu, Oct 25, 2018 at 1:17 AM Jason Joo <hb...@163.com> wrote:
> >>
> >> hi, king
> >>
> >> I think we also care about if it would cause abusing in practices of DUBBO.
> >> The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.
> >>
> >> typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
> >> -------------------
> >> before patch:  8536
> >> after patch:     140
> >> @2.5.3:           141
> >> smooth:           414
> >>
> >> but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
> >> -------------------
> >> before patch:     25002       23939         23435
> >> after patch:        2141         2034           2033
> >> @2.5.3:             1241         1229           1193
> >> smooth:             2081         2231           2376
> >>
> >>
> >> So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.
> >>
> >> Certainly it's a little geek in this case and i will be ok about our future conclusion.
> >>
> >>
> >>
> >> best regards,
> >>
> >> Jason
> >>
> >> On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
> >>
> >> Thanks for a good pr first.
> >> But I think old-way is better useful.
> >> When we need a balance, it means so much invoking occurs, so the most important point is:
> >>
> >> * Lightweight and Performance
> >> Then accuracy and smoothness are not so much prior.
> >> And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
> >> we could not care about its change, check stage is not a key point.
> >>
> >>
> >>
> >> At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
> >>
> >> hi, xiu
> >>
> >> After some deeper research on the algorithm i found it seemed like thread-safe.
> >>
> >> I updated my PR and unit test on it so we can examine if it acts as expected.
> >>
> >> So the recycle logic I change it into an optimistic lock.
> >>
> >> NGINX is a single-process model which lead me to a wrong path.
> >>
> >>
> >>
> >> So it's lock-free and with memory recycler now.
> >>
> >> Let's check if it works correctly.
> >>
> >>
> >> best regards,
> >>
> >> Jason
> >>
> >> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
> >>
> >> Hi, jason
> >>
> >> If we can have a good balance on synchronize, thread and memory, I support
> >> the way of smooth.
> >> We need more discussion and solutions on this issue. Looking forward to
> >> your solutions. :)
> >>
> >> Thx
> >>
> >> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
> >>
> >> hi, xiu
> >>
> >> Good proposal.
> >>
> >> The old not-very-smooth RoundRobin implementation can work fine in most
> >> conditions.
> >> Actually it depends the number of weight.
> >> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
> >> simplify the weights when selecting.
> >>
> >>
> >> And i have another thought about the KEY.
> >> Now the key is defined by Method (which can make method's invocation RR).
> >> If we change it into by Service (which the method will not be RR if its
> >> invocations just match a round) the memory issue may looked better.
> >>
> >>
> >> So what do other guys think about?
> >>
> >>
> >> best regards,
> >>
> >> Jason
> >>
> >> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
> >>
> >> 你好,
> >>
> >> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
> >> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
> >> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
> >>
> >> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
> >>
> >>
> >>
> >> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
> >>
> >>
> >> 谢谢。
> >>
> >> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
> >>
> >> hi, Luo
> >>
> >> Glad to receive your response. I posted a reply before including some
> >> minds about the lock:
> >>
> >> * Separated recycle thread (more threads)
> >>
> >> or
> >>
> >> * Lock free (more memory in special conditions)
> >>
> >> It's truly a struggling job to make a decision and we can do it
> >>
> >> together.
> >>
> >> For the lock-free implementation it will waste or even fail if the
> >> providers are fully dynamic deployed after running enough time(OOM?).
> >>
> >> best regards,
> >>
> >> Jason
> >>
> >> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
> >>
> >> Hi Jason,
> >>
> >> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
> >>
> >> selection) [1] today. It is an awesome implementation and I like it.
> >>
> >>
> >> There's one particular issue you may need to consider further is I
> >>
> >> think
> >>
> >> we should avoid synchronized block. I have drop review comments on the
> >>
> >> pull
> >>
> >> request. Would you mind to consider this further. After that, I think
> >>
> >> this
> >>
> >> change is ready to go.
> >>
> >>
> >> Thanks,
> >> -Ian.
> >>
> >> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
> >>
> >> https://github.com/apache/incubator-dubbo/pull/2647>
> >>
> >>
> >>
> >>
> >>
>

Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Jason Joo <hb...@163.com>.
hi, luo

The patch is in PR #2586 which improves the performance of round robin in versions 2.6.x.

Link is: https://github.com/apache/incubator-dubbo/pull/2586
Issue: https://github.com/apache/incubator-dubbo/issues/2578

best regards,

Jason

> On Oct 25, 2018, at 10:19, Ian Luo <ia...@gmail.com> wrote:
> 
> The data seems convincing. What's meaning of 'before patch' and 'after patch'?
> 
> 
> Thanks,
> -Ian.
> On Thu, Oct 25, 2018 at 1:17 AM Jason Joo <hb...@163.com> wrote:
>> 
>> hi, king
>> 
>> I think we also care about if it would cause abusing in practices of DUBBO.
>> The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.
>> 
>> typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
>> -------------------
>> before patch:  8536
>> after patch:     140
>> @2.5.3:           141
>> smooth:           414
>> 
>> but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
>> -------------------
>> before patch:     25002       23939         23435
>> after patch:        2141         2034           2033
>> @2.5.3:             1241         1229           1193
>> smooth:             2081         2231           2376
>> 
>> 
>> So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.
>> 
>> Certainly it's a little geek in this case and i will be ok about our future conclusion.
>> 
>> 
>> 
>> best regards,
>> 
>> Jason
>> 
>> On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
>> 
>> Thanks for a good pr first.
>> But I think old-way is better useful.
>> When we need a balance, it means so much invoking occurs, so the most important point is:
>> 
>> * Lightweight and Performance
>> Then accuracy and smoothness are not so much prior.
>> And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
>> we could not care about its change, check stage is not a key point.
>> 
>> 
>> 
>> At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
>> 
>> hi, xiu
>> 
>> After some deeper research on the algorithm i found it seemed like thread-safe.
>> 
>> I updated my PR and unit test on it so we can examine if it acts as expected.
>> 
>> So the recycle logic I change it into an optimistic lock.
>> 
>> NGINX is a single-process model which lead me to a wrong path.
>> 
>> 
>> 
>> So it's lock-free and with memory recycler now.
>> 
>> Let's check if it works correctly.
>> 
>> 
>> best regards,
>> 
>> Jason
>> 
>> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
>> 
>> Hi, jason
>> 
>> If we can have a good balance on synchronize, thread and memory, I support
>> the way of smooth.
>> We need more discussion and solutions on this issue. Looking forward to
>> your solutions. :)
>> 
>> Thx
>> 
>> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
>> 
>> hi, xiu
>> 
>> Good proposal.
>> 
>> The old not-very-smooth RoundRobin implementation can work fine in most
>> conditions.
>> Actually it depends the number of weight.
>> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
>> simplify the weights when selecting.
>> 
>> 
>> And i have another thought about the KEY.
>> Now the key is defined by Method (which can make method's invocation RR).
>> If we change it into by Service (which the method will not be RR if its
>> invocations just match a round) the memory issue may looked better.
>> 
>> 
>> So what do other guys think about?
>> 
>> 
>> best regards,
>> 
>> Jason
>> 
>> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
>> 
>> 你好,
>> 
>> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
>> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
>> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
>> 
>> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
>> 
>> 
>> 
>> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
>> 
>> 
>> 谢谢。
>> 
>> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
>> 
>> hi, Luo
>> 
>> Glad to receive your response. I posted a reply before including some
>> minds about the lock:
>> 
>> * Separated recycle thread (more threads)
>> 
>> or
>> 
>> * Lock free (more memory in special conditions)
>> 
>> It's truly a struggling job to make a decision and we can do it
>> 
>> together.
>> 
>> For the lock-free implementation it will waste or even fail if the
>> providers are fully dynamic deployed after running enough time(OOM?).
>> 
>> best regards,
>> 
>> Jason
>> 
>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
>> 
>> Hi Jason,
>> 
>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
>> 
>> selection) [1] today. It is an awesome implementation and I like it.
>> 
>> 
>> There's one particular issue you may need to consider further is I
>> 
>> think
>> 
>> we should avoid synchronized block. I have drop review comments on the
>> 
>> pull
>> 
>> request. Would you mind to consider this further. After that, I think
>> 
>> this
>> 
>> change is ready to go.
>> 
>> 
>> Thanks,
>> -Ian.
>> 
>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
>> 
>> https://github.com/apache/incubator-dubbo/pull/2647>
>> 
>> 
>> 
>> 
>> 


Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Ian Luo <ia...@gmail.com>.
I've merged Jason's pull request. @kimmking, @carryxyh, let me know if
you have different opinion.

-Ian.
On Fri, Oct 26, 2018 at 11:22 AM Ian Luo <ia...@gmail.com> wrote:
>
> sure, let me take a look.
> On Fri, Oct 26, 2018 at 10:57 AM Jason Joo <hb...@163.com> wrote:
> >
> > hi, luo
> >
> > Changes has been applied last night, both in 2.6.x/master
> >
> > best regards,
> >
> > Jason
> >
> > > On Oct 26, 2018, at 10:14, Ian Luo <ia...@gmail.com> wrote:
> > >
> > > Jason,
> > >
> > > The problem is, if we use Map instead of ConcurrentMap, then
> > > weightedRoundRobin could be two different objects when two threads
> > > executes at the same time if they happen to use the same URL.
> > >
> > > String identifyString = invoker.getUrl().toIdentityString();
> > > WeightedRoundRobin weightedRoundRobin = map.get(identifyString);
> > > int weight = getWeight(invoker, invocation);
> > > if (weight < 0) {
> > >    weight = 0;
> > > }
> > > if (weightedRoundRobin == null) {
> > >    weightedRoundRobin = new WeightedRoundRobin();
> > >    weightedRoundRobin.setWeight(weight);
> > >    map.putIfAbsent(identifyString, weightedRoundRobin);
> > >    weightedRoundRobin = map.get(identifyString);
> > > }
> > >
> > >
> > > Thanks,
> > > -Ian.
> > > On Thu, Oct 25, 2018 at 8:27 PM Jason Joo <hb...@163.com> wrote:
> > >>
> > >> hi, Luo
> > >>
> > >> Due to a loop on MAP object each time selecting the performance will reduce by 9.3% in single thread test.
> > >>
> > >> Does it worth it?
> > >>
> > >> Under 5, 10, 20 threads the difference is not stable: 8~13% loss
> > >>
> > >> What do you think?
> > >>
> > >> best regards,
> > >>
> > >> Jason
> > >>
> > >>> On Oct 25, 2018, at 19:42, Ian Luo <ia...@gmail.com> wrote:
> > >>>
> > >>> Jason,
> > >>>
> > >>> what I suggest is to simply declare methodWeightMap from
> > >>> ConcurrentMap<String, Map<String, WeightedRoundRobin>> to
> > >>> ConcurrentMap<String, ConcurrentMap<String, WeightedRoundRobin>>, then
> > >>> you will have 'putIfAbsent', what do you think?
> > >>>
> > >>> Thanks,
> > >>> -Ian.
> > >>>
> > >>> On Thu, Oct 25, 2018 at 3:47 PM Jason Joo <hb...@163.com> wrote:
> > >>>>
> > >>>> hi, luo
> > >>>>
> > >>>> Just replace putIfAbsent with put for compatibility and tested in racing condition.
> > >>>>
> > >>>> best regards,
> > >>>>
> > >>>> Jason
> > >>>>
> > >>>>> On Oct 25, 2018, at 11:33, Ian Luo <ia...@gmail.com> wrote:
> > >>>>>
> > >>>>> great.
> > >>>>> On Thu, Oct 25, 2018 at 11:33 AM Jason Joo <hb...@163.com> wrote:
> > >>>>>>
> > >>>>>> hi, Luo
> > >>>>>>
> > >>>>>> I am switching branch and ide hangs.....I am figuring it
> > >>>>>>
> > >>>>>> best regards,
> > >>>>>>
> > >>>>>> Jason
> > >>>>>>
> > >>>>>>> On Oct 25, 2018, at 11:28, Ian Luo <ia...@gmail.com> wrote:
> > >>>>>>>
> > >>>>>>> Jason,
> > >>>>>>>
> > >>>>>>> Last comment on 'putIfAbsent', pls. take a look.
> > >>>>>>>
> > >>>>>>> Thanks,
> > >>>>>>> -Ian.
> > >>>>>>>
> > >>>>>>> On Thu, Oct 25, 2018 at 11:02 AM Ian Luo <ia...@gmail.com> wrote:
> > >>>>>>>>
> > >>>>>>>> Jason,
> > >>>>>>>>
> > >>>>>>>> More comments, pls. take a look :)
> > >>>>>>>>
> > >>>>>>>> Thanks,
> > >>>>>>>> -Ian.
> > >>>>>>>> On Thu, Oct 25, 2018 at 10:50 AM Jason Joo <hb...@163.com> wrote:
> > >>>>>>>>>
> > >>>>>>>>> hi, Luo
> > >>>>>>>>>
> > >>>>>>>>> Thanks for your great suggestions and PR has been updated.
> > >>>>>>>>>
> > >>>>>>>>> We need more work testing and reviewing to prevent poor performance and so on mentioned in #2578.
> > >>>>>>>>>
> > >>>>>>>>> best regards,
> > >>>>>>>>>
> > >>>>>>>>> Jason
> > >>>>>>>>>
> > >>>>>>>>>> On Oct 25, 2018, at 10:35, Ian Luo <ia...@gmail.com> wrote:
> > >>>>>>>>>>
> > >>>>>>>>>> Jason,
> > >>>>>>>>>>
> > >>>>>>>>>> I take a look at the updated pull request, and give a few suggestions.
> > >>>>>>>>>> I think it's on the right direction, pls. take a look.
> > >>>>>>>>>>
> > >>>>>>>>>> Thanks,
> > >>>>>>>>>> -Ian.
> > >>>>>>>>>> On Thu, Oct 25, 2018 at 10:19 AM Ian Luo <ia...@gmail.com> wrote:
> > >>>>>>>>>>>
> > >>>>>>>>>>> The data seems convincing. What's meaning of 'before patch' and 'after patch'?
> > >>>>>>>>>>>
> > >>>>>>>>>>>
> > >>>>>>>>>>> Thanks,
> > >>>>>>>>>>> -Ian.
> > >>>>>>>>>>> On Thu, Oct 25, 2018 at 1:17 AM Jason Joo <hb...@163.com> wrote:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> hi, king
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> I think we also care about if it would cause abusing in practices of DUBBO.
> > >>>>>>>>>>>> The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
> > >>>>>>>>>>>> -------------------
> > >>>>>>>>>>>> before patch:  8536
> > >>>>>>>>>>>> after patch:     140
> > >>>>>>>>>>>> @2.5.3:           141
> > >>>>>>>>>>>> smooth:           414
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
> > >>>>>>>>>>>> -------------------
> > >>>>>>>>>>>> before patch:     25002       23939         23435
> > >>>>>>>>>>>> after patch:        2141         2034           2033
> > >>>>>>>>>>>> @2.5.3:             1241         1229           1193
> > >>>>>>>>>>>> smooth:             2081         2231           2376
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Certainly it's a little geek in this case and i will be ok about our future conclusion.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> best regards,
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Jason
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Thanks for a good pr first.
> > >>>>>>>>>>>> But I think old-way is better useful.
> > >>>>>>>>>>>> When we need a balance, it means so much invoking occurs, so the most important point is:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> * Lightweight and Performance
> > >>>>>>>>>>>> Then accuracy and smoothness are not so much prior.
> > >>>>>>>>>>>> And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
> > >>>>>>>>>>>> we could not care about its change, check stage is not a key point.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> hi, xiu
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> After some deeper research on the algorithm i found it seemed like thread-safe.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> I updated my PR and unit test on it so we can examine if it acts as expected.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> So the recycle logic I change it into an optimistic lock.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> NGINX is a single-process model which lead me to a wrong path.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> So it's lock-free and with memory recycler now.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Let's check if it works correctly.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> best regards,
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Jason
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Hi, jason
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> If we can have a good balance on synchronize, thread and memory, I support
> > >>>>>>>>>>>> the way of smooth.
> > >>>>>>>>>>>> We need more discussion and solutions on this issue. Looking forward to
> > >>>>>>>>>>>> your solutions. :)
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Thx
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> hi, xiu
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Good proposal.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> The old not-very-smooth RoundRobin implementation can work fine in most
> > >>>>>>>>>>>> conditions.
> > >>>>>>>>>>>> Actually it depends the number of weight.
> > >>>>>>>>>>>> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
> > >>>>>>>>>>>> simplify the weights when selecting.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> And i have another thought about the KEY.
> > >>>>>>>>>>>> Now the key is defined by Method (which can make method's invocation RR).
> > >>>>>>>>>>>> If we change it into by Service (which the method will not be RR if its
> > >>>>>>>>>>>> invocations just match a round) the memory issue may looked better.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> So what do other guys think about?
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> best regards,
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Jason
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> 你好,
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
> > >>>>>>>>>>>> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
> > >>>>>>>>>>>> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> 谢谢。
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> hi, Luo
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Glad to receive your response. I posted a reply before including some
> > >>>>>>>>>>>> minds about the lock:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> * Separated recycle thread (more threads)
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> or
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> * Lock free (more memory in special conditions)
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> It's truly a struggling job to make a decision and we can do it
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> together.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> For the lock-free implementation it will waste or even fail if the
> > >>>>>>>>>>>> providers are fully dynamic deployed after running enough time(OOM?).
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> best regards,
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Jason
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Hi Jason,
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> selection) [1] today. It is an awesome implementation and I like it.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> There's one particular issue you may need to consider further is I
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> think
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> we should avoid synchronized block. I have drop review comments on the
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> pull
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> request. Would you mind to consider this further. After that, I think
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> this
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> change is ready to go.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Thanks,
> > >>>>>>>>>>>> -Ian.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> https://github.com/apache/incubator-dubbo/pull/2647>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>
> > >>>>>>
> > >>>>
> > >>
> >

Re:Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by 秦金卫 <ki...@163.com>.
Base on our previous discussion, no author info in java codes.
Jason, plz submit a PR to remove author info:


> *@authorjason

At 2018-10-26 13:28:18, "Ian Luo" <ia...@gmail.com> wrote:
>I see. I have already merged your pull request on both 2.6.x and
>master. Thanks for your excellent work, and consider contributing more
>in the future :)
>
>Thanks,
>-Ian.
>On Fri, Oct 26, 2018 at 11:39 AM Jason Joo <hb...@163.com> wrote:
>>
>> hi, Luo
>>
>> Implementation of 2.5.3 is indeed fast but it's not correct. Here is example running report:
>>
>> Weights array:
>> 100, 100, 200, 200, 300, 300, 400, 400, 500, 500
>>
>> 2.5.3:
>> 20000, 20000, 45000, 45000, 78333, 78333, 128333, 128333, 228334, 228334
>>
>> before patch:
>> 33400, 33400, 66700, 66700, 100000, 100000, 133300, 133300, 166600, 166600
>>
>> after patch:
>> 33399, 33399, 66701, 66701, 100000, 100000, 133300, 133300, 166600, 166600
>>
>> smooth one:
>> 33333, 33333, 66667, 66667, 100000, 100000, 133333, 133333, 166667, 166667
>>
>>
>> And the smooth version is a strict implementation to see how many invocation should really happen.
>>
>> best regards,
>>
>> Jason
>>
>> > On Oct 26, 2018, at 11:28, Ian Luo <ia...@gmail.com> wrote:
>> >
>> > one
>>

Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Ian Luo <ia...@gmail.com>.
I see. I have already merged your pull request on both 2.6.x and
master. Thanks for your excellent work, and consider contributing more
in the future :)

Thanks,
-Ian.
On Fri, Oct 26, 2018 at 11:39 AM Jason Joo <hb...@163.com> wrote:
>
> hi, Luo
>
> Implementation of 2.5.3 is indeed fast but it's not correct. Here is example running report:
>
> Weights array:
> 100, 100, 200, 200, 300, 300, 400, 400, 500, 500
>
> 2.5.3:
> 20000, 20000, 45000, 45000, 78333, 78333, 128333, 128333, 228334, 228334
>
> before patch:
> 33400, 33400, 66700, 66700, 100000, 100000, 133300, 133300, 166600, 166600
>
> after patch:
> 33399, 33399, 66701, 66701, 100000, 100000, 133300, 133300, 166600, 166600
>
> smooth one:
> 33333, 33333, 66667, 66667, 100000, 100000, 133333, 133333, 166667, 166667
>
>
> And the smooth version is a strict implementation to see how many invocation should really happen.
>
> best regards,
>
> Jason
>
> > On Oct 26, 2018, at 11:28, Ian Luo <ia...@gmail.com> wrote:
> >
> > one
>

Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Jason Joo <hb...@163.com>.
hi, Luo

Implementation of 2.5.3 is indeed fast but it's not correct. Here is example running report:

Weights array: 
100, 100, 200, 200, 300, 300, 400, 400, 500, 500

2.5.3:
20000, 20000, 45000, 45000, 78333, 78333, 128333, 128333, 228334, 228334

before patch:
33400, 33400, 66700, 66700, 100000, 100000, 133300, 133300, 166600, 166600

after patch:
33399, 33399, 66701, 66701, 100000, 100000, 133300, 133300, 166600, 166600

smooth one:
33333, 33333, 66667, 66667, 100000, 100000, 133333, 133333, 166667, 166667


And the smooth version is a strict implementation to see how many invocation should really happen.

best regards,

Jason

> On Oct 26, 2018, at 11:28, Ian Luo <ia...@gmail.com> wrote:
> 
> one


Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Ian Luo <ia...@gmail.com>.
I took a brief look and I think the current change is ready to go.

Two relevant questions:
1. why RR run much faster on 2.5.x, does anyone have insight on this?
2. Should we give this RR strategy a new name, so that it's possible
to keep the original one?

Thanks,
-Ian.

On Fri, Oct 26, 2018 at 11:22 AM Ian Luo <ia...@gmail.com> wrote:
>
> sure, let me take a look.
> On Fri, Oct 26, 2018 at 10:57 AM Jason Joo <hb...@163.com> wrote:
> >
> > hi, luo
> >
> > Changes has been applied last night, both in 2.6.x/master
> >
> > best regards,
> >
> > Jason
> >
> > > On Oct 26, 2018, at 10:14, Ian Luo <ia...@gmail.com> wrote:
> > >
> > > Jason,
> > >
> > > The problem is, if we use Map instead of ConcurrentMap, then
> > > weightedRoundRobin could be two different objects when two threads
> > > executes at the same time if they happen to use the same URL.
> > >
> > > String identifyString = invoker.getUrl().toIdentityString();
> > > WeightedRoundRobin weightedRoundRobin = map.get(identifyString);
> > > int weight = getWeight(invoker, invocation);
> > > if (weight < 0) {
> > >    weight = 0;
> > > }
> > > if (weightedRoundRobin == null) {
> > >    weightedRoundRobin = new WeightedRoundRobin();
> > >    weightedRoundRobin.setWeight(weight);
> > >    map.putIfAbsent(identifyString, weightedRoundRobin);
> > >    weightedRoundRobin = map.get(identifyString);
> > > }
> > >
> > >
> > > Thanks,
> > > -Ian.
> > > On Thu, Oct 25, 2018 at 8:27 PM Jason Joo <hb...@163.com> wrote:
> > >>
> > >> hi, Luo
> > >>
> > >> Due to a loop on MAP object each time selecting the performance will reduce by 9.3% in single thread test.
> > >>
> > >> Does it worth it?
> > >>
> > >> Under 5, 10, 20 threads the difference is not stable: 8~13% loss
> > >>
> > >> What do you think?
> > >>
> > >> best regards,
> > >>
> > >> Jason
> > >>
> > >>> On Oct 25, 2018, at 19:42, Ian Luo <ia...@gmail.com> wrote:
> > >>>
> > >>> Jason,
> > >>>
> > >>> what I suggest is to simply declare methodWeightMap from
> > >>> ConcurrentMap<String, Map<String, WeightedRoundRobin>> to
> > >>> ConcurrentMap<String, ConcurrentMap<String, WeightedRoundRobin>>, then
> > >>> you will have 'putIfAbsent', what do you think?
> > >>>
> > >>> Thanks,
> > >>> -Ian.
> > >>>
> > >>> On Thu, Oct 25, 2018 at 3:47 PM Jason Joo <hb...@163.com> wrote:
> > >>>>
> > >>>> hi, luo
> > >>>>
> > >>>> Just replace putIfAbsent with put for compatibility and tested in racing condition.
> > >>>>
> > >>>> best regards,
> > >>>>
> > >>>> Jason
> > >>>>
> > >>>>> On Oct 25, 2018, at 11:33, Ian Luo <ia...@gmail.com> wrote:
> > >>>>>
> > >>>>> great.
> > >>>>> On Thu, Oct 25, 2018 at 11:33 AM Jason Joo <hb...@163.com> wrote:
> > >>>>>>
> > >>>>>> hi, Luo
> > >>>>>>
> > >>>>>> I am switching branch and ide hangs.....I am figuring it
> > >>>>>>
> > >>>>>> best regards,
> > >>>>>>
> > >>>>>> Jason
> > >>>>>>
> > >>>>>>> On Oct 25, 2018, at 11:28, Ian Luo <ia...@gmail.com> wrote:
> > >>>>>>>
> > >>>>>>> Jason,
> > >>>>>>>
> > >>>>>>> Last comment on 'putIfAbsent', pls. take a look.
> > >>>>>>>
> > >>>>>>> Thanks,
> > >>>>>>> -Ian.
> > >>>>>>>
> > >>>>>>> On Thu, Oct 25, 2018 at 11:02 AM Ian Luo <ia...@gmail.com> wrote:
> > >>>>>>>>
> > >>>>>>>> Jason,
> > >>>>>>>>
> > >>>>>>>> More comments, pls. take a look :)
> > >>>>>>>>
> > >>>>>>>> Thanks,
> > >>>>>>>> -Ian.
> > >>>>>>>> On Thu, Oct 25, 2018 at 10:50 AM Jason Joo <hb...@163.com> wrote:
> > >>>>>>>>>
> > >>>>>>>>> hi, Luo
> > >>>>>>>>>
> > >>>>>>>>> Thanks for your great suggestions and PR has been updated.
> > >>>>>>>>>
> > >>>>>>>>> We need more work testing and reviewing to prevent poor performance and so on mentioned in #2578.
> > >>>>>>>>>
> > >>>>>>>>> best regards,
> > >>>>>>>>>
> > >>>>>>>>> Jason
> > >>>>>>>>>
> > >>>>>>>>>> On Oct 25, 2018, at 10:35, Ian Luo <ia...@gmail.com> wrote:
> > >>>>>>>>>>
> > >>>>>>>>>> Jason,
> > >>>>>>>>>>
> > >>>>>>>>>> I take a look at the updated pull request, and give a few suggestions.
> > >>>>>>>>>> I think it's on the right direction, pls. take a look.
> > >>>>>>>>>>
> > >>>>>>>>>> Thanks,
> > >>>>>>>>>> -Ian.
> > >>>>>>>>>> On Thu, Oct 25, 2018 at 10:19 AM Ian Luo <ia...@gmail.com> wrote:
> > >>>>>>>>>>>
> > >>>>>>>>>>> The data seems convincing. What's meaning of 'before patch' and 'after patch'?
> > >>>>>>>>>>>
> > >>>>>>>>>>>
> > >>>>>>>>>>> Thanks,
> > >>>>>>>>>>> -Ian.
> > >>>>>>>>>>> On Thu, Oct 25, 2018 at 1:17 AM Jason Joo <hb...@163.com> wrote:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> hi, king
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> I think we also care about if it would cause abusing in practices of DUBBO.
> > >>>>>>>>>>>> The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
> > >>>>>>>>>>>> -------------------
> > >>>>>>>>>>>> before patch:  8536
> > >>>>>>>>>>>> after patch:     140
> > >>>>>>>>>>>> @2.5.3:           141
> > >>>>>>>>>>>> smooth:           414
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
> > >>>>>>>>>>>> -------------------
> > >>>>>>>>>>>> before patch:     25002       23939         23435
> > >>>>>>>>>>>> after patch:        2141         2034           2033
> > >>>>>>>>>>>> @2.5.3:             1241         1229           1193
> > >>>>>>>>>>>> smooth:             2081         2231           2376
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Certainly it's a little geek in this case and i will be ok about our future conclusion.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> best regards,
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Jason
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Thanks for a good pr first.
> > >>>>>>>>>>>> But I think old-way is better useful.
> > >>>>>>>>>>>> When we need a balance, it means so much invoking occurs, so the most important point is:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> * Lightweight and Performance
> > >>>>>>>>>>>> Then accuracy and smoothness are not so much prior.
> > >>>>>>>>>>>> And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
> > >>>>>>>>>>>> we could not care about its change, check stage is not a key point.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> hi, xiu
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> After some deeper research on the algorithm i found it seemed like thread-safe.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> I updated my PR and unit test on it so we can examine if it acts as expected.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> So the recycle logic I change it into an optimistic lock.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> NGINX is a single-process model which lead me to a wrong path.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> So it's lock-free and with memory recycler now.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Let's check if it works correctly.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> best regards,
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Jason
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Hi, jason
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> If we can have a good balance on synchronize, thread and memory, I support
> > >>>>>>>>>>>> the way of smooth.
> > >>>>>>>>>>>> We need more discussion and solutions on this issue. Looking forward to
> > >>>>>>>>>>>> your solutions. :)
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Thx
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> hi, xiu
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Good proposal.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> The old not-very-smooth RoundRobin implementation can work fine in most
> > >>>>>>>>>>>> conditions.
> > >>>>>>>>>>>> Actually it depends the number of weight.
> > >>>>>>>>>>>> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
> > >>>>>>>>>>>> simplify the weights when selecting.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> And i have another thought about the KEY.
> > >>>>>>>>>>>> Now the key is defined by Method (which can make method's invocation RR).
> > >>>>>>>>>>>> If we change it into by Service (which the method will not be RR if its
> > >>>>>>>>>>>> invocations just match a round) the memory issue may looked better.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> So what do other guys think about?
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> best regards,
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Jason
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> 你好,
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
> > >>>>>>>>>>>> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
> > >>>>>>>>>>>> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> 谢谢。
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> hi, Luo
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Glad to receive your response. I posted a reply before including some
> > >>>>>>>>>>>> minds about the lock:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> * Separated recycle thread (more threads)
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> or
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> * Lock free (more memory in special conditions)
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> It's truly a struggling job to make a decision and we can do it
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> together.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> For the lock-free implementation it will waste or even fail if the
> > >>>>>>>>>>>> providers are fully dynamic deployed after running enough time(OOM?).
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> best regards,
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Jason
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Hi Jason,
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> selection) [1] today. It is an awesome implementation and I like it.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> There's one particular issue you may need to consider further is I
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> think
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> we should avoid synchronized block. I have drop review comments on the
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> pull
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> request. Would you mind to consider this further. After that, I think
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> this
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> change is ready to go.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Thanks,
> > >>>>>>>>>>>> -Ian.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> https://github.com/apache/incubator-dubbo/pull/2647>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>
> > >>>>>>
> > >>>>
> > >>
> >

Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Ian Luo <ia...@gmail.com>.
sure, let me take a look.
On Fri, Oct 26, 2018 at 10:57 AM Jason Joo <hb...@163.com> wrote:
>
> hi, luo
>
> Changes has been applied last night, both in 2.6.x/master
>
> best regards,
>
> Jason
>
> > On Oct 26, 2018, at 10:14, Ian Luo <ia...@gmail.com> wrote:
> >
> > Jason,
> >
> > The problem is, if we use Map instead of ConcurrentMap, then
> > weightedRoundRobin could be two different objects when two threads
> > executes at the same time if they happen to use the same URL.
> >
> > String identifyString = invoker.getUrl().toIdentityString();
> > WeightedRoundRobin weightedRoundRobin = map.get(identifyString);
> > int weight = getWeight(invoker, invocation);
> > if (weight < 0) {
> >    weight = 0;
> > }
> > if (weightedRoundRobin == null) {
> >    weightedRoundRobin = new WeightedRoundRobin();
> >    weightedRoundRobin.setWeight(weight);
> >    map.putIfAbsent(identifyString, weightedRoundRobin);
> >    weightedRoundRobin = map.get(identifyString);
> > }
> >
> >
> > Thanks,
> > -Ian.
> > On Thu, Oct 25, 2018 at 8:27 PM Jason Joo <hb...@163.com> wrote:
> >>
> >> hi, Luo
> >>
> >> Due to a loop on MAP object each time selecting the performance will reduce by 9.3% in single thread test.
> >>
> >> Does it worth it?
> >>
> >> Under 5, 10, 20 threads the difference is not stable: 8~13% loss
> >>
> >> What do you think?
> >>
> >> best regards,
> >>
> >> Jason
> >>
> >>> On Oct 25, 2018, at 19:42, Ian Luo <ia...@gmail.com> wrote:
> >>>
> >>> Jason,
> >>>
> >>> what I suggest is to simply declare methodWeightMap from
> >>> ConcurrentMap<String, Map<String, WeightedRoundRobin>> to
> >>> ConcurrentMap<String, ConcurrentMap<String, WeightedRoundRobin>>, then
> >>> you will have 'putIfAbsent', what do you think?
> >>>
> >>> Thanks,
> >>> -Ian.
> >>>
> >>> On Thu, Oct 25, 2018 at 3:47 PM Jason Joo <hb...@163.com> wrote:
> >>>>
> >>>> hi, luo
> >>>>
> >>>> Just replace putIfAbsent with put for compatibility and tested in racing condition.
> >>>>
> >>>> best regards,
> >>>>
> >>>> Jason
> >>>>
> >>>>> On Oct 25, 2018, at 11:33, Ian Luo <ia...@gmail.com> wrote:
> >>>>>
> >>>>> great.
> >>>>> On Thu, Oct 25, 2018 at 11:33 AM Jason Joo <hb...@163.com> wrote:
> >>>>>>
> >>>>>> hi, Luo
> >>>>>>
> >>>>>> I am switching branch and ide hangs.....I am figuring it
> >>>>>>
> >>>>>> best regards,
> >>>>>>
> >>>>>> Jason
> >>>>>>
> >>>>>>> On Oct 25, 2018, at 11:28, Ian Luo <ia...@gmail.com> wrote:
> >>>>>>>
> >>>>>>> Jason,
> >>>>>>>
> >>>>>>> Last comment on 'putIfAbsent', pls. take a look.
> >>>>>>>
> >>>>>>> Thanks,
> >>>>>>> -Ian.
> >>>>>>>
> >>>>>>> On Thu, Oct 25, 2018 at 11:02 AM Ian Luo <ia...@gmail.com> wrote:
> >>>>>>>>
> >>>>>>>> Jason,
> >>>>>>>>
> >>>>>>>> More comments, pls. take a look :)
> >>>>>>>>
> >>>>>>>> Thanks,
> >>>>>>>> -Ian.
> >>>>>>>> On Thu, Oct 25, 2018 at 10:50 AM Jason Joo <hb...@163.com> wrote:
> >>>>>>>>>
> >>>>>>>>> hi, Luo
> >>>>>>>>>
> >>>>>>>>> Thanks for your great suggestions and PR has been updated.
> >>>>>>>>>
> >>>>>>>>> We need more work testing and reviewing to prevent poor performance and so on mentioned in #2578.
> >>>>>>>>>
> >>>>>>>>> best regards,
> >>>>>>>>>
> >>>>>>>>> Jason
> >>>>>>>>>
> >>>>>>>>>> On Oct 25, 2018, at 10:35, Ian Luo <ia...@gmail.com> wrote:
> >>>>>>>>>>
> >>>>>>>>>> Jason,
> >>>>>>>>>>
> >>>>>>>>>> I take a look at the updated pull request, and give a few suggestions.
> >>>>>>>>>> I think it's on the right direction, pls. take a look.
> >>>>>>>>>>
> >>>>>>>>>> Thanks,
> >>>>>>>>>> -Ian.
> >>>>>>>>>> On Thu, Oct 25, 2018 at 10:19 AM Ian Luo <ia...@gmail.com> wrote:
> >>>>>>>>>>>
> >>>>>>>>>>> The data seems convincing. What's meaning of 'before patch' and 'after patch'?
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>> Thanks,
> >>>>>>>>>>> -Ian.
> >>>>>>>>>>> On Thu, Oct 25, 2018 at 1:17 AM Jason Joo <hb...@163.com> wrote:
> >>>>>>>>>>>>
> >>>>>>>>>>>> hi, king
> >>>>>>>>>>>>
> >>>>>>>>>>>> I think we also care about if it would cause abusing in practices of DUBBO.
> >>>>>>>>>>>> The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.
> >>>>>>>>>>>>
> >>>>>>>>>>>> typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
> >>>>>>>>>>>> -------------------
> >>>>>>>>>>>> before patch:  8536
> >>>>>>>>>>>> after patch:     140
> >>>>>>>>>>>> @2.5.3:           141
> >>>>>>>>>>>> smooth:           414
> >>>>>>>>>>>>
> >>>>>>>>>>>> but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
> >>>>>>>>>>>> -------------------
> >>>>>>>>>>>> before patch:     25002       23939         23435
> >>>>>>>>>>>> after patch:        2141         2034           2033
> >>>>>>>>>>>> @2.5.3:             1241         1229           1193
> >>>>>>>>>>>> smooth:             2081         2231           2376
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.
> >>>>>>>>>>>>
> >>>>>>>>>>>> Certainly it's a little geek in this case and i will be ok about our future conclusion.
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> best regards,
> >>>>>>>>>>>>
> >>>>>>>>>>>> Jason
> >>>>>>>>>>>>
> >>>>>>>>>>>> On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
> >>>>>>>>>>>>
> >>>>>>>>>>>> Thanks for a good pr first.
> >>>>>>>>>>>> But I think old-way is better useful.
> >>>>>>>>>>>> When we need a balance, it means so much invoking occurs, so the most important point is:
> >>>>>>>>>>>>
> >>>>>>>>>>>> * Lightweight and Performance
> >>>>>>>>>>>> Then accuracy and smoothness are not so much prior.
> >>>>>>>>>>>> And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
> >>>>>>>>>>>> we could not care about its change, check stage is not a key point.
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
> >>>>>>>>>>>>
> >>>>>>>>>>>> hi, xiu
> >>>>>>>>>>>>
> >>>>>>>>>>>> After some deeper research on the algorithm i found it seemed like thread-safe.
> >>>>>>>>>>>>
> >>>>>>>>>>>> I updated my PR and unit test on it so we can examine if it acts as expected.
> >>>>>>>>>>>>
> >>>>>>>>>>>> So the recycle logic I change it into an optimistic lock.
> >>>>>>>>>>>>
> >>>>>>>>>>>> NGINX is a single-process model which lead me to a wrong path.
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> So it's lock-free and with memory recycler now.
> >>>>>>>>>>>>
> >>>>>>>>>>>> Let's check if it works correctly.
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> best regards,
> >>>>>>>>>>>>
> >>>>>>>>>>>> Jason
> >>>>>>>>>>>>
> >>>>>>>>>>>> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
> >>>>>>>>>>>>
> >>>>>>>>>>>> Hi, jason
> >>>>>>>>>>>>
> >>>>>>>>>>>> If we can have a good balance on synchronize, thread and memory, I support
> >>>>>>>>>>>> the way of smooth.
> >>>>>>>>>>>> We need more discussion and solutions on this issue. Looking forward to
> >>>>>>>>>>>> your solutions. :)
> >>>>>>>>>>>>
> >>>>>>>>>>>> Thx
> >>>>>>>>>>>>
> >>>>>>>>>>>> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
> >>>>>>>>>>>>
> >>>>>>>>>>>> hi, xiu
> >>>>>>>>>>>>
> >>>>>>>>>>>> Good proposal.
> >>>>>>>>>>>>
> >>>>>>>>>>>> The old not-very-smooth RoundRobin implementation can work fine in most
> >>>>>>>>>>>> conditions.
> >>>>>>>>>>>> Actually it depends the number of weight.
> >>>>>>>>>>>> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
> >>>>>>>>>>>> simplify the weights when selecting.
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> And i have another thought about the KEY.
> >>>>>>>>>>>> Now the key is defined by Method (which can make method's invocation RR).
> >>>>>>>>>>>> If we change it into by Service (which the method will not be RR if its
> >>>>>>>>>>>> invocations just match a round) the memory issue may looked better.
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> So what do other guys think about?
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> best regards,
> >>>>>>>>>>>>
> >>>>>>>>>>>> Jason
> >>>>>>>>>>>>
> >>>>>>>>>>>> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
> >>>>>>>>>>>>
> >>>>>>>>>>>> 你好,
> >>>>>>>>>>>>
> >>>>>>>>>>>> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
> >>>>>>>>>>>> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
> >>>>>>>>>>>> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
> >>>>>>>>>>>>
> >>>>>>>>>>>> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> 谢谢。
> >>>>>>>>>>>>
> >>>>>>>>>>>> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
> >>>>>>>>>>>>
> >>>>>>>>>>>> hi, Luo
> >>>>>>>>>>>>
> >>>>>>>>>>>> Glad to receive your response. I posted a reply before including some
> >>>>>>>>>>>> minds about the lock:
> >>>>>>>>>>>>
> >>>>>>>>>>>> * Separated recycle thread (more threads)
> >>>>>>>>>>>>
> >>>>>>>>>>>> or
> >>>>>>>>>>>>
> >>>>>>>>>>>> * Lock free (more memory in special conditions)
> >>>>>>>>>>>>
> >>>>>>>>>>>> It's truly a struggling job to make a decision and we can do it
> >>>>>>>>>>>>
> >>>>>>>>>>>> together.
> >>>>>>>>>>>>
> >>>>>>>>>>>> For the lock-free implementation it will waste or even fail if the
> >>>>>>>>>>>> providers are fully dynamic deployed after running enough time(OOM?).
> >>>>>>>>>>>>
> >>>>>>>>>>>> best regards,
> >>>>>>>>>>>>
> >>>>>>>>>>>> Jason
> >>>>>>>>>>>>
> >>>>>>>>>>>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
> >>>>>>>>>>>>
> >>>>>>>>>>>> Hi Jason,
> >>>>>>>>>>>>
> >>>>>>>>>>>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
> >>>>>>>>>>>>
> >>>>>>>>>>>> selection) [1] today. It is an awesome implementation and I like it.
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> There's one particular issue you may need to consider further is I
> >>>>>>>>>>>>
> >>>>>>>>>>>> think
> >>>>>>>>>>>>
> >>>>>>>>>>>> we should avoid synchronized block. I have drop review comments on the
> >>>>>>>>>>>>
> >>>>>>>>>>>> pull
> >>>>>>>>>>>>
> >>>>>>>>>>>> request. Would you mind to consider this further. After that, I think
> >>>>>>>>>>>>
> >>>>>>>>>>>> this
> >>>>>>>>>>>>
> >>>>>>>>>>>> change is ready to go.
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> Thanks,
> >>>>>>>>>>>> -Ian.
> >>>>>>>>>>>>
> >>>>>>>>>>>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
> >>>>>>>>>>>>
> >>>>>>>>>>>> https://github.com/apache/incubator-dubbo/pull/2647>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>
> >>>>>>
> >>>>
> >>
>

Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Jason Joo <hb...@163.com>.
hi, luo

Changes has been applied last night, both in 2.6.x/master

best regards,

Jason

> On Oct 26, 2018, at 10:14, Ian Luo <ia...@gmail.com> wrote:
> 
> Jason,
> 
> The problem is, if we use Map instead of ConcurrentMap, then
> weightedRoundRobin could be two different objects when two threads
> executes at the same time if they happen to use the same URL.
> 
> String identifyString = invoker.getUrl().toIdentityString();
> WeightedRoundRobin weightedRoundRobin = map.get(identifyString);
> int weight = getWeight(invoker, invocation);
> if (weight < 0) {
>    weight = 0;
> }
> if (weightedRoundRobin == null) {
>    weightedRoundRobin = new WeightedRoundRobin();
>    weightedRoundRobin.setWeight(weight);
>    map.putIfAbsent(identifyString, weightedRoundRobin);
>    weightedRoundRobin = map.get(identifyString);
> }
> 
> 
> Thanks,
> -Ian.
> On Thu, Oct 25, 2018 at 8:27 PM Jason Joo <hb...@163.com> wrote:
>> 
>> hi, Luo
>> 
>> Due to a loop on MAP object each time selecting the performance will reduce by 9.3% in single thread test.
>> 
>> Does it worth it?
>> 
>> Under 5, 10, 20 threads the difference is not stable: 8~13% loss
>> 
>> What do you think?
>> 
>> best regards,
>> 
>> Jason
>> 
>>> On Oct 25, 2018, at 19:42, Ian Luo <ia...@gmail.com> wrote:
>>> 
>>> Jason,
>>> 
>>> what I suggest is to simply declare methodWeightMap from
>>> ConcurrentMap<String, Map<String, WeightedRoundRobin>> to
>>> ConcurrentMap<String, ConcurrentMap<String, WeightedRoundRobin>>, then
>>> you will have 'putIfAbsent', what do you think?
>>> 
>>> Thanks,
>>> -Ian.
>>> 
>>> On Thu, Oct 25, 2018 at 3:47 PM Jason Joo <hb...@163.com> wrote:
>>>> 
>>>> hi, luo
>>>> 
>>>> Just replace putIfAbsent with put for compatibility and tested in racing condition.
>>>> 
>>>> best regards,
>>>> 
>>>> Jason
>>>> 
>>>>> On Oct 25, 2018, at 11:33, Ian Luo <ia...@gmail.com> wrote:
>>>>> 
>>>>> great.
>>>>> On Thu, Oct 25, 2018 at 11:33 AM Jason Joo <hb...@163.com> wrote:
>>>>>> 
>>>>>> hi, Luo
>>>>>> 
>>>>>> I am switching branch and ide hangs.....I am figuring it
>>>>>> 
>>>>>> best regards,
>>>>>> 
>>>>>> Jason
>>>>>> 
>>>>>>> On Oct 25, 2018, at 11:28, Ian Luo <ia...@gmail.com> wrote:
>>>>>>> 
>>>>>>> Jason,
>>>>>>> 
>>>>>>> Last comment on 'putIfAbsent', pls. take a look.
>>>>>>> 
>>>>>>> Thanks,
>>>>>>> -Ian.
>>>>>>> 
>>>>>>> On Thu, Oct 25, 2018 at 11:02 AM Ian Luo <ia...@gmail.com> wrote:
>>>>>>>> 
>>>>>>>> Jason,
>>>>>>>> 
>>>>>>>> More comments, pls. take a look :)
>>>>>>>> 
>>>>>>>> Thanks,
>>>>>>>> -Ian.
>>>>>>>> On Thu, Oct 25, 2018 at 10:50 AM Jason Joo <hb...@163.com> wrote:
>>>>>>>>> 
>>>>>>>>> hi, Luo
>>>>>>>>> 
>>>>>>>>> Thanks for your great suggestions and PR has been updated.
>>>>>>>>> 
>>>>>>>>> We need more work testing and reviewing to prevent poor performance and so on mentioned in #2578.
>>>>>>>>> 
>>>>>>>>> best regards,
>>>>>>>>> 
>>>>>>>>> Jason
>>>>>>>>> 
>>>>>>>>>> On Oct 25, 2018, at 10:35, Ian Luo <ia...@gmail.com> wrote:
>>>>>>>>>> 
>>>>>>>>>> Jason,
>>>>>>>>>> 
>>>>>>>>>> I take a look at the updated pull request, and give a few suggestions.
>>>>>>>>>> I think it's on the right direction, pls. take a look.
>>>>>>>>>> 
>>>>>>>>>> Thanks,
>>>>>>>>>> -Ian.
>>>>>>>>>> On Thu, Oct 25, 2018 at 10:19 AM Ian Luo <ia...@gmail.com> wrote:
>>>>>>>>>>> 
>>>>>>>>>>> The data seems convincing. What's meaning of 'before patch' and 'after patch'?
>>>>>>>>>>> 
>>>>>>>>>>> 
>>>>>>>>>>> Thanks,
>>>>>>>>>>> -Ian.
>>>>>>>>>>> On Thu, Oct 25, 2018 at 1:17 AM Jason Joo <hb...@163.com> wrote:
>>>>>>>>>>>> 
>>>>>>>>>>>> hi, king
>>>>>>>>>>>> 
>>>>>>>>>>>> I think we also care about if it would cause abusing in practices of DUBBO.
>>>>>>>>>>>> The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.
>>>>>>>>>>>> 
>>>>>>>>>>>> typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
>>>>>>>>>>>> -------------------
>>>>>>>>>>>> before patch:  8536
>>>>>>>>>>>> after patch:     140
>>>>>>>>>>>> @2.5.3:           141
>>>>>>>>>>>> smooth:           414
>>>>>>>>>>>> 
>>>>>>>>>>>> but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
>>>>>>>>>>>> -------------------
>>>>>>>>>>>> before patch:     25002       23939         23435
>>>>>>>>>>>> after patch:        2141         2034           2033
>>>>>>>>>>>> @2.5.3:             1241         1229           1193
>>>>>>>>>>>> smooth:             2081         2231           2376
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.
>>>>>>>>>>>> 
>>>>>>>>>>>> Certainly it's a little geek in this case and i will be ok about our future conclusion.
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> best regards,
>>>>>>>>>>>> 
>>>>>>>>>>>> Jason
>>>>>>>>>>>> 
>>>>>>>>>>>> On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
>>>>>>>>>>>> 
>>>>>>>>>>>> Thanks for a good pr first.
>>>>>>>>>>>> But I think old-way is better useful.
>>>>>>>>>>>> When we need a balance, it means so much invoking occurs, so the most important point is:
>>>>>>>>>>>> 
>>>>>>>>>>>> * Lightweight and Performance
>>>>>>>>>>>> Then accuracy and smoothness are not so much prior.
>>>>>>>>>>>> And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
>>>>>>>>>>>> we could not care about its change, check stage is not a key point.
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
>>>>>>>>>>>> 
>>>>>>>>>>>> hi, xiu
>>>>>>>>>>>> 
>>>>>>>>>>>> After some deeper research on the algorithm i found it seemed like thread-safe.
>>>>>>>>>>>> 
>>>>>>>>>>>> I updated my PR and unit test on it so we can examine if it acts as expected.
>>>>>>>>>>>> 
>>>>>>>>>>>> So the recycle logic I change it into an optimistic lock.
>>>>>>>>>>>> 
>>>>>>>>>>>> NGINX is a single-process model which lead me to a wrong path.
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> So it's lock-free and with memory recycler now.
>>>>>>>>>>>> 
>>>>>>>>>>>> Let's check if it works correctly.
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> best regards,
>>>>>>>>>>>> 
>>>>>>>>>>>> Jason
>>>>>>>>>>>> 
>>>>>>>>>>>> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
>>>>>>>>>>>> 
>>>>>>>>>>>> Hi, jason
>>>>>>>>>>>> 
>>>>>>>>>>>> If we can have a good balance on synchronize, thread and memory, I support
>>>>>>>>>>>> the way of smooth.
>>>>>>>>>>>> We need more discussion and solutions on this issue. Looking forward to
>>>>>>>>>>>> your solutions. :)
>>>>>>>>>>>> 
>>>>>>>>>>>> Thx
>>>>>>>>>>>> 
>>>>>>>>>>>> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
>>>>>>>>>>>> 
>>>>>>>>>>>> hi, xiu
>>>>>>>>>>>> 
>>>>>>>>>>>> Good proposal.
>>>>>>>>>>>> 
>>>>>>>>>>>> The old not-very-smooth RoundRobin implementation can work fine in most
>>>>>>>>>>>> conditions.
>>>>>>>>>>>> Actually it depends the number of weight.
>>>>>>>>>>>> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
>>>>>>>>>>>> simplify the weights when selecting.
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> And i have another thought about the KEY.
>>>>>>>>>>>> Now the key is defined by Method (which can make method's invocation RR).
>>>>>>>>>>>> If we change it into by Service (which the method will not be RR if its
>>>>>>>>>>>> invocations just match a round) the memory issue may looked better.
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> So what do other guys think about?
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> best regards,
>>>>>>>>>>>> 
>>>>>>>>>>>> Jason
>>>>>>>>>>>> 
>>>>>>>>>>>> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
>>>>>>>>>>>> 
>>>>>>>>>>>> 你好,
>>>>>>>>>>>> 
>>>>>>>>>>>> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
>>>>>>>>>>>> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
>>>>>>>>>>>> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
>>>>>>>>>>>> 
>>>>>>>>>>>> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> 谢谢。
>>>>>>>>>>>> 
>>>>>>>>>>>> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
>>>>>>>>>>>> 
>>>>>>>>>>>> hi, Luo
>>>>>>>>>>>> 
>>>>>>>>>>>> Glad to receive your response. I posted a reply before including some
>>>>>>>>>>>> minds about the lock:
>>>>>>>>>>>> 
>>>>>>>>>>>> * Separated recycle thread (more threads)
>>>>>>>>>>>> 
>>>>>>>>>>>> or
>>>>>>>>>>>> 
>>>>>>>>>>>> * Lock free (more memory in special conditions)
>>>>>>>>>>>> 
>>>>>>>>>>>> It's truly a struggling job to make a decision and we can do it
>>>>>>>>>>>> 
>>>>>>>>>>>> together.
>>>>>>>>>>>> 
>>>>>>>>>>>> For the lock-free implementation it will waste or even fail if the
>>>>>>>>>>>> providers are fully dynamic deployed after running enough time(OOM?).
>>>>>>>>>>>> 
>>>>>>>>>>>> best regards,
>>>>>>>>>>>> 
>>>>>>>>>>>> Jason
>>>>>>>>>>>> 
>>>>>>>>>>>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
>>>>>>>>>>>> 
>>>>>>>>>>>> Hi Jason,
>>>>>>>>>>>> 
>>>>>>>>>>>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
>>>>>>>>>>>> 
>>>>>>>>>>>> selection) [1] today. It is an awesome implementation and I like it.
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> There's one particular issue you may need to consider further is I
>>>>>>>>>>>> 
>>>>>>>>>>>> think
>>>>>>>>>>>> 
>>>>>>>>>>>> we should avoid synchronized block. I have drop review comments on the
>>>>>>>>>>>> 
>>>>>>>>>>>> pull
>>>>>>>>>>>> 
>>>>>>>>>>>> request. Would you mind to consider this further. After that, I think
>>>>>>>>>>>> 
>>>>>>>>>>>> this
>>>>>>>>>>>> 
>>>>>>>>>>>> change is ready to go.
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> Thanks,
>>>>>>>>>>>> -Ian.
>>>>>>>>>>>> 
>>>>>>>>>>>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
>>>>>>>>>>>> 
>>>>>>>>>>>> https://github.com/apache/incubator-dubbo/pull/2647>
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>>>>> 
>>>>>>>>> 
>>>>>> 
>>>> 
>> 


Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Ian Luo <ia...@gmail.com>.
Jason,

The problem is, if we use Map instead of ConcurrentMap, then
weightedRoundRobin could be two different objects when two threads
executes at the same time if they happen to use the same URL.

String identifyString = invoker.getUrl().toIdentityString();
WeightedRoundRobin weightedRoundRobin = map.get(identifyString);
int weight = getWeight(invoker, invocation);
if (weight < 0) {
    weight = 0;
}
if (weightedRoundRobin == null) {
    weightedRoundRobin = new WeightedRoundRobin();
    weightedRoundRobin.setWeight(weight);
    map.putIfAbsent(identifyString, weightedRoundRobin);
    weightedRoundRobin = map.get(identifyString);
}


Thanks,
-Ian.
On Thu, Oct 25, 2018 at 8:27 PM Jason Joo <hb...@163.com> wrote:
>
> hi, Luo
>
> Due to a loop on MAP object each time selecting the performance will reduce by 9.3% in single thread test.
>
> Does it worth it?
>
> Under 5, 10, 20 threads the difference is not stable: 8~13% loss
>
> What do you think?
>
> best regards,
>
> Jason
>
> > On Oct 25, 2018, at 19:42, Ian Luo <ia...@gmail.com> wrote:
> >
> > Jason,
> >
> > what I suggest is to simply declare methodWeightMap from
> > ConcurrentMap<String, Map<String, WeightedRoundRobin>> to
> > ConcurrentMap<String, ConcurrentMap<String, WeightedRoundRobin>>, then
> > you will have 'putIfAbsent', what do you think?
> >
> > Thanks,
> > -Ian.
> >
> > On Thu, Oct 25, 2018 at 3:47 PM Jason Joo <hb...@163.com> wrote:
> >>
> >> hi, luo
> >>
> >> Just replace putIfAbsent with put for compatibility and tested in racing condition.
> >>
> >> best regards,
> >>
> >> Jason
> >>
> >>> On Oct 25, 2018, at 11:33, Ian Luo <ia...@gmail.com> wrote:
> >>>
> >>> great.
> >>> On Thu, Oct 25, 2018 at 11:33 AM Jason Joo <hb...@163.com> wrote:
> >>>>
> >>>> hi, Luo
> >>>>
> >>>> I am switching branch and ide hangs.....I am figuring it
> >>>>
> >>>> best regards,
> >>>>
> >>>> Jason
> >>>>
> >>>>> On Oct 25, 2018, at 11:28, Ian Luo <ia...@gmail.com> wrote:
> >>>>>
> >>>>> Jason,
> >>>>>
> >>>>> Last comment on 'putIfAbsent', pls. take a look.
> >>>>>
> >>>>> Thanks,
> >>>>> -Ian.
> >>>>>
> >>>>> On Thu, Oct 25, 2018 at 11:02 AM Ian Luo <ia...@gmail.com> wrote:
> >>>>>>
> >>>>>> Jason,
> >>>>>>
> >>>>>> More comments, pls. take a look :)
> >>>>>>
> >>>>>> Thanks,
> >>>>>> -Ian.
> >>>>>> On Thu, Oct 25, 2018 at 10:50 AM Jason Joo <hb...@163.com> wrote:
> >>>>>>>
> >>>>>>> hi, Luo
> >>>>>>>
> >>>>>>> Thanks for your great suggestions and PR has been updated.
> >>>>>>>
> >>>>>>> We need more work testing and reviewing to prevent poor performance and so on mentioned in #2578.
> >>>>>>>
> >>>>>>> best regards,
> >>>>>>>
> >>>>>>> Jason
> >>>>>>>
> >>>>>>>> On Oct 25, 2018, at 10:35, Ian Luo <ia...@gmail.com> wrote:
> >>>>>>>>
> >>>>>>>> Jason,
> >>>>>>>>
> >>>>>>>> I take a look at the updated pull request, and give a few suggestions.
> >>>>>>>> I think it's on the right direction, pls. take a look.
> >>>>>>>>
> >>>>>>>> Thanks,
> >>>>>>>> -Ian.
> >>>>>>>> On Thu, Oct 25, 2018 at 10:19 AM Ian Luo <ia...@gmail.com> wrote:
> >>>>>>>>>
> >>>>>>>>> The data seems convincing. What's meaning of 'before patch' and 'after patch'?
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> Thanks,
> >>>>>>>>> -Ian.
> >>>>>>>>> On Thu, Oct 25, 2018 at 1:17 AM Jason Joo <hb...@163.com> wrote:
> >>>>>>>>>>
> >>>>>>>>>> hi, king
> >>>>>>>>>>
> >>>>>>>>>> I think we also care about if it would cause abusing in practices of DUBBO.
> >>>>>>>>>> The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.
> >>>>>>>>>>
> >>>>>>>>>> typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
> >>>>>>>>>> -------------------
> >>>>>>>>>> before patch:  8536
> >>>>>>>>>> after patch:     140
> >>>>>>>>>> @2.5.3:           141
> >>>>>>>>>> smooth:           414
> >>>>>>>>>>
> >>>>>>>>>> but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
> >>>>>>>>>> -------------------
> >>>>>>>>>> before patch:     25002       23939         23435
> >>>>>>>>>> after patch:        2141         2034           2033
> >>>>>>>>>> @2.5.3:             1241         1229           1193
> >>>>>>>>>> smooth:             2081         2231           2376
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.
> >>>>>>>>>>
> >>>>>>>>>> Certainly it's a little geek in this case and i will be ok about our future conclusion.
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> best regards,
> >>>>>>>>>>
> >>>>>>>>>> Jason
> >>>>>>>>>>
> >>>>>>>>>> On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
> >>>>>>>>>>
> >>>>>>>>>> Thanks for a good pr first.
> >>>>>>>>>> But I think old-way is better useful.
> >>>>>>>>>> When we need a balance, it means so much invoking occurs, so the most important point is:
> >>>>>>>>>>
> >>>>>>>>>> * Lightweight and Performance
> >>>>>>>>>> Then accuracy and smoothness are not so much prior.
> >>>>>>>>>> And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
> >>>>>>>>>> we could not care about its change, check stage is not a key point.
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
> >>>>>>>>>>
> >>>>>>>>>> hi, xiu
> >>>>>>>>>>
> >>>>>>>>>> After some deeper research on the algorithm i found it seemed like thread-safe.
> >>>>>>>>>>
> >>>>>>>>>> I updated my PR and unit test on it so we can examine if it acts as expected.
> >>>>>>>>>>
> >>>>>>>>>> So the recycle logic I change it into an optimistic lock.
> >>>>>>>>>>
> >>>>>>>>>> NGINX is a single-process model which lead me to a wrong path.
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> So it's lock-free and with memory recycler now.
> >>>>>>>>>>
> >>>>>>>>>> Let's check if it works correctly.
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> best regards,
> >>>>>>>>>>
> >>>>>>>>>> Jason
> >>>>>>>>>>
> >>>>>>>>>> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
> >>>>>>>>>>
> >>>>>>>>>> Hi, jason
> >>>>>>>>>>
> >>>>>>>>>> If we can have a good balance on synchronize, thread and memory, I support
> >>>>>>>>>> the way of smooth.
> >>>>>>>>>> We need more discussion and solutions on this issue. Looking forward to
> >>>>>>>>>> your solutions. :)
> >>>>>>>>>>
> >>>>>>>>>> Thx
> >>>>>>>>>>
> >>>>>>>>>> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
> >>>>>>>>>>
> >>>>>>>>>> hi, xiu
> >>>>>>>>>>
> >>>>>>>>>> Good proposal.
> >>>>>>>>>>
> >>>>>>>>>> The old not-very-smooth RoundRobin implementation can work fine in most
> >>>>>>>>>> conditions.
> >>>>>>>>>> Actually it depends the number of weight.
> >>>>>>>>>> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
> >>>>>>>>>> simplify the weights when selecting.
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> And i have another thought about the KEY.
> >>>>>>>>>> Now the key is defined by Method (which can make method's invocation RR).
> >>>>>>>>>> If we change it into by Service (which the method will not be RR if its
> >>>>>>>>>> invocations just match a round) the memory issue may looked better.
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> So what do other guys think about?
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> best regards,
> >>>>>>>>>>
> >>>>>>>>>> Jason
> >>>>>>>>>>
> >>>>>>>>>> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
> >>>>>>>>>>
> >>>>>>>>>> 你好,
> >>>>>>>>>>
> >>>>>>>>>> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
> >>>>>>>>>> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
> >>>>>>>>>> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
> >>>>>>>>>>
> >>>>>>>>>> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> 谢谢。
> >>>>>>>>>>
> >>>>>>>>>> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
> >>>>>>>>>>
> >>>>>>>>>> hi, Luo
> >>>>>>>>>>
> >>>>>>>>>> Glad to receive your response. I posted a reply before including some
> >>>>>>>>>> minds about the lock:
> >>>>>>>>>>
> >>>>>>>>>> * Separated recycle thread (more threads)
> >>>>>>>>>>
> >>>>>>>>>> or
> >>>>>>>>>>
> >>>>>>>>>> * Lock free (more memory in special conditions)
> >>>>>>>>>>
> >>>>>>>>>> It's truly a struggling job to make a decision and we can do it
> >>>>>>>>>>
> >>>>>>>>>> together.
> >>>>>>>>>>
> >>>>>>>>>> For the lock-free implementation it will waste or even fail if the
> >>>>>>>>>> providers are fully dynamic deployed after running enough time(OOM?).
> >>>>>>>>>>
> >>>>>>>>>> best regards,
> >>>>>>>>>>
> >>>>>>>>>> Jason
> >>>>>>>>>>
> >>>>>>>>>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
> >>>>>>>>>>
> >>>>>>>>>> Hi Jason,
> >>>>>>>>>>
> >>>>>>>>>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
> >>>>>>>>>>
> >>>>>>>>>> selection) [1] today. It is an awesome implementation and I like it.
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> There's one particular issue you may need to consider further is I
> >>>>>>>>>>
> >>>>>>>>>> think
> >>>>>>>>>>
> >>>>>>>>>> we should avoid synchronized block. I have drop review comments on the
> >>>>>>>>>>
> >>>>>>>>>> pull
> >>>>>>>>>>
> >>>>>>>>>> request. Would you mind to consider this further. After that, I think
> >>>>>>>>>>
> >>>>>>>>>> this
> >>>>>>>>>>
> >>>>>>>>>> change is ready to go.
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> Thanks,
> >>>>>>>>>> -Ian.
> >>>>>>>>>>
> >>>>>>>>>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
> >>>>>>>>>>
> >>>>>>>>>> https://github.com/apache/incubator-dubbo/pull/2647>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>
> >>>>
> >>
>

Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Jason Joo <hb...@163.com>.
hi, Luo

Due to a loop on MAP object each time selecting the performance will reduce by 9.3% in single thread test.

Does it worth it?

Under 5, 10, 20 threads the difference is not stable: 8~13% loss

What do you think?

best regards,

Jason

> On Oct 25, 2018, at 19:42, Ian Luo <ia...@gmail.com> wrote:
> 
> Jason,
> 
> what I suggest is to simply declare methodWeightMap from
> ConcurrentMap<String, Map<String, WeightedRoundRobin>> to
> ConcurrentMap<String, ConcurrentMap<String, WeightedRoundRobin>>, then
> you will have 'putIfAbsent', what do you think?
> 
> Thanks,
> -Ian.
> 
> On Thu, Oct 25, 2018 at 3:47 PM Jason Joo <hb...@163.com> wrote:
>> 
>> hi, luo
>> 
>> Just replace putIfAbsent with put for compatibility and tested in racing condition.
>> 
>> best regards,
>> 
>> Jason
>> 
>>> On Oct 25, 2018, at 11:33, Ian Luo <ia...@gmail.com> wrote:
>>> 
>>> great.
>>> On Thu, Oct 25, 2018 at 11:33 AM Jason Joo <hb...@163.com> wrote:
>>>> 
>>>> hi, Luo
>>>> 
>>>> I am switching branch and ide hangs.....I am figuring it
>>>> 
>>>> best regards,
>>>> 
>>>> Jason
>>>> 
>>>>> On Oct 25, 2018, at 11:28, Ian Luo <ia...@gmail.com> wrote:
>>>>> 
>>>>> Jason,
>>>>> 
>>>>> Last comment on 'putIfAbsent', pls. take a look.
>>>>> 
>>>>> Thanks,
>>>>> -Ian.
>>>>> 
>>>>> On Thu, Oct 25, 2018 at 11:02 AM Ian Luo <ia...@gmail.com> wrote:
>>>>>> 
>>>>>> Jason,
>>>>>> 
>>>>>> More comments, pls. take a look :)
>>>>>> 
>>>>>> Thanks,
>>>>>> -Ian.
>>>>>> On Thu, Oct 25, 2018 at 10:50 AM Jason Joo <hb...@163.com> wrote:
>>>>>>> 
>>>>>>> hi, Luo
>>>>>>> 
>>>>>>> Thanks for your great suggestions and PR has been updated.
>>>>>>> 
>>>>>>> We need more work testing and reviewing to prevent poor performance and so on mentioned in #2578.
>>>>>>> 
>>>>>>> best regards,
>>>>>>> 
>>>>>>> Jason
>>>>>>> 
>>>>>>>> On Oct 25, 2018, at 10:35, Ian Luo <ia...@gmail.com> wrote:
>>>>>>>> 
>>>>>>>> Jason,
>>>>>>>> 
>>>>>>>> I take a look at the updated pull request, and give a few suggestions.
>>>>>>>> I think it's on the right direction, pls. take a look.
>>>>>>>> 
>>>>>>>> Thanks,
>>>>>>>> -Ian.
>>>>>>>> On Thu, Oct 25, 2018 at 10:19 AM Ian Luo <ia...@gmail.com> wrote:
>>>>>>>>> 
>>>>>>>>> The data seems convincing. What's meaning of 'before patch' and 'after patch'?
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> Thanks,
>>>>>>>>> -Ian.
>>>>>>>>> On Thu, Oct 25, 2018 at 1:17 AM Jason Joo <hb...@163.com> wrote:
>>>>>>>>>> 
>>>>>>>>>> hi, king
>>>>>>>>>> 
>>>>>>>>>> I think we also care about if it would cause abusing in practices of DUBBO.
>>>>>>>>>> The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.
>>>>>>>>>> 
>>>>>>>>>> typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
>>>>>>>>>> -------------------
>>>>>>>>>> before patch:  8536
>>>>>>>>>> after patch:     140
>>>>>>>>>> @2.5.3:           141
>>>>>>>>>> smooth:           414
>>>>>>>>>> 
>>>>>>>>>> but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
>>>>>>>>>> -------------------
>>>>>>>>>> before patch:     25002       23939         23435
>>>>>>>>>> after patch:        2141         2034           2033
>>>>>>>>>> @2.5.3:             1241         1229           1193
>>>>>>>>>> smooth:             2081         2231           2376
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.
>>>>>>>>>> 
>>>>>>>>>> Certainly it's a little geek in this case and i will be ok about our future conclusion.
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> best regards,
>>>>>>>>>> 
>>>>>>>>>> Jason
>>>>>>>>>> 
>>>>>>>>>> On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
>>>>>>>>>> 
>>>>>>>>>> Thanks for a good pr first.
>>>>>>>>>> But I think old-way is better useful.
>>>>>>>>>> When we need a balance, it means so much invoking occurs, so the most important point is:
>>>>>>>>>> 
>>>>>>>>>> * Lightweight and Performance
>>>>>>>>>> Then accuracy and smoothness are not so much prior.
>>>>>>>>>> And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
>>>>>>>>>> we could not care about its change, check stage is not a key point.
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
>>>>>>>>>> 
>>>>>>>>>> hi, xiu
>>>>>>>>>> 
>>>>>>>>>> After some deeper research on the algorithm i found it seemed like thread-safe.
>>>>>>>>>> 
>>>>>>>>>> I updated my PR and unit test on it so we can examine if it acts as expected.
>>>>>>>>>> 
>>>>>>>>>> So the recycle logic I change it into an optimistic lock.
>>>>>>>>>> 
>>>>>>>>>> NGINX is a single-process model which lead me to a wrong path.
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> So it's lock-free and with memory recycler now.
>>>>>>>>>> 
>>>>>>>>>> Let's check if it works correctly.
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> best regards,
>>>>>>>>>> 
>>>>>>>>>> Jason
>>>>>>>>>> 
>>>>>>>>>> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
>>>>>>>>>> 
>>>>>>>>>> Hi, jason
>>>>>>>>>> 
>>>>>>>>>> If we can have a good balance on synchronize, thread and memory, I support
>>>>>>>>>> the way of smooth.
>>>>>>>>>> We need more discussion and solutions on this issue. Looking forward to
>>>>>>>>>> your solutions. :)
>>>>>>>>>> 
>>>>>>>>>> Thx
>>>>>>>>>> 
>>>>>>>>>> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
>>>>>>>>>> 
>>>>>>>>>> hi, xiu
>>>>>>>>>> 
>>>>>>>>>> Good proposal.
>>>>>>>>>> 
>>>>>>>>>> The old not-very-smooth RoundRobin implementation can work fine in most
>>>>>>>>>> conditions.
>>>>>>>>>> Actually it depends the number of weight.
>>>>>>>>>> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
>>>>>>>>>> simplify the weights when selecting.
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> And i have another thought about the KEY.
>>>>>>>>>> Now the key is defined by Method (which can make method's invocation RR).
>>>>>>>>>> If we change it into by Service (which the method will not be RR if its
>>>>>>>>>> invocations just match a round) the memory issue may looked better.
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> So what do other guys think about?
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> best regards,
>>>>>>>>>> 
>>>>>>>>>> Jason
>>>>>>>>>> 
>>>>>>>>>> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
>>>>>>>>>> 
>>>>>>>>>> 你好,
>>>>>>>>>> 
>>>>>>>>>> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
>>>>>>>>>> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
>>>>>>>>>> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
>>>>>>>>>> 
>>>>>>>>>> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> 谢谢。
>>>>>>>>>> 
>>>>>>>>>> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
>>>>>>>>>> 
>>>>>>>>>> hi, Luo
>>>>>>>>>> 
>>>>>>>>>> Glad to receive your response. I posted a reply before including some
>>>>>>>>>> minds about the lock:
>>>>>>>>>> 
>>>>>>>>>> * Separated recycle thread (more threads)
>>>>>>>>>> 
>>>>>>>>>> or
>>>>>>>>>> 
>>>>>>>>>> * Lock free (more memory in special conditions)
>>>>>>>>>> 
>>>>>>>>>> It's truly a struggling job to make a decision and we can do it
>>>>>>>>>> 
>>>>>>>>>> together.
>>>>>>>>>> 
>>>>>>>>>> For the lock-free implementation it will waste or even fail if the
>>>>>>>>>> providers are fully dynamic deployed after running enough time(OOM?).
>>>>>>>>>> 
>>>>>>>>>> best regards,
>>>>>>>>>> 
>>>>>>>>>> Jason
>>>>>>>>>> 
>>>>>>>>>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
>>>>>>>>>> 
>>>>>>>>>> Hi Jason,
>>>>>>>>>> 
>>>>>>>>>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
>>>>>>>>>> 
>>>>>>>>>> selection) [1] today. It is an awesome implementation and I like it.
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> There's one particular issue you may need to consider further is I
>>>>>>>>>> 
>>>>>>>>>> think
>>>>>>>>>> 
>>>>>>>>>> we should avoid synchronized block. I have drop review comments on the
>>>>>>>>>> 
>>>>>>>>>> pull
>>>>>>>>>> 
>>>>>>>>>> request. Would you mind to consider this further. After that, I think
>>>>>>>>>> 
>>>>>>>>>> this
>>>>>>>>>> 
>>>>>>>>>> change is ready to go.
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> Thanks,
>>>>>>>>>> -Ian.
>>>>>>>>>> 
>>>>>>>>>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
>>>>>>>>>> 
>>>>>>>>>> https://github.com/apache/incubator-dubbo/pull/2647>
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>> 
>>>> 
>> 


Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Ian Luo <ia...@gmail.com>.
Jason,

what I suggest is to simply declare methodWeightMap from
ConcurrentMap<String, Map<String, WeightedRoundRobin>> to
ConcurrentMap<String, ConcurrentMap<String, WeightedRoundRobin>>, then
you will have 'putIfAbsent', what do you think?

Thanks,
-Ian.

On Thu, Oct 25, 2018 at 3:47 PM Jason Joo <hb...@163.com> wrote:
>
> hi, luo
>
> Just replace putIfAbsent with put for compatibility and tested in racing condition.
>
> best regards,
>
> Jason
>
> > On Oct 25, 2018, at 11:33, Ian Luo <ia...@gmail.com> wrote:
> >
> > great.
> > On Thu, Oct 25, 2018 at 11:33 AM Jason Joo <hb...@163.com> wrote:
> >>
> >> hi, Luo
> >>
> >> I am switching branch and ide hangs.....I am figuring it
> >>
> >> best regards,
> >>
> >> Jason
> >>
> >>> On Oct 25, 2018, at 11:28, Ian Luo <ia...@gmail.com> wrote:
> >>>
> >>> Jason,
> >>>
> >>> Last comment on 'putIfAbsent', pls. take a look.
> >>>
> >>> Thanks,
> >>> -Ian.
> >>>
> >>> On Thu, Oct 25, 2018 at 11:02 AM Ian Luo <ia...@gmail.com> wrote:
> >>>>
> >>>> Jason,
> >>>>
> >>>> More comments, pls. take a look :)
> >>>>
> >>>> Thanks,
> >>>> -Ian.
> >>>> On Thu, Oct 25, 2018 at 10:50 AM Jason Joo <hb...@163.com> wrote:
> >>>>>
> >>>>> hi, Luo
> >>>>>
> >>>>> Thanks for your great suggestions and PR has been updated.
> >>>>>
> >>>>> We need more work testing and reviewing to prevent poor performance and so on mentioned in #2578.
> >>>>>
> >>>>> best regards,
> >>>>>
> >>>>> Jason
> >>>>>
> >>>>>> On Oct 25, 2018, at 10:35, Ian Luo <ia...@gmail.com> wrote:
> >>>>>>
> >>>>>> Jason,
> >>>>>>
> >>>>>> I take a look at the updated pull request, and give a few suggestions.
> >>>>>> I think it's on the right direction, pls. take a look.
> >>>>>>
> >>>>>> Thanks,
> >>>>>> -Ian.
> >>>>>> On Thu, Oct 25, 2018 at 10:19 AM Ian Luo <ia...@gmail.com> wrote:
> >>>>>>>
> >>>>>>> The data seems convincing. What's meaning of 'before patch' and 'after patch'?
> >>>>>>>
> >>>>>>>
> >>>>>>> Thanks,
> >>>>>>> -Ian.
> >>>>>>> On Thu, Oct 25, 2018 at 1:17 AM Jason Joo <hb...@163.com> wrote:
> >>>>>>>>
> >>>>>>>> hi, king
> >>>>>>>>
> >>>>>>>> I think we also care about if it would cause abusing in practices of DUBBO.
> >>>>>>>> The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.
> >>>>>>>>
> >>>>>>>> typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
> >>>>>>>> -------------------
> >>>>>>>> before patch:  8536
> >>>>>>>> after patch:     140
> >>>>>>>> @2.5.3:           141
> >>>>>>>> smooth:           414
> >>>>>>>>
> >>>>>>>> but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
> >>>>>>>> -------------------
> >>>>>>>> before patch:     25002       23939         23435
> >>>>>>>> after patch:        2141         2034           2033
> >>>>>>>> @2.5.3:             1241         1229           1193
> >>>>>>>> smooth:             2081         2231           2376
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.
> >>>>>>>>
> >>>>>>>> Certainly it's a little geek in this case and i will be ok about our future conclusion.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> best regards,
> >>>>>>>>
> >>>>>>>> Jason
> >>>>>>>>
> >>>>>>>> On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
> >>>>>>>>
> >>>>>>>> Thanks for a good pr first.
> >>>>>>>> But I think old-way is better useful.
> >>>>>>>> When we need a balance, it means so much invoking occurs, so the most important point is:
> >>>>>>>>
> >>>>>>>> * Lightweight and Performance
> >>>>>>>> Then accuracy and smoothness are not so much prior.
> >>>>>>>> And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
> >>>>>>>> we could not care about its change, check stage is not a key point.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
> >>>>>>>>
> >>>>>>>> hi, xiu
> >>>>>>>>
> >>>>>>>> After some deeper research on the algorithm i found it seemed like thread-safe.
> >>>>>>>>
> >>>>>>>> I updated my PR and unit test on it so we can examine if it acts as expected.
> >>>>>>>>
> >>>>>>>> So the recycle logic I change it into an optimistic lock.
> >>>>>>>>
> >>>>>>>> NGINX is a single-process model which lead me to a wrong path.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> So it's lock-free and with memory recycler now.
> >>>>>>>>
> >>>>>>>> Let's check if it works correctly.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> best regards,
> >>>>>>>>
> >>>>>>>> Jason
> >>>>>>>>
> >>>>>>>> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
> >>>>>>>>
> >>>>>>>> Hi, jason
> >>>>>>>>
> >>>>>>>> If we can have a good balance on synchronize, thread and memory, I support
> >>>>>>>> the way of smooth.
> >>>>>>>> We need more discussion and solutions on this issue. Looking forward to
> >>>>>>>> your solutions. :)
> >>>>>>>>
> >>>>>>>> Thx
> >>>>>>>>
> >>>>>>>> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
> >>>>>>>>
> >>>>>>>> hi, xiu
> >>>>>>>>
> >>>>>>>> Good proposal.
> >>>>>>>>
> >>>>>>>> The old not-very-smooth RoundRobin implementation can work fine in most
> >>>>>>>> conditions.
> >>>>>>>> Actually it depends the number of weight.
> >>>>>>>> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
> >>>>>>>> simplify the weights when selecting.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> And i have another thought about the KEY.
> >>>>>>>> Now the key is defined by Method (which can make method's invocation RR).
> >>>>>>>> If we change it into by Service (which the method will not be RR if its
> >>>>>>>> invocations just match a round) the memory issue may looked better.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> So what do other guys think about?
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> best regards,
> >>>>>>>>
> >>>>>>>> Jason
> >>>>>>>>
> >>>>>>>> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
> >>>>>>>>
> >>>>>>>> 你好,
> >>>>>>>>
> >>>>>>>> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
> >>>>>>>> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
> >>>>>>>> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
> >>>>>>>>
> >>>>>>>> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> 谢谢。
> >>>>>>>>
> >>>>>>>> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
> >>>>>>>>
> >>>>>>>> hi, Luo
> >>>>>>>>
> >>>>>>>> Glad to receive your response. I posted a reply before including some
> >>>>>>>> minds about the lock:
> >>>>>>>>
> >>>>>>>> * Separated recycle thread (more threads)
> >>>>>>>>
> >>>>>>>> or
> >>>>>>>>
> >>>>>>>> * Lock free (more memory in special conditions)
> >>>>>>>>
> >>>>>>>> It's truly a struggling job to make a decision and we can do it
> >>>>>>>>
> >>>>>>>> together.
> >>>>>>>>
> >>>>>>>> For the lock-free implementation it will waste or even fail if the
> >>>>>>>> providers are fully dynamic deployed after running enough time(OOM?).
> >>>>>>>>
> >>>>>>>> best regards,
> >>>>>>>>
> >>>>>>>> Jason
> >>>>>>>>
> >>>>>>>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
> >>>>>>>>
> >>>>>>>> Hi Jason,
> >>>>>>>>
> >>>>>>>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
> >>>>>>>>
> >>>>>>>> selection) [1] today. It is an awesome implementation and I like it.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> There's one particular issue you may need to consider further is I
> >>>>>>>>
> >>>>>>>> think
> >>>>>>>>
> >>>>>>>> we should avoid synchronized block. I have drop review comments on the
> >>>>>>>>
> >>>>>>>> pull
> >>>>>>>>
> >>>>>>>> request. Would you mind to consider this further. After that, I think
> >>>>>>>>
> >>>>>>>> this
> >>>>>>>>
> >>>>>>>> change is ready to go.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> Thanks,
> >>>>>>>> -Ian.
> >>>>>>>>
> >>>>>>>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
> >>>>>>>>
> >>>>>>>> https://github.com/apache/incubator-dubbo/pull/2647>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>
> >>
>

Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Jason Joo <hb...@163.com>.
hi, luo

Just replace putIfAbsent with put for compatibility and tested in racing condition.

best regards,

Jason

> On Oct 25, 2018, at 11:33, Ian Luo <ia...@gmail.com> wrote:
> 
> great.
> On Thu, Oct 25, 2018 at 11:33 AM Jason Joo <hb...@163.com> wrote:
>> 
>> hi, Luo
>> 
>> I am switching branch and ide hangs.....I am figuring it
>> 
>> best regards,
>> 
>> Jason
>> 
>>> On Oct 25, 2018, at 11:28, Ian Luo <ia...@gmail.com> wrote:
>>> 
>>> Jason,
>>> 
>>> Last comment on 'putIfAbsent', pls. take a look.
>>> 
>>> Thanks,
>>> -Ian.
>>> 
>>> On Thu, Oct 25, 2018 at 11:02 AM Ian Luo <ia...@gmail.com> wrote:
>>>> 
>>>> Jason,
>>>> 
>>>> More comments, pls. take a look :)
>>>> 
>>>> Thanks,
>>>> -Ian.
>>>> On Thu, Oct 25, 2018 at 10:50 AM Jason Joo <hb...@163.com> wrote:
>>>>> 
>>>>> hi, Luo
>>>>> 
>>>>> Thanks for your great suggestions and PR has been updated.
>>>>> 
>>>>> We need more work testing and reviewing to prevent poor performance and so on mentioned in #2578.
>>>>> 
>>>>> best regards,
>>>>> 
>>>>> Jason
>>>>> 
>>>>>> On Oct 25, 2018, at 10:35, Ian Luo <ia...@gmail.com> wrote:
>>>>>> 
>>>>>> Jason,
>>>>>> 
>>>>>> I take a look at the updated pull request, and give a few suggestions.
>>>>>> I think it's on the right direction, pls. take a look.
>>>>>> 
>>>>>> Thanks,
>>>>>> -Ian.
>>>>>> On Thu, Oct 25, 2018 at 10:19 AM Ian Luo <ia...@gmail.com> wrote:
>>>>>>> 
>>>>>>> The data seems convincing. What's meaning of 'before patch' and 'after patch'?
>>>>>>> 
>>>>>>> 
>>>>>>> Thanks,
>>>>>>> -Ian.
>>>>>>> On Thu, Oct 25, 2018 at 1:17 AM Jason Joo <hb...@163.com> wrote:
>>>>>>>> 
>>>>>>>> hi, king
>>>>>>>> 
>>>>>>>> I think we also care about if it would cause abusing in practices of DUBBO.
>>>>>>>> The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.
>>>>>>>> 
>>>>>>>> typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
>>>>>>>> -------------------
>>>>>>>> before patch:  8536
>>>>>>>> after patch:     140
>>>>>>>> @2.5.3:           141
>>>>>>>> smooth:           414
>>>>>>>> 
>>>>>>>> but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
>>>>>>>> -------------------
>>>>>>>> before patch:     25002       23939         23435
>>>>>>>> after patch:        2141         2034           2033
>>>>>>>> @2.5.3:             1241         1229           1193
>>>>>>>> smooth:             2081         2231           2376
>>>>>>>> 
>>>>>>>> 
>>>>>>>> So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.
>>>>>>>> 
>>>>>>>> Certainly it's a little geek in this case and i will be ok about our future conclusion.
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 
>>>>>>>> best regards,
>>>>>>>> 
>>>>>>>> Jason
>>>>>>>> 
>>>>>>>> On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
>>>>>>>> 
>>>>>>>> Thanks for a good pr first.
>>>>>>>> But I think old-way is better useful.
>>>>>>>> When we need a balance, it means so much invoking occurs, so the most important point is:
>>>>>>>> 
>>>>>>>> * Lightweight and Performance
>>>>>>>> Then accuracy and smoothness are not so much prior.
>>>>>>>> And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
>>>>>>>> we could not care about its change, check stage is not a key point.
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 
>>>>>>>> At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
>>>>>>>> 
>>>>>>>> hi, xiu
>>>>>>>> 
>>>>>>>> After some deeper research on the algorithm i found it seemed like thread-safe.
>>>>>>>> 
>>>>>>>> I updated my PR and unit test on it so we can examine if it acts as expected.
>>>>>>>> 
>>>>>>>> So the recycle logic I change it into an optimistic lock.
>>>>>>>> 
>>>>>>>> NGINX is a single-process model which lead me to a wrong path.
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 
>>>>>>>> So it's lock-free and with memory recycler now.
>>>>>>>> 
>>>>>>>> Let's check if it works correctly.
>>>>>>>> 
>>>>>>>> 
>>>>>>>> best regards,
>>>>>>>> 
>>>>>>>> Jason
>>>>>>>> 
>>>>>>>> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
>>>>>>>> 
>>>>>>>> Hi, jason
>>>>>>>> 
>>>>>>>> If we can have a good balance on synchronize, thread and memory, I support
>>>>>>>> the way of smooth.
>>>>>>>> We need more discussion and solutions on this issue. Looking forward to
>>>>>>>> your solutions. :)
>>>>>>>> 
>>>>>>>> Thx
>>>>>>>> 
>>>>>>>> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
>>>>>>>> 
>>>>>>>> hi, xiu
>>>>>>>> 
>>>>>>>> Good proposal.
>>>>>>>> 
>>>>>>>> The old not-very-smooth RoundRobin implementation can work fine in most
>>>>>>>> conditions.
>>>>>>>> Actually it depends the number of weight.
>>>>>>>> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
>>>>>>>> simplify the weights when selecting.
>>>>>>>> 
>>>>>>>> 
>>>>>>>> And i have another thought about the KEY.
>>>>>>>> Now the key is defined by Method (which can make method's invocation RR).
>>>>>>>> If we change it into by Service (which the method will not be RR if its
>>>>>>>> invocations just match a round) the memory issue may looked better.
>>>>>>>> 
>>>>>>>> 
>>>>>>>> So what do other guys think about?
>>>>>>>> 
>>>>>>>> 
>>>>>>>> best regards,
>>>>>>>> 
>>>>>>>> Jason
>>>>>>>> 
>>>>>>>> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
>>>>>>>> 
>>>>>>>> 你好,
>>>>>>>> 
>>>>>>>> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
>>>>>>>> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
>>>>>>>> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
>>>>>>>> 
>>>>>>>> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 谢谢。
>>>>>>>> 
>>>>>>>> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
>>>>>>>> 
>>>>>>>> hi, Luo
>>>>>>>> 
>>>>>>>> Glad to receive your response. I posted a reply before including some
>>>>>>>> minds about the lock:
>>>>>>>> 
>>>>>>>> * Separated recycle thread (more threads)
>>>>>>>> 
>>>>>>>> or
>>>>>>>> 
>>>>>>>> * Lock free (more memory in special conditions)
>>>>>>>> 
>>>>>>>> It's truly a struggling job to make a decision and we can do it
>>>>>>>> 
>>>>>>>> together.
>>>>>>>> 
>>>>>>>> For the lock-free implementation it will waste or even fail if the
>>>>>>>> providers are fully dynamic deployed after running enough time(OOM?).
>>>>>>>> 
>>>>>>>> best regards,
>>>>>>>> 
>>>>>>>> Jason
>>>>>>>> 
>>>>>>>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
>>>>>>>> 
>>>>>>>> Hi Jason,
>>>>>>>> 
>>>>>>>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
>>>>>>>> 
>>>>>>>> selection) [1] today. It is an awesome implementation and I like it.
>>>>>>>> 
>>>>>>>> 
>>>>>>>> There's one particular issue you may need to consider further is I
>>>>>>>> 
>>>>>>>> think
>>>>>>>> 
>>>>>>>> we should avoid synchronized block. I have drop review comments on the
>>>>>>>> 
>>>>>>>> pull
>>>>>>>> 
>>>>>>>> request. Would you mind to consider this further. After that, I think
>>>>>>>> 
>>>>>>>> this
>>>>>>>> 
>>>>>>>> change is ready to go.
>>>>>>>> 
>>>>>>>> 
>>>>>>>> Thanks,
>>>>>>>> -Ian.
>>>>>>>> 
>>>>>>>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
>>>>>>>> 
>>>>>>>> https://github.com/apache/incubator-dubbo/pull/2647>
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 
>>>>> 
>> 


Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Ian Luo <ia...@gmail.com>.
great.
On Thu, Oct 25, 2018 at 11:33 AM Jason Joo <hb...@163.com> wrote:
>
> hi, Luo
>
> I am switching branch and ide hangs.....I am figuring it
>
> best regards,
>
> Jason
>
> > On Oct 25, 2018, at 11:28, Ian Luo <ia...@gmail.com> wrote:
> >
> > Jason,
> >
> > Last comment on 'putIfAbsent', pls. take a look.
> >
> > Thanks,
> > -Ian.
> >
> > On Thu, Oct 25, 2018 at 11:02 AM Ian Luo <ia...@gmail.com> wrote:
> >>
> >> Jason,
> >>
> >> More comments, pls. take a look :)
> >>
> >> Thanks,
> >> -Ian.
> >> On Thu, Oct 25, 2018 at 10:50 AM Jason Joo <hb...@163.com> wrote:
> >>>
> >>> hi, Luo
> >>>
> >>> Thanks for your great suggestions and PR has been updated.
> >>>
> >>> We need more work testing and reviewing to prevent poor performance and so on mentioned in #2578.
> >>>
> >>> best regards,
> >>>
> >>> Jason
> >>>
> >>>> On Oct 25, 2018, at 10:35, Ian Luo <ia...@gmail.com> wrote:
> >>>>
> >>>> Jason,
> >>>>
> >>>> I take a look at the updated pull request, and give a few suggestions.
> >>>> I think it's on the right direction, pls. take a look.
> >>>>
> >>>> Thanks,
> >>>> -Ian.
> >>>> On Thu, Oct 25, 2018 at 10:19 AM Ian Luo <ia...@gmail.com> wrote:
> >>>>>
> >>>>> The data seems convincing. What's meaning of 'before patch' and 'after patch'?
> >>>>>
> >>>>>
> >>>>> Thanks,
> >>>>> -Ian.
> >>>>> On Thu, Oct 25, 2018 at 1:17 AM Jason Joo <hb...@163.com> wrote:
> >>>>>>
> >>>>>> hi, king
> >>>>>>
> >>>>>> I think we also care about if it would cause abusing in practices of DUBBO.
> >>>>>> The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.
> >>>>>>
> >>>>>> typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
> >>>>>> -------------------
> >>>>>> before patch:  8536
> >>>>>> after patch:     140
> >>>>>> @2.5.3:           141
> >>>>>> smooth:           414
> >>>>>>
> >>>>>> but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
> >>>>>> -------------------
> >>>>>> before patch:     25002       23939         23435
> >>>>>> after patch:        2141         2034           2033
> >>>>>> @2.5.3:             1241         1229           1193
> >>>>>> smooth:             2081         2231           2376
> >>>>>>
> >>>>>>
> >>>>>> So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.
> >>>>>>
> >>>>>> Certainly it's a little geek in this case and i will be ok about our future conclusion.
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> best regards,
> >>>>>>
> >>>>>> Jason
> >>>>>>
> >>>>>> On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
> >>>>>>
> >>>>>> Thanks for a good pr first.
> >>>>>> But I think old-way is better useful.
> >>>>>> When we need a balance, it means so much invoking occurs, so the most important point is:
> >>>>>>
> >>>>>> * Lightweight and Performance
> >>>>>> Then accuracy and smoothness are not so much prior.
> >>>>>> And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
> >>>>>> we could not care about its change, check stage is not a key point.
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
> >>>>>>
> >>>>>> hi, xiu
> >>>>>>
> >>>>>> After some deeper research on the algorithm i found it seemed like thread-safe.
> >>>>>>
> >>>>>> I updated my PR and unit test on it so we can examine if it acts as expected.
> >>>>>>
> >>>>>> So the recycle logic I change it into an optimistic lock.
> >>>>>>
> >>>>>> NGINX is a single-process model which lead me to a wrong path.
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> So it's lock-free and with memory recycler now.
> >>>>>>
> >>>>>> Let's check if it works correctly.
> >>>>>>
> >>>>>>
> >>>>>> best regards,
> >>>>>>
> >>>>>> Jason
> >>>>>>
> >>>>>> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
> >>>>>>
> >>>>>> Hi, jason
> >>>>>>
> >>>>>> If we can have a good balance on synchronize, thread and memory, I support
> >>>>>> the way of smooth.
> >>>>>> We need more discussion and solutions on this issue. Looking forward to
> >>>>>> your solutions. :)
> >>>>>>
> >>>>>> Thx
> >>>>>>
> >>>>>> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
> >>>>>>
> >>>>>> hi, xiu
> >>>>>>
> >>>>>> Good proposal.
> >>>>>>
> >>>>>> The old not-very-smooth RoundRobin implementation can work fine in most
> >>>>>> conditions.
> >>>>>> Actually it depends the number of weight.
> >>>>>> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
> >>>>>> simplify the weights when selecting.
> >>>>>>
> >>>>>>
> >>>>>> And i have another thought about the KEY.
> >>>>>> Now the key is defined by Method (which can make method's invocation RR).
> >>>>>> If we change it into by Service (which the method will not be RR if its
> >>>>>> invocations just match a round) the memory issue may looked better.
> >>>>>>
> >>>>>>
> >>>>>> So what do other guys think about?
> >>>>>>
> >>>>>>
> >>>>>> best regards,
> >>>>>>
> >>>>>> Jason
> >>>>>>
> >>>>>> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
> >>>>>>
> >>>>>> 你好,
> >>>>>>
> >>>>>> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
> >>>>>> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
> >>>>>> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
> >>>>>>
> >>>>>> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
> >>>>>>
> >>>>>>
> >>>>>> 谢谢。
> >>>>>>
> >>>>>> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
> >>>>>>
> >>>>>> hi, Luo
> >>>>>>
> >>>>>> Glad to receive your response. I posted a reply before including some
> >>>>>> minds about the lock:
> >>>>>>
> >>>>>> * Separated recycle thread (more threads)
> >>>>>>
> >>>>>> or
> >>>>>>
> >>>>>> * Lock free (more memory in special conditions)
> >>>>>>
> >>>>>> It's truly a struggling job to make a decision and we can do it
> >>>>>>
> >>>>>> together.
> >>>>>>
> >>>>>> For the lock-free implementation it will waste or even fail if the
> >>>>>> providers are fully dynamic deployed after running enough time(OOM?).
> >>>>>>
> >>>>>> best regards,
> >>>>>>
> >>>>>> Jason
> >>>>>>
> >>>>>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
> >>>>>>
> >>>>>> Hi Jason,
> >>>>>>
> >>>>>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
> >>>>>>
> >>>>>> selection) [1] today. It is an awesome implementation and I like it.
> >>>>>>
> >>>>>>
> >>>>>> There's one particular issue you may need to consider further is I
> >>>>>>
> >>>>>> think
> >>>>>>
> >>>>>> we should avoid synchronized block. I have drop review comments on the
> >>>>>>
> >>>>>> pull
> >>>>>>
> >>>>>> request. Would you mind to consider this further. After that, I think
> >>>>>>
> >>>>>> this
> >>>>>>
> >>>>>> change is ready to go.
> >>>>>>
> >>>>>>
> >>>>>> Thanks,
> >>>>>> -Ian.
> >>>>>>
> >>>>>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
> >>>>>>
> >>>>>> https://github.com/apache/incubator-dubbo/pull/2647>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>
>

Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Jason Joo <hb...@163.com>.
hi, Luo

I am switching branch and ide hangs.....I am figuring it

best regards,

Jason

> On Oct 25, 2018, at 11:28, Ian Luo <ia...@gmail.com> wrote:
> 
> Jason,
> 
> Last comment on 'putIfAbsent', pls. take a look.
> 
> Thanks,
> -Ian.
> 
> On Thu, Oct 25, 2018 at 11:02 AM Ian Luo <ia...@gmail.com> wrote:
>> 
>> Jason,
>> 
>> More comments, pls. take a look :)
>> 
>> Thanks,
>> -Ian.
>> On Thu, Oct 25, 2018 at 10:50 AM Jason Joo <hb...@163.com> wrote:
>>> 
>>> hi, Luo
>>> 
>>> Thanks for your great suggestions and PR has been updated.
>>> 
>>> We need more work testing and reviewing to prevent poor performance and so on mentioned in #2578.
>>> 
>>> best regards,
>>> 
>>> Jason
>>> 
>>>> On Oct 25, 2018, at 10:35, Ian Luo <ia...@gmail.com> wrote:
>>>> 
>>>> Jason,
>>>> 
>>>> I take a look at the updated pull request, and give a few suggestions.
>>>> I think it's on the right direction, pls. take a look.
>>>> 
>>>> Thanks,
>>>> -Ian.
>>>> On Thu, Oct 25, 2018 at 10:19 AM Ian Luo <ia...@gmail.com> wrote:
>>>>> 
>>>>> The data seems convincing. What's meaning of 'before patch' and 'after patch'?
>>>>> 
>>>>> 
>>>>> Thanks,
>>>>> -Ian.
>>>>> On Thu, Oct 25, 2018 at 1:17 AM Jason Joo <hb...@163.com> wrote:
>>>>>> 
>>>>>> hi, king
>>>>>> 
>>>>>> I think we also care about if it would cause abusing in practices of DUBBO.
>>>>>> The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.
>>>>>> 
>>>>>> typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
>>>>>> -------------------
>>>>>> before patch:  8536
>>>>>> after patch:     140
>>>>>> @2.5.3:           141
>>>>>> smooth:           414
>>>>>> 
>>>>>> but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
>>>>>> -------------------
>>>>>> before patch:     25002       23939         23435
>>>>>> after patch:        2141         2034           2033
>>>>>> @2.5.3:             1241         1229           1193
>>>>>> smooth:             2081         2231           2376
>>>>>> 
>>>>>> 
>>>>>> So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.
>>>>>> 
>>>>>> Certainly it's a little geek in this case and i will be ok about our future conclusion.
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> best regards,
>>>>>> 
>>>>>> Jason
>>>>>> 
>>>>>> On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
>>>>>> 
>>>>>> Thanks for a good pr first.
>>>>>> But I think old-way is better useful.
>>>>>> When we need a balance, it means so much invoking occurs, so the most important point is:
>>>>>> 
>>>>>> * Lightweight and Performance
>>>>>> Then accuracy and smoothness are not so much prior.
>>>>>> And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
>>>>>> we could not care about its change, check stage is not a key point.
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
>>>>>> 
>>>>>> hi, xiu
>>>>>> 
>>>>>> After some deeper research on the algorithm i found it seemed like thread-safe.
>>>>>> 
>>>>>> I updated my PR and unit test on it so we can examine if it acts as expected.
>>>>>> 
>>>>>> So the recycle logic I change it into an optimistic lock.
>>>>>> 
>>>>>> NGINX is a single-process model which lead me to a wrong path.
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> So it's lock-free and with memory recycler now.
>>>>>> 
>>>>>> Let's check if it works correctly.
>>>>>> 
>>>>>> 
>>>>>> best regards,
>>>>>> 
>>>>>> Jason
>>>>>> 
>>>>>> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
>>>>>> 
>>>>>> Hi, jason
>>>>>> 
>>>>>> If we can have a good balance on synchronize, thread and memory, I support
>>>>>> the way of smooth.
>>>>>> We need more discussion and solutions on this issue. Looking forward to
>>>>>> your solutions. :)
>>>>>> 
>>>>>> Thx
>>>>>> 
>>>>>> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
>>>>>> 
>>>>>> hi, xiu
>>>>>> 
>>>>>> Good proposal.
>>>>>> 
>>>>>> The old not-very-smooth RoundRobin implementation can work fine in most
>>>>>> conditions.
>>>>>> Actually it depends the number of weight.
>>>>>> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
>>>>>> simplify the weights when selecting.
>>>>>> 
>>>>>> 
>>>>>> And i have another thought about the KEY.
>>>>>> Now the key is defined by Method (which can make method's invocation RR).
>>>>>> If we change it into by Service (which the method will not be RR if its
>>>>>> invocations just match a round) the memory issue may looked better.
>>>>>> 
>>>>>> 
>>>>>> So what do other guys think about?
>>>>>> 
>>>>>> 
>>>>>> best regards,
>>>>>> 
>>>>>> Jason
>>>>>> 
>>>>>> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
>>>>>> 
>>>>>> 你好,
>>>>>> 
>>>>>> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
>>>>>> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
>>>>>> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
>>>>>> 
>>>>>> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
>>>>>> 
>>>>>> 
>>>>>> 谢谢。
>>>>>> 
>>>>>> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
>>>>>> 
>>>>>> hi, Luo
>>>>>> 
>>>>>> Glad to receive your response. I posted a reply before including some
>>>>>> minds about the lock:
>>>>>> 
>>>>>> * Separated recycle thread (more threads)
>>>>>> 
>>>>>> or
>>>>>> 
>>>>>> * Lock free (more memory in special conditions)
>>>>>> 
>>>>>> It's truly a struggling job to make a decision and we can do it
>>>>>> 
>>>>>> together.
>>>>>> 
>>>>>> For the lock-free implementation it will waste or even fail if the
>>>>>> providers are fully dynamic deployed after running enough time(OOM?).
>>>>>> 
>>>>>> best regards,
>>>>>> 
>>>>>> Jason
>>>>>> 
>>>>>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
>>>>>> 
>>>>>> Hi Jason,
>>>>>> 
>>>>>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
>>>>>> 
>>>>>> selection) [1] today. It is an awesome implementation and I like it.
>>>>>> 
>>>>>> 
>>>>>> There's one particular issue you may need to consider further is I
>>>>>> 
>>>>>> think
>>>>>> 
>>>>>> we should avoid synchronized block. I have drop review comments on the
>>>>>> 
>>>>>> pull
>>>>>> 
>>>>>> request. Would you mind to consider this further. After that, I think
>>>>>> 
>>>>>> this
>>>>>> 
>>>>>> change is ready to go.
>>>>>> 
>>>>>> 
>>>>>> Thanks,
>>>>>> -Ian.
>>>>>> 
>>>>>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
>>>>>> 
>>>>>> https://github.com/apache/incubator-dubbo/pull/2647>
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>> 


Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Ian Luo <ia...@gmail.com>.
Jason,

Last comment on 'putIfAbsent', pls. take a look.

Thanks,
-Ian.

On Thu, Oct 25, 2018 at 11:02 AM Ian Luo <ia...@gmail.com> wrote:
>
> Jason,
>
> More comments, pls. take a look :)
>
> Thanks,
> -Ian.
> On Thu, Oct 25, 2018 at 10:50 AM Jason Joo <hb...@163.com> wrote:
> >
> > hi, Luo
> >
> > Thanks for your great suggestions and PR has been updated.
> >
> > We need more work testing and reviewing to prevent poor performance and so on mentioned in #2578.
> >
> > best regards,
> >
> > Jason
> >
> > > On Oct 25, 2018, at 10:35, Ian Luo <ia...@gmail.com> wrote:
> > >
> > > Jason,
> > >
> > > I take a look at the updated pull request, and give a few suggestions.
> > > I think it's on the right direction, pls. take a look.
> > >
> > > Thanks,
> > > -Ian.
> > > On Thu, Oct 25, 2018 at 10:19 AM Ian Luo <ia...@gmail.com> wrote:
> > >>
> > >> The data seems convincing. What's meaning of 'before patch' and 'after patch'?
> > >>
> > >>
> > >> Thanks,
> > >> -Ian.
> > >> On Thu, Oct 25, 2018 at 1:17 AM Jason Joo <hb...@163.com> wrote:
> > >>>
> > >>> hi, king
> > >>>
> > >>> I think we also care about if it would cause abusing in practices of DUBBO.
> > >>> The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.
> > >>>
> > >>> typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
> > >>> -------------------
> > >>> before patch:  8536
> > >>> after patch:     140
> > >>> @2.5.3:           141
> > >>> smooth:           414
> > >>>
> > >>> but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
> > >>> -------------------
> > >>> before patch:     25002       23939         23435
> > >>> after patch:        2141         2034           2033
> > >>> @2.5.3:             1241         1229           1193
> > >>> smooth:             2081         2231           2376
> > >>>
> > >>>
> > >>> So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.
> > >>>
> > >>> Certainly it's a little geek in this case and i will be ok about our future conclusion.
> > >>>
> > >>>
> > >>>
> > >>> best regards,
> > >>>
> > >>> Jason
> > >>>
> > >>> On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
> > >>>
> > >>> Thanks for a good pr first.
> > >>> But I think old-way is better useful.
> > >>> When we need a balance, it means so much invoking occurs, so the most important point is:
> > >>>
> > >>> * Lightweight and Performance
> > >>> Then accuracy and smoothness are not so much prior.
> > >>> And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
> > >>> we could not care about its change, check stage is not a key point.
> > >>>
> > >>>
> > >>>
> > >>> At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
> > >>>
> > >>> hi, xiu
> > >>>
> > >>> After some deeper research on the algorithm i found it seemed like thread-safe.
> > >>>
> > >>> I updated my PR and unit test on it so we can examine if it acts as expected.
> > >>>
> > >>> So the recycle logic I change it into an optimistic lock.
> > >>>
> > >>> NGINX is a single-process model which lead me to a wrong path.
> > >>>
> > >>>
> > >>>
> > >>> So it's lock-free and with memory recycler now.
> > >>>
> > >>> Let's check if it works correctly.
> > >>>
> > >>>
> > >>> best regards,
> > >>>
> > >>> Jason
> > >>>
> > >>> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
> > >>>
> > >>> Hi, jason
> > >>>
> > >>> If we can have a good balance on synchronize, thread and memory, I support
> > >>> the way of smooth.
> > >>> We need more discussion and solutions on this issue. Looking forward to
> > >>> your solutions. :)
> > >>>
> > >>> Thx
> > >>>
> > >>> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
> > >>>
> > >>> hi, xiu
> > >>>
> > >>> Good proposal.
> > >>>
> > >>> The old not-very-smooth RoundRobin implementation can work fine in most
> > >>> conditions.
> > >>> Actually it depends the number of weight.
> > >>> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
> > >>> simplify the weights when selecting.
> > >>>
> > >>>
> > >>> And i have another thought about the KEY.
> > >>> Now the key is defined by Method (which can make method's invocation RR).
> > >>> If we change it into by Service (which the method will not be RR if its
> > >>> invocations just match a round) the memory issue may looked better.
> > >>>
> > >>>
> > >>> So what do other guys think about?
> > >>>
> > >>>
> > >>> best regards,
> > >>>
> > >>> Jason
> > >>>
> > >>> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
> > >>>
> > >>> 你好,
> > >>>
> > >>> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
> > >>> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
> > >>> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
> > >>>
> > >>> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
> > >>>
> > >>>
> > >>>
> > >>> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
> > >>>
> > >>>
> > >>> 谢谢。
> > >>>
> > >>> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
> > >>>
> > >>> hi, Luo
> > >>>
> > >>> Glad to receive your response. I posted a reply before including some
> > >>> minds about the lock:
> > >>>
> > >>> * Separated recycle thread (more threads)
> > >>>
> > >>> or
> > >>>
> > >>> * Lock free (more memory in special conditions)
> > >>>
> > >>> It's truly a struggling job to make a decision and we can do it
> > >>>
> > >>> together.
> > >>>
> > >>> For the lock-free implementation it will waste or even fail if the
> > >>> providers are fully dynamic deployed after running enough time(OOM?).
> > >>>
> > >>> best regards,
> > >>>
> > >>> Jason
> > >>>
> > >>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
> > >>>
> > >>> Hi Jason,
> > >>>
> > >>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
> > >>>
> > >>> selection) [1] today. It is an awesome implementation and I like it.
> > >>>
> > >>>
> > >>> There's one particular issue you may need to consider further is I
> > >>>
> > >>> think
> > >>>
> > >>> we should avoid synchronized block. I have drop review comments on the
> > >>>
> > >>> pull
> > >>>
> > >>> request. Would you mind to consider this further. After that, I think
> > >>>
> > >>> this
> > >>>
> > >>> change is ready to go.
> > >>>
> > >>>
> > >>> Thanks,
> > >>> -Ian.
> > >>>
> > >>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
> > >>>
> > >>> https://github.com/apache/incubator-dubbo/pull/2647>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> >

Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Ian Luo <ia...@gmail.com>.
Jason,

More comments, pls. take a look :)

Thanks,
-Ian.
On Thu, Oct 25, 2018 at 10:50 AM Jason Joo <hb...@163.com> wrote:
>
> hi, Luo
>
> Thanks for your great suggestions and PR has been updated.
>
> We need more work testing and reviewing to prevent poor performance and so on mentioned in #2578.
>
> best regards,
>
> Jason
>
> > On Oct 25, 2018, at 10:35, Ian Luo <ia...@gmail.com> wrote:
> >
> > Jason,
> >
> > I take a look at the updated pull request, and give a few suggestions.
> > I think it's on the right direction, pls. take a look.
> >
> > Thanks,
> > -Ian.
> > On Thu, Oct 25, 2018 at 10:19 AM Ian Luo <ia...@gmail.com> wrote:
> >>
> >> The data seems convincing. What's meaning of 'before patch' and 'after patch'?
> >>
> >>
> >> Thanks,
> >> -Ian.
> >> On Thu, Oct 25, 2018 at 1:17 AM Jason Joo <hb...@163.com> wrote:
> >>>
> >>> hi, king
> >>>
> >>> I think we also care about if it would cause abusing in practices of DUBBO.
> >>> The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.
> >>>
> >>> typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
> >>> -------------------
> >>> before patch:  8536
> >>> after patch:     140
> >>> @2.5.3:           141
> >>> smooth:           414
> >>>
> >>> but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
> >>> -------------------
> >>> before patch:     25002       23939         23435
> >>> after patch:        2141         2034           2033
> >>> @2.5.3:             1241         1229           1193
> >>> smooth:             2081         2231           2376
> >>>
> >>>
> >>> So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.
> >>>
> >>> Certainly it's a little geek in this case and i will be ok about our future conclusion.
> >>>
> >>>
> >>>
> >>> best regards,
> >>>
> >>> Jason
> >>>
> >>> On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
> >>>
> >>> Thanks for a good pr first.
> >>> But I think old-way is better useful.
> >>> When we need a balance, it means so much invoking occurs, so the most important point is:
> >>>
> >>> * Lightweight and Performance
> >>> Then accuracy and smoothness are not so much prior.
> >>> And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
> >>> we could not care about its change, check stage is not a key point.
> >>>
> >>>
> >>>
> >>> At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
> >>>
> >>> hi, xiu
> >>>
> >>> After some deeper research on the algorithm i found it seemed like thread-safe.
> >>>
> >>> I updated my PR and unit test on it so we can examine if it acts as expected.
> >>>
> >>> So the recycle logic I change it into an optimistic lock.
> >>>
> >>> NGINX is a single-process model which lead me to a wrong path.
> >>>
> >>>
> >>>
> >>> So it's lock-free and with memory recycler now.
> >>>
> >>> Let's check if it works correctly.
> >>>
> >>>
> >>> best regards,
> >>>
> >>> Jason
> >>>
> >>> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
> >>>
> >>> Hi, jason
> >>>
> >>> If we can have a good balance on synchronize, thread and memory, I support
> >>> the way of smooth.
> >>> We need more discussion and solutions on this issue. Looking forward to
> >>> your solutions. :)
> >>>
> >>> Thx
> >>>
> >>> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
> >>>
> >>> hi, xiu
> >>>
> >>> Good proposal.
> >>>
> >>> The old not-very-smooth RoundRobin implementation can work fine in most
> >>> conditions.
> >>> Actually it depends the number of weight.
> >>> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
> >>> simplify the weights when selecting.
> >>>
> >>>
> >>> And i have another thought about the KEY.
> >>> Now the key is defined by Method (which can make method's invocation RR).
> >>> If we change it into by Service (which the method will not be RR if its
> >>> invocations just match a round) the memory issue may looked better.
> >>>
> >>>
> >>> So what do other guys think about?
> >>>
> >>>
> >>> best regards,
> >>>
> >>> Jason
> >>>
> >>> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
> >>>
> >>> 你好,
> >>>
> >>> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
> >>> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
> >>> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
> >>>
> >>> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
> >>>
> >>>
> >>>
> >>> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
> >>>
> >>>
> >>> 谢谢。
> >>>
> >>> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
> >>>
> >>> hi, Luo
> >>>
> >>> Glad to receive your response. I posted a reply before including some
> >>> minds about the lock:
> >>>
> >>> * Separated recycle thread (more threads)
> >>>
> >>> or
> >>>
> >>> * Lock free (more memory in special conditions)
> >>>
> >>> It's truly a struggling job to make a decision and we can do it
> >>>
> >>> together.
> >>>
> >>> For the lock-free implementation it will waste or even fail if the
> >>> providers are fully dynamic deployed after running enough time(OOM?).
> >>>
> >>> best regards,
> >>>
> >>> Jason
> >>>
> >>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
> >>>
> >>> Hi Jason,
> >>>
> >>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
> >>>
> >>> selection) [1] today. It is an awesome implementation and I like it.
> >>>
> >>>
> >>> There's one particular issue you may need to consider further is I
> >>>
> >>> think
> >>>
> >>> we should avoid synchronized block. I have drop review comments on the
> >>>
> >>> pull
> >>>
> >>> request. Would you mind to consider this further. After that, I think
> >>>
> >>> this
> >>>
> >>> change is ready to go.
> >>>
> >>>
> >>> Thanks,
> >>> -Ian.
> >>>
> >>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
> >>>
> >>> https://github.com/apache/incubator-dubbo/pull/2647>
> >>>
> >>>
> >>>
> >>>
> >>>
>

Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Jason Joo <hb...@163.com>.
hi, Luo

Thanks for your great suggestions and PR has been updated.

We need more work testing and reviewing to prevent poor performance and so on mentioned in #2578.

best regards,

Jason

> On Oct 25, 2018, at 10:35, Ian Luo <ia...@gmail.com> wrote:
> 
> Jason,
> 
> I take a look at the updated pull request, and give a few suggestions.
> I think it's on the right direction, pls. take a look.
> 
> Thanks,
> -Ian.
> On Thu, Oct 25, 2018 at 10:19 AM Ian Luo <ia...@gmail.com> wrote:
>> 
>> The data seems convincing. What's meaning of 'before patch' and 'after patch'?
>> 
>> 
>> Thanks,
>> -Ian.
>> On Thu, Oct 25, 2018 at 1:17 AM Jason Joo <hb...@163.com> wrote:
>>> 
>>> hi, king
>>> 
>>> I think we also care about if it would cause abusing in practices of DUBBO.
>>> The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.
>>> 
>>> typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
>>> -------------------
>>> before patch:  8536
>>> after patch:     140
>>> @2.5.3:           141
>>> smooth:           414
>>> 
>>> but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
>>> -------------------
>>> before patch:     25002       23939         23435
>>> after patch:        2141         2034           2033
>>> @2.5.3:             1241         1229           1193
>>> smooth:             2081         2231           2376
>>> 
>>> 
>>> So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.
>>> 
>>> Certainly it's a little geek in this case and i will be ok about our future conclusion.
>>> 
>>> 
>>> 
>>> best regards,
>>> 
>>> Jason
>>> 
>>> On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
>>> 
>>> Thanks for a good pr first.
>>> But I think old-way is better useful.
>>> When we need a balance, it means so much invoking occurs, so the most important point is:
>>> 
>>> * Lightweight and Performance
>>> Then accuracy and smoothness are not so much prior.
>>> And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
>>> we could not care about its change, check stage is not a key point.
>>> 
>>> 
>>> 
>>> At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
>>> 
>>> hi, xiu
>>> 
>>> After some deeper research on the algorithm i found it seemed like thread-safe.
>>> 
>>> I updated my PR and unit test on it so we can examine if it acts as expected.
>>> 
>>> So the recycle logic I change it into an optimistic lock.
>>> 
>>> NGINX is a single-process model which lead me to a wrong path.
>>> 
>>> 
>>> 
>>> So it's lock-free and with memory recycler now.
>>> 
>>> Let's check if it works correctly.
>>> 
>>> 
>>> best regards,
>>> 
>>> Jason
>>> 
>>> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
>>> 
>>> Hi, jason
>>> 
>>> If we can have a good balance on synchronize, thread and memory, I support
>>> the way of smooth.
>>> We need more discussion and solutions on this issue. Looking forward to
>>> your solutions. :)
>>> 
>>> Thx
>>> 
>>> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
>>> 
>>> hi, xiu
>>> 
>>> Good proposal.
>>> 
>>> The old not-very-smooth RoundRobin implementation can work fine in most
>>> conditions.
>>> Actually it depends the number of weight.
>>> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
>>> simplify the weights when selecting.
>>> 
>>> 
>>> And i have another thought about the KEY.
>>> Now the key is defined by Method (which can make method's invocation RR).
>>> If we change it into by Service (which the method will not be RR if its
>>> invocations just match a round) the memory issue may looked better.
>>> 
>>> 
>>> So what do other guys think about?
>>> 
>>> 
>>> best regards,
>>> 
>>> Jason
>>> 
>>> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
>>> 
>>> 你好,
>>> 
>>> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
>>> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
>>> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
>>> 
>>> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
>>> 
>>> 
>>> 
>>> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
>>> 
>>> 
>>> 谢谢。
>>> 
>>> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
>>> 
>>> hi, Luo
>>> 
>>> Glad to receive your response. I posted a reply before including some
>>> minds about the lock:
>>> 
>>> * Separated recycle thread (more threads)
>>> 
>>> or
>>> 
>>> * Lock free (more memory in special conditions)
>>> 
>>> It's truly a struggling job to make a decision and we can do it
>>> 
>>> together.
>>> 
>>> For the lock-free implementation it will waste or even fail if the
>>> providers are fully dynamic deployed after running enough time(OOM?).
>>> 
>>> best regards,
>>> 
>>> Jason
>>> 
>>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
>>> 
>>> Hi Jason,
>>> 
>>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
>>> 
>>> selection) [1] today. It is an awesome implementation and I like it.
>>> 
>>> 
>>> There's one particular issue you may need to consider further is I
>>> 
>>> think
>>> 
>>> we should avoid synchronized block. I have drop review comments on the
>>> 
>>> pull
>>> 
>>> request. Would you mind to consider this further. After that, I think
>>> 
>>> this
>>> 
>>> change is ready to go.
>>> 
>>> 
>>> Thanks,
>>> -Ian.
>>> 
>>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
>>> 
>>> https://github.com/apache/incubator-dubbo/pull/2647>
>>> 
>>> 
>>> 
>>> 
>>> 


Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Ian Luo <ia...@gmail.com>.
Jason,

I take a look at the updated pull request, and give a few suggestions.
I think it's on the right direction, pls. take a look.

Thanks,
-Ian.
On Thu, Oct 25, 2018 at 10:19 AM Ian Luo <ia...@gmail.com> wrote:
>
> The data seems convincing. What's meaning of 'before patch' and 'after patch'?
>
>
> Thanks,
> -Ian.
> On Thu, Oct 25, 2018 at 1:17 AM Jason Joo <hb...@163.com> wrote:
> >
> > hi, king
> >
> > I think we also care about if it would cause abusing in practices of DUBBO.
> > The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.
> >
> > typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
> > -------------------
> > before patch:  8536
> > after patch:     140
> > @2.5.3:           141
> > smooth:           414
> >
> > but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
> > -------------------
> > before patch:     25002       23939         23435
> > after patch:        2141         2034           2033
> > @2.5.3:             1241         1229           1193
> > smooth:             2081         2231           2376
> >
> >
> > So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.
> >
> > Certainly it's a little geek in this case and i will be ok about our future conclusion.
> >
> >
> >
> > best regards,
> >
> > Jason
> >
> > On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
> >
> > Thanks for a good pr first.
> > But I think old-way is better useful.
> > When we need a balance, it means so much invoking occurs, so the most important point is:
> >
> > * Lightweight and Performance
> > Then accuracy and smoothness are not so much prior.
> > And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
> > we could not care about its change, check stage is not a key point.
> >
> >
> >
> > At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
> >
> > hi, xiu
> >
> > After some deeper research on the algorithm i found it seemed like thread-safe.
> >
> > I updated my PR and unit test on it so we can examine if it acts as expected.
> >
> > So the recycle logic I change it into an optimistic lock.
> >
> > NGINX is a single-process model which lead me to a wrong path.
> >
> >
> >
> > So it's lock-free and with memory recycler now.
> >
> > Let's check if it works correctly.
> >
> >
> > best regards,
> >
> > Jason
> >
> > On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
> >
> > Hi, jason
> >
> > If we can have a good balance on synchronize, thread and memory, I support
> > the way of smooth.
> > We need more discussion and solutions on this issue. Looking forward to
> > your solutions. :)
> >
> > Thx
> >
> > Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
> >
> > hi, xiu
> >
> > Good proposal.
> >
> > The old not-very-smooth RoundRobin implementation can work fine in most
> > conditions.
> > Actually it depends the number of weight.
> > That means 500:500:500 will be quite different from 1:1:1 and maybe we can
> > simplify the weights when selecting.
> >
> >
> > And i have another thought about the KEY.
> > Now the key is defined by Method (which can make method's invocation RR).
> > If we change it into by Service (which the method will not be RR if its
> > invocations just match a round) the memory issue may looked better.
> >
> >
> > So what do other guys think about?
> >
> >
> > best regards,
> >
> > Jason
> >
> > On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
> >
> > 你好,
> >
> > 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
> > 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
> > 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
> >
> > 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
> >
> >
> >
> > 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
> >
> >
> > 谢谢。
> >
> > Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
> >
> > hi, Luo
> >
> > Glad to receive your response. I posted a reply before including some
> > minds about the lock:
> >
> > * Separated recycle thread (more threads)
> >
> > or
> >
> > * Lock free (more memory in special conditions)
> >
> > It's truly a struggling job to make a decision and we can do it
> >
> > together.
> >
> > For the lock-free implementation it will waste or even fail if the
> > providers are fully dynamic deployed after running enough time(OOM?).
> >
> > best regards,
> >
> > Jason
> >
> > On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
> >
> > Hi Jason,
> >
> > I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
> >
> > selection) [1] today. It is an awesome implementation and I like it.
> >
> >
> > There's one particular issue you may need to consider further is I
> >
> > think
> >
> > we should avoid synchronized block. I have drop review comments on the
> >
> > pull
> >
> > request. Would you mind to consider this further. After that, I think
> >
> > this
> >
> > change is ready to go.
> >
> >
> > Thanks,
> > -Ian.
> >
> > 1. https://github.com/apache/incubator-dubbo/pull/2647 <
> >
> > https://github.com/apache/incubator-dubbo/pull/2647>
> >
> >
> >
> >
> >

Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Ian Luo <ia...@gmail.com>.
The data seems convincing. What's meaning of 'before patch' and 'after patch'?


Thanks,
-Ian.
On Thu, Oct 25, 2018 at 1:17 AM Jason Joo <hb...@163.com> wrote:
>
> hi, king
>
> I think we also care about if it would cause abusing in practices of DUBBO.
> The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.
>
> typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
> -------------------
> before patch:  8536
> after patch:     140
> @2.5.3:           141
> smooth:           414
>
> but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
> -------------------
> before patch:     25002       23939         23435
> after patch:        2141         2034           2033
> @2.5.3:             1241         1229           1193
> smooth:             2081         2231           2376
>
>
> So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.
>
> Certainly it's a little geek in this case and i will be ok about our future conclusion.
>
>
>
> best regards,
>
> Jason
>
> On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
>
> Thanks for a good pr first.
> But I think old-way is better useful.
> When we need a balance, it means so much invoking occurs, so the most important point is:
>
> * Lightweight and Performance
> Then accuracy and smoothness are not so much prior.
> And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
> we could not care about its change, check stage is not a key point.
>
>
>
> At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
>
> hi, xiu
>
> After some deeper research on the algorithm i found it seemed like thread-safe.
>
> I updated my PR and unit test on it so we can examine if it acts as expected.
>
> So the recycle logic I change it into an optimistic lock.
>
> NGINX is a single-process model which lead me to a wrong path.
>
>
>
> So it's lock-free and with memory recycler now.
>
> Let's check if it works correctly.
>
>
> best regards,
>
> Jason
>
> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
>
> Hi, jason
>
> If we can have a good balance on synchronize, thread and memory, I support
> the way of smooth.
> We need more discussion and solutions on this issue. Looking forward to
> your solutions. :)
>
> Thx
>
> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
>
> hi, xiu
>
> Good proposal.
>
> The old not-very-smooth RoundRobin implementation can work fine in most
> conditions.
> Actually it depends the number of weight.
> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
> simplify the weights when selecting.
>
>
> And i have another thought about the KEY.
> Now the key is defined by Method (which can make method's invocation RR).
> If we change it into by Service (which the method will not be RR if its
> invocations just match a round) the memory issue may looked better.
>
>
> So what do other guys think about?
>
>
> best regards,
>
> Jason
>
> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
>
> 你好,
>
> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
>
> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
>
>
>
> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
>
>
> 谢谢。
>
> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
>
> hi, Luo
>
> Glad to receive your response. I posted a reply before including some
> minds about the lock:
>
> * Separated recycle thread (more threads)
>
> or
>
> * Lock free (more memory in special conditions)
>
> It's truly a struggling job to make a decision and we can do it
>
> together.
>
> For the lock-free implementation it will waste or even fail if the
> providers are fully dynamic deployed after running enough time(OOM?).
>
> best regards,
>
> Jason
>
> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
>
> Hi Jason,
>
> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
>
> selection) [1] today. It is an awesome implementation and I like it.
>
>
> There's one particular issue you may need to consider further is I
>
> think
>
> we should avoid synchronized block. I have drop review comments on the
>
> pull
>
> request. Would you mind to consider this further. After that, I think
>
> this
>
> change is ready to go.
>
>
> Thanks,
> -Ian.
>
> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
>
> https://github.com/apache/incubator-dubbo/pull/2647>
>
>
>
>
>

Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Jason Joo <hb...@163.com>.
hi, king

I think we also care about if it would cause abusing in practices of DUBBO.
The smooth version is at least twenty times faster compared with implementation of 2.6.x, and more smooth and make sense compared with implementation of 2.5.3. Actually it maybe about up to three times cost compared with recently correction.

typically cost(1000, 000 loops, simplified code, in milliseconds, single thread):
-------------------
before patch:  8536
after patch:     140
@2.5.3:           141
smooth:           414

but things changed in multi-thread condition(10 threads, using strict condition inner thread to begin loops):
-------------------
before patch:     25002       23939         23435
after patch:        2141         2034           2033
@2.5.3:             1241         1229           1193
smooth:             2081         2231           2376


So they are more or less in multi threaded environment due to some local object trade off.  Test code is in attachment.

Certainly it's a little geek in this case and i will be ok about our future conclusion.




best regards,

Jason

> On Oct 24, 2018, at 23:17, KimmKing <ki...@apache.org> wrote:
> 
> Thanks for a good pr first.
> But I think old-way is better useful.
> When we need a balance, it means so much invoking occurs, so the most important point is:
> 
> * Lightweight and Performance
> Then accuracy and smoothness are not so much prior.
> And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
> we could not care about its change, check stage is not a key point.
> 
> 
> 
> At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
>> hi, xiu
>> 
>> After some deeper research on the algorithm i found it seemed like thread-safe.
>> 
>> I updated my PR and unit test on it so we can examine if it acts as expected.
>> 
>> So the recycle logic I change it into an optimistic lock.
>> 
>> NGINX is a single-process model which lead me to a wrong path.
>> 
>> 
>> 
>> So it's lock-free and with memory recycler now.
>> 
>> Let's check if it works correctly.
>> 
>> 
>> best regards,
>> 
>> Jason
>> 
>>> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
>>> 
>>> Hi, jason
>>> 
>>> If we can have a good balance on synchronize, thread and memory, I support
>>> the way of smooth.
>>> We need more discussion and solutions on this issue. Looking forward to
>>> your solutions. :)
>>> 
>>> Thx
>>> 
>>> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
>>> 
>>>> hi, xiu
>>>> 
>>>> Good proposal.
>>>> 
>>>> The old not-very-smooth RoundRobin implementation can work fine in most
>>>> conditions.
>>>> Actually it depends the number of weight.
>>>> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
>>>> simplify the weights when selecting.
>>>> 
>>>> 
>>>> And i have another thought about the KEY.
>>>> Now the key is defined by Method (which can make method's invocation RR).
>>>> If we change it into by Service (which the method will not be RR if its
>>>> invocations just match a round) the memory issue may looked better.
>>>> 
>>>> 
>>>> So what do other guys think about?
>>>> 
>>>> 
>>>> best regards,
>>>> 
>>>> Jason
>>>> 
>>>>> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
>>>>> 
>>>>> 你好,
>>>>> 
>>>>> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
>>>>> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
>>>>> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
>>>>> 
>>>> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
>>>>> 
>>>>> 
>>>> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
>>>>> 
>>>>> 谢谢。
>>>>> 
>>>>> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
>>>>> 
>>>>>> hi, Luo
>>>>>> 
>>>>>> Glad to receive your response. I posted a reply before including some
>>>>>> minds about the lock:
>>>>>> 
>>>>>> * Separated recycle thread (more threads)
>>>>>> 
>>>>>> or
>>>>>> 
>>>>>> * Lock free (more memory in special conditions)
>>>>>> 
>>>>>> It's truly a struggling job to make a decision and we can do it
>>>> together.
>>>>>> For the lock-free implementation it will waste or even fail if the
>>>>>> providers are fully dynamic deployed after running enough time(OOM?).
>>>>>> 
>>>>>> best regards,
>>>>>> 
>>>>>> Jason
>>>>>> 
>>>>>>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
>>>>>>> 
>>>>>>> Hi Jason,
>>>>>>> 
>>>>>>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
>>>>>> selection) [1] today. It is an awesome implementation and I like it.
>>>>>>> 
>>>>>>> There's one particular issue you may need to consider further is I
>>>> think
>>>>>> we should avoid synchronized block. I have drop review comments on the
>>>> pull
>>>>>> request. Would you mind to consider this further. After that, I think
>>>> this
>>>>>> change is ready to go.
>>>>>>> 
>>>>>>> Thanks,
>>>>>>> -Ian.
>>>>>>> 
>>>>>>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
>>>>>> https://github.com/apache/incubator-dubbo/pull/2647>
>>>>>> 
>>>> 
>>>> 
>> 


Re:Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by KimmKing <ki...@apache.org>.
Thanks for a good pr first.
But I think old-way is better useful.
When we need a balance, it means so much invoking occurs, so the most important point is:

* Lightweight and Performance
Then accuracy and smoothness are not so much prior.
And actually nobody would have more than 100 providers for a single service, so the number of invokers is small,
we could not care about its change, check stage is not a key point.



At 2018-10-24 17:48:31, "Jason Joo" <hb...@163.com> wrote:
>hi, xiu
>
>After some deeper research on the algorithm i found it seemed like thread-safe.
>
>I updated my PR and unit test on it so we can examine if it acts as expected.
>
>So the recycle logic I change it into an optimistic lock.
>
>NGINX is a single-process model which lead me to a wrong path.
>
>
>
>So it's lock-free and with memory recycler now.
>
>Let's check if it works correctly.
>
>
>best regards,
>
>Jason
>
>> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
>> 
>> Hi, jason
>> 
>> If we can have a good balance on synchronize, thread and memory, I support
>> the way of smooth.
>> We need more discussion and solutions on this issue. Looking forward to
>> your solutions. :)
>> 
>> Thx
>> 
>> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
>> 
>>> hi, xiu
>>> 
>>> Good proposal.
>>> 
>>> The old not-very-smooth RoundRobin implementation can work fine in most
>>> conditions.
>>> Actually it depends the number of weight.
>>> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
>>> simplify the weights when selecting.
>>> 
>>> 
>>> And i have another thought about the KEY.
>>> Now the key is defined by Method (which can make method's invocation RR).
>>> If we change it into by Service (which the method will not be RR if its
>>> invocations just match a round) the memory issue may looked better.
>>> 
>>> 
>>> So what do other guys think about?
>>> 
>>> 
>>> best regards,
>>> 
>>> Jason
>>> 
>>>> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
>>>> 
>>>> 你好,
>>>> 
>>>> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
>>>> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
>>>> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
>>>> 
>>> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
>>>> 
>>>> 
>>> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
>>>> 
>>>> 谢谢。
>>>> 
>>>> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
>>>> 
>>>>> hi, Luo
>>>>> 
>>>>> Glad to receive your response. I posted a reply before including some
>>>>> minds about the lock:
>>>>> 
>>>>> * Separated recycle thread (more threads)
>>>>> 
>>>>> or
>>>>> 
>>>>> * Lock free (more memory in special conditions)
>>>>> 
>>>>> It's truly a struggling job to make a decision and we can do it
>>> together.
>>>>> For the lock-free implementation it will waste or even fail if the
>>>>> providers are fully dynamic deployed after running enough time(OOM?).
>>>>> 
>>>>> best regards,
>>>>> 
>>>>> Jason
>>>>> 
>>>>>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
>>>>>> 
>>>>>> Hi Jason,
>>>>>> 
>>>>>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
>>>>> selection) [1] today. It is an awesome implementation and I like it.
>>>>>> 
>>>>>> There's one particular issue you may need to consider further is I
>>> think
>>>>> we should avoid synchronized block. I have drop review comments on the
>>> pull
>>>>> request. Would you mind to consider this further. After that, I think
>>> this
>>>>> change is ready to go.
>>>>>> 
>>>>>> Thanks,
>>>>>> -Ian.
>>>>>> 
>>>>>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
>>>>> https://github.com/apache/incubator-dubbo/pull/2647>
>>>>> 
>>> 
>>> 
>

Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Jason Joo <hb...@163.com>.
hi, xiu

After some deeper research on the algorithm i found it seemed like thread-safe.

I updated my PR and unit test on it so we can examine if it acts as expected.

So the recycle logic I change it into an optimistic lock.

NGINX is a single-process model which lead me to a wrong path.



So it's lock-free and with memory recycler now.

Let's check if it works correctly.


best regards,

Jason

> On Oct 24, 2018, at 16:38, yuhang xiu <ca...@gmail.com> wrote:
> 
> Hi, jason
> 
> If we can have a good balance on synchronize, thread and memory, I support
> the way of smooth.
> We need more discussion and solutions on this issue. Looking forward to
> your solutions. :)
> 
> Thx
> 
> Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:
> 
>> hi, xiu
>> 
>> Good proposal.
>> 
>> The old not-very-smooth RoundRobin implementation can work fine in most
>> conditions.
>> Actually it depends the number of weight.
>> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
>> simplify the weights when selecting.
>> 
>> 
>> And i have another thought about the KEY.
>> Now the key is defined by Method (which can make method's invocation RR).
>> If we change it into by Service (which the method will not be RR if its
>> invocations just match a round) the memory issue may looked better.
>> 
>> 
>> So what do other guys think about?
>> 
>> 
>> best regards,
>> 
>> Jason
>> 
>>> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
>>> 
>>> 你好,
>>> 
>>> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
>>> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
>>> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
>>> 
>> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
>>> 
>>> 
>> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
>>> 
>>> 谢谢。
>>> 
>>> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
>>> 
>>>> hi, Luo
>>>> 
>>>> Glad to receive your response. I posted a reply before including some
>>>> minds about the lock:
>>>> 
>>>> * Separated recycle thread (more threads)
>>>> 
>>>> or
>>>> 
>>>> * Lock free (more memory in special conditions)
>>>> 
>>>> It's truly a struggling job to make a decision and we can do it
>> together.
>>>> For the lock-free implementation it will waste or even fail if the
>>>> providers are fully dynamic deployed after running enough time(OOM?).
>>>> 
>>>> best regards,
>>>> 
>>>> Jason
>>>> 
>>>>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
>>>>> 
>>>>> Hi Jason,
>>>>> 
>>>>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
>>>> selection) [1] today. It is an awesome implementation and I like it.
>>>>> 
>>>>> There's one particular issue you may need to consider further is I
>> think
>>>> we should avoid synchronized block. I have drop review comments on the
>> pull
>>>> request. Would you mind to consider this further. After that, I think
>> this
>>>> change is ready to go.
>>>>> 
>>>>> Thanks,
>>>>> -Ian.
>>>>> 
>>>>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
>>>> https://github.com/apache/incubator-dubbo/pull/2647>
>>>> 
>> 
>> 


Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by yuhang xiu <ca...@gmail.com>.
Hi, jason

If we can have a good balance on synchronize, thread and memory, I support
the way of smooth.
We need more discussion and solutions on this issue. Looking forward to
your solutions. :)

Thx

Jason Joo <hb...@163.com> 于2018年10月24日周三 下午4:32写道:

> hi, xiu
>
> Good proposal.
>
> The old not-very-smooth RoundRobin implementation can work fine in most
> conditions.
> Actually it depends the number of weight.
> That means 500:500:500 will be quite different from 1:1:1 and maybe we can
> simplify the weights when selecting.
>
>
> And i have another thought about the KEY.
> Now the key is defined by Method (which can make method's invocation RR).
> If we change it into by Service (which the method will not be RR if its
> invocations just match a round) the memory issue may looked better.
>
>
> So what do other guys think about?
>
>
> best regards,
>
> Jason
>
> > On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
> >
> > 你好,
> >
> > 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
> > 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
> > 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
> >
> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
> >
> >
> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
> >
> > 谢谢。
> >
> > Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
> >
> >> hi, Luo
> >>
> >> Glad to receive your response. I posted a reply before including some
> >> minds about the lock:
> >>
> >> * Separated recycle thread (more threads)
> >>
> >> or
> >>
> >> * Lock free (more memory in special conditions)
> >>
> >> It's truly a struggling job to make a decision and we can do it
> together.
> >> For the lock-free implementation it will waste or even fail if the
> >> providers are fully dynamic deployed after running enough time(OOM?).
> >>
> >> best regards,
> >>
> >> Jason
> >>
> >>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
> >>>
> >>> Hi Jason,
> >>>
> >>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
> >> selection) [1] today. It is an awesome implementation and I like it.
> >>>
> >>> There's one particular issue you may need to consider further is I
> think
> >> we should avoid synchronized block. I have drop review comments on the
> pull
> >> request. Would you mind to consider this further. After that, I think
> this
> >> change is ready to go.
> >>>
> >>> Thanks,
> >>> -Ian.
> >>>
> >>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
> >> https://github.com/apache/incubator-dubbo/pull/2647>
> >>
>
>

Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Jason Joo <hb...@163.com>.
hi, xiu

Good proposal.

The old not-very-smooth RoundRobin implementation can work fine in most conditions. 
Actually it depends the number of weight. 
That means 500:500:500 will be quite different from 1:1:1 and maybe we can simplify the weights when selecting.


And i have another thought about the KEY. 
Now the key is defined by Method (which can make method's invocation RR). If we change it into by Service (which the method will not be RR if its invocations just match a round) the memory issue may looked better.


So what do other guys think about?


best regards,

Jason

> On Oct 24, 2018, at 16:09, yuhang xiu <ca...@gmail.com> wrote:
> 
> 你好,
> 
> 我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
> 1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
> 说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
> 2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。
> 
> 综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。
> 
> 谢谢。
> 
> Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:
> 
>> hi, Luo
>> 
>> Glad to receive your response. I posted a reply before including some
>> minds about the lock:
>> 
>> * Separated recycle thread (more threads)
>> 
>> or
>> 
>> * Lock free (more memory in special conditions)
>> 
>> It's truly a struggling job to make a decision and we can do it together.
>> For the lock-free implementation it will waste or even fail if the
>> providers are fully dynamic deployed after running enough time(OOM?).
>> 
>> best regards,
>> 
>> Jason
>> 
>>> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
>>> 
>>> Hi Jason,
>>> 
>>> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
>> selection) [1] today. It is an awesome implementation and I like it.
>>> 
>>> There's one particular issue you may need to consider further is I think
>> we should avoid synchronized block. I have drop review comments on the pull
>> request. Would you mind to consider this further. After that, I think this
>> change is ready to go.
>>> 
>>> Thanks,
>>> -Ian.
>>> 
>>> 1. https://github.com/apache/incubator-dubbo/pull/2647 <
>> https://github.com/apache/incubator-dubbo/pull/2647>
>> 


Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Ian Luo <ia...@gmail.com>.
I think we should look further if it is possible to make it lock free
based on the current implementation.

Jason, we can work together :)

-Ian.

google translation:
>
>
> I personally think we should make a trade-off between smooth and performance. I personally tend to use a non-smooth way, for the following reasons:
> 1. Using smooth requires increasing thread overhead or increasing memory overhead, or using locks to increase performance overhead, like @jason
> That said. And load balancing itself is a very lightweight component. Do we need to make him so complicated?
> 2. I admit that the smooth way is better, but if we set the weight of a provider to a specific value, then it means that it can withstand the corresponding request amount, whether N requests are performed simultaneously or separately. If the provider can't afford to make N requests at the same time, what we need to do is to lower his weight.
> In summary, I personally think that the current implementation of smooth is not very good, we can not achieve a very good balance in locks, threads and memory. So I think you can not use the way of smooth.
> Thank you.<br><div class="gmail_quote"><div dir="ltr">On Wed, Oct 24, 2018 at 4:09 PM yuhang xiu &lt;carryxyh@gmail.com&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">你好,<br>
<br>
我个人认为我们应该在smooth和性能之间做一个取舍。我个人<wbr>倾向于使用非smooth的方式,原因:<br>
1.使用smooth需要增加线程开销或者增加内存开销,或者用<wbr>锁来增加了性能开销,就像 @jason<br>
说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把<wbr>他做的这么复杂?<br>
2.我承认smooth的方式更好,但是如果我们把一个prov<wbr>ider的权重设置为特定的值,那么说明他能承受相应的请求量,<wbr>不管是N个请求同时进行还是分开进行。如果这个provider<wbr>承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。<br>
<br>
综上,我个人认为,当前的smooth实现方式不是很理想,我们<wbr>没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可<wbr>以不使用smooth的方式。<br>
<br>
谢谢。<br>
<br>
Jason Joo &lt;<a href="mailto:hblzxsj@gmail.com"
target="_blank">hblzxsj@gmail.com</a>&gt; 于2018年10月24日周三 下午3:57写道:<br>
<br>
&gt; hi, Luo<br>
&gt;<br>
&gt; Glad to receive your response. I posted a reply before including some<br>
&gt; minds about the lock:<br>
&gt;<br>
&gt; * Separated recycle thread (more threads)<br>
&gt;<br>
&gt; or<br>
&gt;<br>
&gt; * Lock free (more memory in special conditions)<br>
&gt;<br>
&gt; It&#39;s truly a struggling job to make a decision and we can do
it together.<br>
&gt; For the lock-free implementation it will waste or even fail if the<br>
&gt; providers are fully dynamic deployed after running enough time(OOM?).<br>
&gt;<br>
&gt; best regards,<br>
&gt;<br>
&gt; Jason<br>
&gt;<br>
&gt; &gt; On Oct 24, 2018, at 14:50, Ian Luo &lt;<a
href="mailto:ian.luo@gmail.com"
target="_blank">ian.luo@gmail.com</a>&gt; wrote:<br>
&gt; &gt;<br>
&gt; &gt; Hi Jason,<br>
&gt; &gt;<br>
&gt; &gt; I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin<br>
&gt; selection) [1] today. It is an awesome implementation and I like it.<br>
&gt; &gt;<br>
&gt; &gt; There&#39;s one particular issue you may need to consider
further is I think<br>
&gt; we should avoid synchronized block. I have drop review comments
on the pull<br>
&gt; request. Would you mind to consider this further. After that, I
think this<br>
&gt; change is ready to go.<br>
&gt; &gt;<br>
&gt; &gt; Thanks,<br>
&gt; &gt; -Ian.<br>
&gt; &gt;<br>
&gt; &gt; 1. <a
href="https://github.com/apache/incubator-dubbo/pull/2647"
rel="noreferrer" target="_blank"
data-saferedirecturl="https://www.google.com/url?q=https://github.com/apache/incubator-dubbo/pull/2647&amp;source=gmail&amp;ust=1540456071989000&amp;usg=AFQjCNHutzo51zebXQPaJHsXykPdWBWQHA">https://github.com/apache/incu<wbr>bator-dubbo/pull/2647</a>
&lt;<br>
&gt; <a href="https://github.com/apache/incubator-dubbo/pull/2647"
rel="noreferrer" target="_blank"
data-saferedirecturl="https://www.google.com/url?q=https://github.com/apache/incubator-dubbo/pull/2647&amp;source=gmail&amp;ust=1540456071989000&amp;usg=AFQjCNHutzo51zebXQPaJHsXykPdWBWQHA">https://github.com/apache/incu<wbr>bator-dubbo/pull/2647</a>&gt;<br>
&gt;<br>
</blockquote></div>

Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by yuhang xiu <ca...@gmail.com>.
你好,

我个人认为我们应该在smooth和性能之间做一个取舍。我个人倾向于使用非smooth的方式,原因:
1.使用smooth需要增加线程开销或者增加内存开销,或者用锁来增加了性能开销,就像 @jason
说的那样。而本身负载均衡是一个很轻量的组件,我们是否有必要把他做的这么复杂?
2.我承认smooth的方式更好,但是如果我们把一个provider的权重设置为特定的值,那么说明他能承受相应的请求量,不管是N个请求同时进行还是分开进行。如果这个provider承受不住同时进行N个请求,我们需要做的应该是把他的权重调低。

综上,我个人认为,当前的smooth实现方式不是很理想,我们没法在锁、线程和内存上都达到一个非常优秀的平衡。所以我认为可以不使用smooth的方式。

谢谢。

Jason Joo <hb...@gmail.com> 于2018年10月24日周三 下午3:57写道:

> hi, Luo
>
> Glad to receive your response. I posted a reply before including some
> minds about the lock:
>
> * Separated recycle thread (more threads)
>
> or
>
> * Lock free (more memory in special conditions)
>
> It's truly a struggling job to make a decision and we can do it together.
> For the lock-free implementation it will waste or even fail if the
> providers are fully dynamic deployed after running enough time(OOM?).
>
> best regards,
>
> Jason
>
> > On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
> >
> > Hi Jason,
> >
> > I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin
> selection) [1] today. It is an awesome implementation and I like it.
> >
> > There's one particular issue you may need to consider further is I think
> we should avoid synchronized block. I have drop review comments on the pull
> request. Would you mind to consider this further. After that, I think this
> change is ready to go.
> >
> > Thanks,
> > -Ian.
> >
> > 1. https://github.com/apache/incubator-dubbo/pull/2647 <
> https://github.com/apache/incubator-dubbo/pull/2647>
>

Re: pull request #2647: [Dubbo-2578]Smooth Round Robin selection

Posted by Jason Joo <hb...@gmail.com>.
hi, Luo

Glad to receive your response. I posted a reply before including some minds about the lock: 

* Separated recycle thread (more threads)

or

* Lock free (more memory in special conditions)

It's truly a struggling job to make a decision and we can do it together.
For the lock-free implementation it will waste or even fail if the providers are fully dynamic deployed after running enough time(OOM?).

best regards,

Jason

> On Oct 24, 2018, at 14:50, Ian Luo <ia...@gmail.com> wrote:
> 
> Hi Jason,
> 
> I reviewed your pull request 2647 ( [Dubbo-2578]Smooth Round Robin selection) [1] today. It is an awesome implementation and I like it. 
> 
> There's one particular issue you may need to consider further is I think we should avoid synchronized block. I have drop review comments on the pull request. Would you mind to consider this further. After that, I think this change is ready to go.
> 
> Thanks,
> -Ian.
> 
> 1. https://github.com/apache/incubator-dubbo/pull/2647 <https://github.com/apache/incubator-dubbo/pull/2647>