Load-balancer demo script

Prerequisite

Cluster setup
  • Setup cluster as per your requirement. Refer to ssh demo script for more details.
  • User can create standalone instance(s) instead of cluster(s) and front-end them with load-balancer. However there cannot be a mix of cluster(s) and stand-alone instance(s).
  • Install web-server and configure load-balancer plugin. Refer to GlassFish v2 documentation for more details.
  • Create a SSL listener in web-server and enable client certificate authentication for that listener. This step is needed in case you want to use command apply-http-lb-changes.

MS4 Demo : Preferred failover instance feature

  • Deploy an application across cluster. Application used for demo - SimpleWebApp.war is attached.
  • As part of demo, session replication is not enabled. However user can enable session replication by deploying this application with availabilityenabled argument set to true.
  • Generate the load-balancer xml and push it web-server. Web-server is now ready to service requests for application SimpleWebApp.

Maintaining stickiness using cookies

  1. Access application multiple times to validate round-robin behavior.
    Access URL : http://<web-server-host>:<web-server-port>/SimpleWebApp/SimpleServlet
  2. Create session by accessing below URL
    Access URL : http://<web-server-host>:<web-server-port>/SimpleWebApp/SimpleServlet?createSession=true
  3. Repeat step 1. You will notice after creating session, all subsequent requests will stick to same instance.
  4. Set replica partner information. Select an instance from the same cluster and use it as value for parameter replica-instance. Note: This information will be automatically set by session replication framework and web container. However in this demo, we set this information manually.
    Access URL : http://<web-server-host>:<web-server-port>/SimpleWebApp/SimpleServlet?replica-instance=<instance-name>
  5. Bring down instance currently servicing the request. You can access that information from web page itself. Check for highlighted name value pair : Instance name.
    asadmin stop-instance <instance-name>
  6. Repeat step 1. You will notice all requests are being serviced from instance selected in step 4. Since session replication is not enabled, the session will not be available on failed-over instance.
  7. Bring back stopped instance.
    asadmin stop-instance <instance-name>
  8. Repeat step 1. You will notice all requests are still being serviced from instance selected in step 4. Sessions are not moved back on instance recovery.
  9. Create multiple clusters and now run step 4 choosing an instance from different cluster.
  10. Bring down instance currently servicing the requests.
  11. Repeat step 1. You will notice your suggested fail-over instance directive is ignored. Sessions are only allowed to fail-over with in cluster boundary. Load-balancer will only fail-over requests outside cluster boundary if all instances in current cluster are not available (unhealthy or disabled). In current case, load-balancer will select an instance from current cluster to service the request.

Maintaining stickiness using url-rewriting

  1. Access application multiple times to validate round-robin behavior.
    Access URL : http://<web-server-host>:<web-server-port>/SimpleWebApp/SimpleServlet
  2. Create session by accessing below URL
    Access URL : http://<web-server-host>:<web-server-port>/SimpleWebApp/SimpleServlet?createSession=true
  3. Repeat step 1. You will notice after creating session, all subsequent requests will stick to same instance.
  4. Bring down instance currently servicing the request. You can access that information from web page itself. Check for highlighted name value pair : Instance name.
    asadmin stop-instance <instance-name>
  5. Set replica partner information. Select an instance from the same cluster and use it as value for parameter jreplica. Note: This information will be automatically set by session replication framework and web container. However in this demo, we set this information manually.
    Access URL : http://<web-server-host>:<web-server-port>/SimpleWebApp/SimpleServlet;jreplica=<instance-name>
  6. Repeat step 1. You will notice all requests are being serviced from instance selected in step 5. Since session replication is not enabled, the session will not be available on failed-over instance.

MS3 Demo : Steps to generate and transfer loadbalancer.xml to web-server.

Approach 1

  • Use export-http-lb-config directly to generate load-balancer xml
    asadmin export-http-lb-config --lbtargets <comma-separated-list-of-clusters> --property <colon-separated-list-of-properties-as-name-value-pair> <load-balancer-xml-file>
    example : asadmin export-http-lb-config --lbtargets cluster1,cluster2 --property response-timeout-in-seconds=30:https-routing=true loadbalancer.xml
  • Copy the generated loadbalancer.xml file to web-server config directory
  • Once new loadbalancer.xml is loaded by load-balancer plugin, it will start routing requests based on that.

Approach 2

  • Create a load-balancer using create-http-lb
    asadmin create-http-lb --devicehost <web-server-host-name> --deviceport <web-server-SSL-port> --target <GlassFish-cluster-name> <load-balancer-name>
    example : asadmin create-http-lb --devicehost machine1.oracle.com --deviceport 443 --target cluster1 lb-cluster1
  • Either use apply-http-lb-changes or export-http-lb-config
    • Option 1 : Using apply-http-lb-changes to generate and push load-balancer xml file over the wire to web-server
      • Export DAS certificate and import it to web-server certificate database. Refer to section Export and Import the DAS Certificate in GlassFish v2 documentation for more details.
      • Test SSL connection to the web-server
        asadmin apply-http-lb-changes  --ping=true <load-balancer-name>
        example : asadmin apply-http-lb-changes  --ping=true lb-cluster1
      • Push load-balancer xml over the wire to web-server
        asadmin apply-http-lb-changes <load-balancer-name>
        example : asadmin apply-http-lb-changes lb-cluster1
    • Option 2 : Using export-http-lb-config to generate load-balancer xml and then manually copy it to web-server
      • Use export-http-lb-config to generate load-balancer xml
        asadmin export-http-lb-config --lbname <load-balancer-name> <load-balancer-xml-file>
        example : asadmin export-http-lb-config --lbname lb-cluster1 loadbalancer.xml
      • Copy the generated loadbalancer.xml file to web-server config directory
      • Once new loadbalancer.xml is loaded by load-balancer plugin, it will start routing requests based on that.

LB-deployment.gif (image/gif)