Writing Customized Load Balancing Algorithm
In a cluster environment, Logi Report Server provides a load balancing mechanism which enables the server to work more effectively. You can also write your own load balancing algorithm based on the API included in Logi Report Server. Note that if you create a load balancing algorithm via API, it will take effect in place of other built-in load balance algorithms you have set. For detailed usage about the API, refer to the jet.server.api.cluster.LoadBalancer interface in the Logi Report Javadoc.
The demo file DemoLoadBalancer.java is provided to show how to customize load balancing using API. You can find it in
Assuming that you have several clustered servers, take the following steps to apply customized load balancing algorithm:
- Compile DemoLoadBalancer.java to generate the class file as follows (when compiling DemoLoadBalancer.java, you need to add JRESServlets.jar to the class path):
javac -classpath <install_root>\lib\JRESServlets.jar DemoLoadBalancer.java
- Add DemoLoadBalancer.class to the class path of setenv.bat in the ADDCLASSPATH variable.
- Add the parameter
-Dloadbalance.custom_class=DemoLoadBalancerto the server's startup file JRServer.bat which locates in
<install_root>\bin. For example:
"%JAVAHOME%\bin\java.exe" -Dloadbalance.custom_class=DemoLoadBalancer "-Dinstall.root=%REPORTHOME%" ...
- Launch JRServer.bat, the customized load balancer DemoLoadBalancer will then be applied.
- Submit some tasks for running. You can now find that these tasks are allocated to the clustered servers based on the DemoLoadBalancer code.
Tip: You can choose the load balancing type by setting the API method setLoadBalanceType() in jet.server.api.admin.ClusterAdminService. For example, setting the API method as setLoadBalanceType(0), setLoadBalanceType(1), setLoadBalanceType(2), and setLoadBalanceType(3) means respectively the algorithm Least Current Reports (Min-load), Round Robin, Least Weighted Current Reports (Weighted Min-load) and Random will be chosen.
Please sign in to leave a comment.