You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Xiaoli Ding (JIRA)" <ji...@apache.org> on 2012/08/21 10:39:37 UTC

[jira] [Updated] (CAMEL-5525) Load balancing with “Random” policy is not halfway evenly distributed to endPoint with vast exchange

     [ https://issues.apache.org/jira/browse/CAMEL-5525?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Xiaoli Ding updated CAMEL-5525:
-------------------------------

    Summary: Load balancing with “Random” policy is not halfway evenly distributed to endPoint with vast exchange   (was: Load balancing with“Random” policy is not halfway evenly distributed to endPoint with vast exchange )
    
> Load balancing with “Random” policy is not halfway evenly distributed to endPoint with vast exchange 
> -----------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-5525
>                 URL: https://issues.apache.org/jira/browse/CAMEL-5525
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>            Reporter: Xiaoli Ding
>            Priority: Minor
>
> Look the code about choosing processor in camel: http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/loadbalancer/RandomLoadBalancer.html
> {noformat} 
>  protected synchronized Processor chooseProcessor(List<Processor> processors, Exchange exchange) {
>         int size = processors.size();
>         while (true) {
>             int index = (int) Math.round(Math.random() * size);
>             if (index < size) {
>                 return processors.get(index);
>             }
>         }
> }
> {noformat} 
> For example, processors.size() = 3,
> so, Math.random() * size = 0.0 .. 3.0,
> So, index is either 0, or 1, or 2, or 3,
> so there is four variants, while we are looking for three variants.
> and, variant "3" is then thrown away in "if" comparison and re-selected.that is a source of uneveningness.when there are vast message exchange, the load radio for three endpoints are approach to 20%,40%,40%. it is unreasonable radio,should approach 33% allowing the amount of time difference for each endpoint. 
> For the above code, can replace "int index = (int) Math.round(Math.random() * size)" with "int index = (int)Math.ceil(Math.random() * 3 - 1)"

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira