|
YOUR FEEDBACK Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP THREE LINKS YOU MUST CLICK ON Moving to a Cluster...
What the guidebook doesn't tell you
By: David Purcell
Dec. 8, 2004 12:00 AM
You've engineered a J2EE application that has become mission critical for your business operations. You know that downtime will be less acceptable as the business starts to rely more on the application, so you want to start eliminating single points of failure and improve availability. One of your first thoughts might be: "Let's move to a clustered application server environment." Migrating to a clustered environment is a reasonable thing to do, but if this is your first experience with clustering application servers, make sure you understand what you're getting into when you go to your project owner and tell him or her about your plans. Project Considerations What are the consequences of not doing it? Business owners who have lean budgets might need to understand the chances of downtime occurring and its implications. Also, you could consider alternatives, such as a multiserver environment that doesn't involve clustering. Clustering can give you advantages such as:
In any case, be sure that there is a need and be ready to discuss not only the migration costs, but also some of the ongoing costs described below. One Change at a Time, Please Test the Failover Capabilities Be sure to test the system by shutting down each application server node (leaving at least one node up), and also by shutting down individual applications within the node (leaving at least one instance of the application running), and verifying that each combination still results in a working system. Administration Considerations Setting up the certification environment to match the production environment is standard practice for many organizations. However, the extra costs of hardware and server licenses might make departments on a lean budget try to get by without setting up identical environments. In the end, the costs of not doing so will probably catch up with them. On a recent project, for instance, I saw how a machine hosting a directory server masked an underlying problem in the certification environment, as its hardware was different than the production environment's. Although the problem existed in both environments, it manifested itself differently in the certification environment. The problem wasn't noticed until the system was deployed into the production environment, and the trouble that it caused resulted in downtime and significant troubleshooting expenses. Having identical environments will save you time and money in the long run. Little Things Add Up Also, debugging might become a little more tedious. For example, someone may experience a problem, but you don't know which instance of the server handled the request. When trying to debug an issue in a nonproduction environment, you might want to shut down one instance of the server so you can more quickly focus on the problem. Don't Let the Redundancy Fool You Application Design Considerations Persistence mechanisms, such as Hibernate, should identify which of their primary key generators are safe when used in a cluster. A mechanism we used had a seemingly simple CMP bean implementation of a primary key. Although it appeared to be cluster-safe, the entity bean that kept track of the latest primary key only wrote to the database for every 10 requests it received. Therefore, in a situation with multiple servers, each one eventually got to the tenth item and wrote to the db, overwriting the previous value. Not Everything Can or Should Take Advantage of Clustering If you have objects that use timed tasks, such as classes that implement java.util.TimerTask, those tasks will not be shared across the cluster, even if they are associated with objects that are shared across the cluster. The result is that each server will be running its own tasks. So if you have timed tasks and you don't want multiple instances of the task to be running, you need to come up with a way around it. Clark Richey's article, "Clustered Timers" (JDJ, Vol. 9, issue 3, www.sys-con.com/story/?storyid=43944), provides a good discussion on timers in a clustered environment. In our case, we knew that the timers were running in each server, but we implemented a mechanism where they had to check a database record to see if they should continue with their process. Only one instance of the timer would be allowed to perform its process. Watch Out for File Services If you have a situation where you have lots of writes to only one file, you might want to consider having each application server maintain its own instance of the file, and then setting up a nightly cron job to merge the files. If you don't want to mess with that kind of maintenance issue, or the merge won't meet your business needs, consider changing that type of function to use a database instead of writing to a file. JSP/Servlet Clustering and HttpSession State Failover I've already mentioned how some objects can't be clustered, so those objects are certainly ones that you wouldn't want to put into the HttpSession. However, keep in mind that since the HttpSession objects are going to be kept on other servers, the memory requirements on each server might not be reduced much by distributing the load. Usually the HttpSession will be kept in memory on the server that the user first visits, and another server hosts a replica of the HttpSession. If you only have two servers, each server will hold the entire set of all HttpSession state objects, not half of them. When designing applications for a clustered environment, keep in mind that your session objects should be serializable, you should keep the session objects small, and you shouldn't overuse the HttpSession by keeping everything in it. When your project is being tested, make sure you test the failover capabilities of the servers to verify that the HttpSession is always available and users don't notice when a server is taken offline. EJB Handles and Distributed Applications EJB containers on many of the major application servers provide mechanisms to handle distributing the load among clusters. BEA's WebLogic server, for instance, allows you to specify in the deployment descriptors that an EJB is clusterable. In that event, the EJBHome stub, and possibly the EJBObject remote stub, are aware of the cluster (replica-aware stubs), and will try to find a different server if the initial call fails. Whether or not an EJB can use a replica-aware EJBObject remote stub depends on the type of EJB and, for entity EJBs, the concurrency strategy (read only or read-write) selected at deployment time. IBM's WebSphere provides a concept called EJB Workload Management. No specific deployment configuration changes are required for the EJBs to be clusterable, as long as the EJB client makes requests through the WLM Plug-In in the client application server. WebSphere supports clustering of stateless session beans and the clustering of stateful session bean home objects among multiple application servers. However, it does provide clustering of a specific instance of a stateful session bean. Each instance of a specific stateful session bean can exist in only one application server, so once the bean instance is created, requests to the bean must be directed to that particular application server. For entity beans, the WebSphere EJB container supports three different entity bean caching options that define where the bean can be accessed (which servers) and when it is reloaded and passivated. Be sure to take the time to understand the clustering capabilities of your container with respect to EJBs. If such clustering capabilities aren't available, don't cache the EJBHome handles in your client. Again, testing the failover capabilities of your server is important. You will want to make the changes that you think are needed, and then test failover to make sure there aren't any dependencies between servers. Conclusion YOUR FEEDBACK
LATEST JAVA STORIES & POSTS
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK SPONSORED BY INFRAGISTICS
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||