0

I'm facing up to the load balance algorithm implementation for customizing the load balance endpoint.

On this documentation page: http://docs.wso2.org/display/ESB470/Load-balance+Endpoint

I read:

Algorithm - Either a default "Round-robin" or custom loaded algorithm of the group. See more information about this algorithm in the article.

Where "article" is a link point to this page:

http://supunk.blogspot.it/2010/02/writing-load-balance-algorithm-for-wso2.html

But the referred article is not complete and doesn't tell anything about the algorithm development. Could anyone give me a valid example?

Community
  • 1
  • 1
Alex
  • 1,515
  • 2
  • 22
  • 44

3 Answers3

2

You can use below sample to send multiple request to share between diffent endpoint using RoundRobin algo.

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="TestLoadBalance"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <endpoint>
         <loadbalance algorithm="org.apache.synapse.endpoints.algorithms.RoundRobin">
            <endpoint>
               <address uri="http://localhost:9000/services/SimpleStockQuoteService/"/>
            </endpoint>
            <endpoint>
               <address uri="http://localhost:9001/services/SimpleStockQuoteService/"/>
            </endpoint>
            <endpoint>
               <address uri="http://localhost:9002/services/SimpleStockQuoteService/"/>
            </endpoint>
         </loadbalance>
      </endpoint>
   </target>
   <description/>
</proxy>
jayalalk
  • 2,382
  • 3
  • 17
  • 14
  • Thanks, i've already tried it and it works. But would like to have the possibility to write my own load balance algorithm and, working with dynamic load balance endpoint too, my own loadbalancehandlermembership. I know it's an interface and that there are 2 implementations: the Axis and the Service one. But is there any tutorial explaining step by step how they can be implemented? – Alex Nov 25 '13 at 13:27
  • Please see the implemenation of weighted algorithm, so you can follow same http://grepcode.com/file/repo1.maven.org/maven2/org.apache.synapse/synapse-core/2.1.0/org/apache/synapse/endpoints/algorithms/WeightedRoundRobin.java ) – jayalalk Nov 26 '13 at 04:52
0

As the documentation specifies, the algorithm should be an implementation of org.apache.synapse.endpoints.algorithms.LoadbalanceAlgorithm

You need to write a class implementing LoadbalanceAlgorithm interface. You can refer the existing implementations RoundRobin, WeightedRRLCAlgorithm and WeightedRoundRobin classes found in org.apache.synapse.endpoints.algorithms package.

Then create a jar file with your class and add it to <ESB_HOME>/repository/components/lib folder and restart the server.

Now when adding a Load Balance Endpoint, select Other... for the Algorithm and provide the full classname of your custom algorithm. For example: org.apache.synapse.endpoints.algorithms.WeightedRoundRobin

Nufail
  • 1,588
  • 1
  • 17
  • 31
0

Looking at LoadBalanceAlgortihm it's not possibile to simply give it a dynamic list of endpoint. Concerning LoadBalanceMambershipHandler and its implementation (Axis2 and Service)...it uses object like:

org.apache.axis2.clustering.management.GroupManagementAgent
and
org.apache.axis2.clustering.ClusteringAgent

so you have to configure your nodes in cluster using the axi2.xml inside /repository/conf/axis2 folder of your ESB. Use the ESB registry to save the loadbalance enpoint in and then access it by code for adding it a new list of address endpoint.

Alex
  • 1,515
  • 2
  • 22
  • 44