Enabling clustering for load balancing and failover



Load balancing is an enterprise-level feature in which the application server automatically alternates requests among the server instances in a cluster. Clustering also enables application servers to route requests to a running server instance when the original server instance goes down.

Note: These instructions apply only when you are running ColdFusion in the multiserver configuration. If you are running JRun4, you can also create clusters in the JMC.

You can get load balancing and failover by deploying identical ColdFusion applications and configurations to multiple server instances and adding the instances to a cluster. Each instance must have the same applications deployed and the same resources configured (such as data sources, Verity collections, and mappings). The web server connector optimizes performance and stability by automatically balancing load and by switching requests to another server instance when a server instance stops running.

Note: Because clustering uses Jini Network Technology, you must be connected to a network for clustering to work.

For maximum failover protection, use multiple computers in a cluster. However, purchase a separate ColdFusion Enterprise Edition license for each computer.

Note: If you set up and test multiple server instances while running the 30-day trial version, the cluster might not continue to function appropriately when the trial version reverts to the Developer version after 30 days.

To implement session failover for the server instances in a cluster, enable session replication for each server instance. Session replication coordinates session information in real time among the server instances in a cluster. Enabling session replication lets JRun automatically route a request to a running server if the current server is unavailable.

Note: When a cluster uses session replication, session data is copied to other servers in the cluster each time it is modified. This can degrade performance if you store a significant amount of information in session scope. If you plan to store a significant amount of information in session scope, consider storing this information in client variables saved in a database.
To enable session replication, manually edit the jrun-web.xml and set persistence to false. To do this, open the jrun_root/servers/server_name/server_name-ear/server_name-war/WEBINF/jrun-web.xml file and modify the <persistence-config> entry to false as follows:
<persistence-config><active>false</active></persistence-config>
For more information, see TechNote "JRun 4: Configuring session replication to enable session failover" at www.adobe.com/go/tn_18226.

Configure a cluster of server instances for load balancing and failover

  1. Create your application and the data sources required for the application.

  2. Check that you installed ColdFusion by using the multiserver configuration.

  3. Open the ColdFusion Administrator for the cfusion server in a browser (http://hostname:8300/CFIDE/administrator).

  4. Select Packaging & Deployment > J2EE Packaging.

  5. Use the J2EE Archives page to create an EAR file that contains the application, its CFM pages, the required data sources, and other settings.

  6. Select Enterprise Manager > Instance Manager.

  7. Create server instances for the cluster as described in Defining additional server instances. Use the Create From EAR/WAR field to specify the archive file that you created.

  8. (Optional) Click the Register Remote Instance button to define existing remote server instances so that you can include them in the cluster. If you use a remote server, ensure that it contains the same application and settings as the local server instances.

    Note: A server can participate in only one cluster. When adding remote instances to a cluster, ensure that the instance is not already part of a cluster.
  9. Ensure that each server instance is started.

    Note: To administer a cluster, at least one member server instance must be running.
  10. Select Enterprise Manager > Cluster Manager.

  11. Name the cluster and click Add.

    The ColdFusion Administrator adds the cluster to the Configured Clusters area.

  12. Click the cluster name or the edit icon.

    The Edit Cluster screen appears.

  13. Use the arrow icons to add server instances to the cluster.

  14. (Optional) Enable session replication, and specify a cluster algorithm.

    Note: When you enable sticky sessions, the connector does not always route requests strictly based on the cluster algorithm. For more information, see Administrator online Help.
  15. Click Submit.

  16. Select Enterprise Manager > Instance Manager.

  17. Use the CF Admin icon on the Instance Manager to open the ColdFusion Administrator on each server instance. Ensure that required resources (such as data sources and Verity collections) are defined appropriately. If you are using session replication, go to the Memory Variables page and enable J2EE sessions. Enable J2EE sessions for all server instances in the cluster. If J2EE sessions are not enabled in the ColdFusion Administrator, session replication does not function properly.

    CFC serialization lets you use J2EE session replication in a cluster and have access to the CFCs in session data across all instances in the cluster. Session replication also ensures that that Session scope variables are replicated across the cluster. However, session replication does not support replication of arrays in Session scope CFCs or variables.

    You can also preserve and access data in a CFC in the case of session failover. ColdFusion structures stored inside the session scope are available in the session scope, even after failover. For example, if you are running multiple ColdFusion instances to balance server load, you can store useful data, including CFCs, inside the session so that you can access the data across all the pages that are served in that session.

    To enable CFC serialization, set the CFC in the session, as follows:

    <cfset cfccomponent = CreateObject("component", "CFIDE.adminapi.datasource")> 
    <cfset session.datasourcecomponent = cfccomponent>

    After failover, you can then access and call methods in the CFC, as follows:

    <cfset check = session.datasourcecomponent.verifyDSN("testdsn")>
  18. For servers that are not on the same subnet, open the jrun_root/lib/security.properties file and add the IP addresses of the other JRun servers in the cluster to the jrun.trusted.hosts property.

    Note: This step is required only for servers that are not on the same subnet; it is not necessary if all servers are on the same subnet.
  19. Restart all JRun servers in the cluster.

  20. Run the Web Server Configuration Tool. Choose your website, but instead of choosing a single server instance, select the cluster. Ensure that you select the Configure Web Server for ColdFusion MX Applications option (GUI) or use the ‑coldfusion option (command line). For more information, see Web server configuration.

  21. Open the SERVER-INF/jrun.xml file for each server instance and ensure that the ProxyService deactivated attribute is set to false.

  22. (Optional) Store the ColdFusion files of your application in the external web server root directory.

  23. Test the application to ensure that load balancing and failover work as expected.