Clustered Helloworld-cluster application

We will now look at the configuration needed so that the two instances of the helloworld-cluster application available at http://localhost:8080/helloworld-cluster/ and http://localhost:8090/helloworld-cluster/ are served as one logical application, by using Apache web server, the mod_jk module, and AJP connectors in Geronimo.

Updating workers.properties

To use the server instance inst2 with mod_jk, we will need to create another worker similar to geronimo_ajp13 in workers.properties. This second worker will point to the AJP connector in inst2. The configuration is as given below:

worker.list=geronimo_inst2_ajp13
worker.geronimo_inst2_ajp13.port=8019
worker.geronimo_inst2_ajp13.host=localhost
worker.geronimo_inst2_ajp13.type=ajp13

Add this configuration to workers.properties.

The two workers geronimo_ajp13 and geronimo_inst2_ajp13 are of type ajp13. Now create another worker of type lb to balance the load between geronimo_ajp13 and geronimo_inst2_ajp13, as given below:

worker.list=loadbalancer
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=geronimo_ajp13,geronimo_inst2_ajp13

You can use the lbfactor property to specify the how the load should be distributed between the workers. The load balancing factor is compared with other workers that comprise the load balancer. For example, if one worker has lb_factor twice as high as compared to the other worker, then it will receive twice as many requests. The configuration is given below:

worker.geronimo_ajp13.lbfactor=2
worker.geronimo_inst2_ajp13.lbfactor=1

Here, geronimo_ajp13, that is, the default instance, will receive twice the number of requests of geronimo_inst2_ajp13, that is, instance inst2.

You can also enable sticky sessions by setting the sticky_session property of loadbalancer to True. Enabling a sticky session ties a user session to a particular server instance such that subsequent requests are routed to the same instance, thus eliminating the need for session replication. If the server instance serving the request goes down, then any data stored in the session will be lost. The configuration for enabling sticky session is given below:

worker.loadbalancer.sticky_session=True

See http://tomcat.apache.org/connectors-doc/reference/workers.html for complete configuration options for workers.properties.

Now update the JkMount directive for /helloworld-cluster/* in httpd.conf to use the loadbalancer worker instead of geronimo_apj13. The configuration to do this is given below:

JkMount /helloworld-cluster/* loadbalancer

Restart the Apache web server so that the configuration changes take effect. The helloworld-clustered application is now clustered with two nodes. Access the application at http://localhost/helloworld-cluster/. Enter a name, and click on getGreeting. The application screen is shown in the following screenshot.

In this screen, notice the server.name value , which can be used to identify the Geronimo server instance that served the request, and stop that server instance. Now refresh or reload the page in the browser to display a screen similar to the one shown in the following screenshot:

Notice that the request is now served by the other running server instance, and the counter value is incremented, indicating that the session state has been replicated to the second server instance.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset