Application Clustering
From Stax
Clustering of Java web applications is a native part of the Stax cloud environment. Use the configuration tab for your application to toggle the number of servers your application is deployed on.
Contents |
Architecture
The Stax Cloud includes an HTTP routing layer that handles clustering and load balancing for your Java web applications. When an HTTP request is received, the routing layer uses the HTTP host header to determine the target application. Once the target application is determined, the request will be forwarded to a deployed instance of the application. If your application has been configured to run in a cluster, requests are forwarded to instances using a round-robin algorithm. If the routing layer is unable to connect to the instance, the request will automatically be directed to the next deployed application instance.
Application Hibernation and Activation
Applications running in the Stax Cloud can be hibernated so they will not consume any server resources associated with your account. Hibernation is a very effective way to increase the efficiency of your application servers so that you can run more application with fewer AWS server resources. This is useful for infrequently used applications or for dev/test application deployments.
When an HTTP request for a hibernated application is received, the Stax HTTP routing layer will automatically re-activate the application by deploying it to an available server. The amount of time required to activate an application varies based on the size of the application's deployment package and the amount of startup logic that occurs when the application is started. A simple Java application, typically takes only a few seconds to activate, but larger applications will take longer. Currently, clients requests are blocked during application activation.
Session clustering
By default applications sessions are bound to a single application instance and not enabled for clustering. Since cluster application routing uses round-robin, if you configure your application for a clustered deployment and use HTTP Sessions, you will want to enable session clustering so that session data stored by one server will be available from other application server instances when the next request is received. To enable clustered sessions, you will need to designate a datasource your application can use to store its session data using the <sessionDataSource> element in your stax-application.xml file. Once your session datasource is bound, the stax_sessions table will automatically be initialized to store your session data.
Enabling JDBC Session Clustering
- Use the AppConsole to create a MySQL database to use for persisting your Session data
- Update stax-application.xml to bind the database to your application as a datasource by adding the datasource XML element.
<resource name="jdbc/DATASOURCE_NAME" auth="Container" type="javax.sql.DataSource"> <param name="username" value="DB_USERNAME" /> <param name="password" value="DB_PASSWORD" /> <param name="url" value="jdbc:stax://DB_NAME" /> </resource>
- Update stax-application.xml to register the datasource as the sessionDataSource by adding the following XML:
<sessionDataSource>jdbc/DATASOURCE_NAME</sessionDataSource>
