|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP THREE LINKS YOU MUST CLICK ON Feature An introduction to WebLogic Server Clustering
An introduction to WebLogic Server Clustering
Jan. 7, 2002 12:00 AM
Welcome to the first issue of BEA WebLogic Developer's Journal! This article is the first of a three-part series geared around the clustering capabilities of BEA WebLogic Server (WLS) 6.1 and aimed at introductory and advanced audiences. This article will talk about the importance of clustering and the high-level clustering capabilities of WLS, provide an in-depth analysis of HttpSession clustering and persistence, discuss basic configuration and trouble shooting, and provide an example that ties together everything discussed in this article. The second article will provide an in-depth analysis of replica-aware stubs, their impact on a clustered system, and how they are used with EJBs, JMS objects, and DataSource objects. The last article will discuss clustering best practices, including the single-tier, coupled model; multi-tiered, coupled model; and the multi-tier, decoupled model.
The Motivation Behind Clustering
An e-business system probably makes use of a cluster to maintain levels of throughput for requests, provide back-up systems in case of unforeseen failures in nodes, or to provide additional processing power to the system. Any system that supports clustering can be characterized by the Reliability, Availability, and Serviceability (RAS) properties:
WLS Clustering Capability Overview
System Requirements for Clustering
There are many places, locations, and activities that a WLS cluster performs to provide developers with a reliable and available system. The most common misconception about WLS clusters is that many developers believe that the cluster itself (the servers in the cluster) performs load balancing or request re-direction. This NEVER occurs in a WLS cluster. Once a request has made it to a server, that server (and only that server) will handle the request or propagate an error condition. This means that all load balancing occurs by business logic that is hosted in front of the cluster (or something that communicates to the cluster). Additionally, this means that failover logic exists outside of the cluster but the cluster replicates any data that needs to be replicated to make sure that a failover request is successful. The high level clustering capabilities of WebLogic Server include:
WLS implements a decentralized, unified naming server approach. Each server in the cluster has its own naming server and all of the naming servers advertise the same services to all clients even if some of the services advertised are located on other servers in the cluster. Each naming server is aware of the services that are hosted on it and the services that are hosted on another server. IP multicast messages are used for inter-server communication to announce new, updated, or removed services from one server to the others in the cluster. For example, when you create a new TxDataSource to a connection pool and deploy the TxDataSource to a single server in the cluster, the server that hosts the TxDataSource will send a copy of the TxDataSource object representing the connection pool to all of the other servers in the cluster using IP multicast. The TxDataSource is hard-wired (pinned) to the server that has its connection pool so any client that requests the TxDataSource will be able to download it from any server. Once downloaded to the remote client, the TxDataSource will communicate with the server that contains the connection pool even if the client downloaded the TxDataSource from a different server. A WLS naming server will track all of the services located on all servers. In the situations where the same service (such as an EJB) is available on more than one server, the naming server will track the objects that represent the same service for all of the servers. Following the connection pool example described above, if the TxDataSource is deployed to the whole cluster and the same connection pool that the TxDataSource manages is available on each server in the cluster, each naming server will have a TxDataSource object that was sent to it from each of the other servers in the cluster. If you have a ten-server cluster, each naming server will have ten TxDataSource objects, each one representing a connection pool on a server. When a client requests a service from a naming server, the server will always attempt to send the object representing the service on the current server to the client. Following our example, the naming server will send the TxDataSource that maps to the connection pool on the current server before it sends a TxDataSource representing the same connection pool hosted on another server. If the service requested is not currently available on the current server, then the naming server will traverse its linked list of objects representing resources on other servers and send one of those instead. As services are deployed and undeployed, a WLS server will announce the changes over IP multicast. When a naming server receives an undeploy message for a service, it merely has to remove the object representing that service for that particular server from its naming tree. When a service is deployed or redeployed, a naming server merely has to add the object representing the service for that server to its naming tree.
Cluster Heartbeats
Cluster-Aware Stubs
In WLS, the factory objects that are downloaded are called cluster-aware stubs. Since the same service may be available on multiple servers in the cluster, the factory object downloaded from JNDI includes load balancing and failover logic for locating an appropriate reference to the resource. JMS ConnectionFactory objects, EJBs, home stubs, and JDBC TxDataSource objects are all cluster-aware stubs that can return a reference to a resource that is located on any server in the cluster. Cluster-aware stubs communicate with the cluster to maintain an active list of servers that host the service they are a factory for. When a client uses a cluster-aware stub to obtain a reference to a resource, the cluster-aware stub can load balance that request to different servers in the cluster. If you have a connection pool deployed to all of the servers in the cluster, a client that calls getConnection() on a TxDataSource multiple times will receive a Connection object from a different server upon each invocation. This behavior only applies to Java clients that are not colocated within the same VM as the server itself. In a situation where the requesting client IS colocated in the same VM as the server, it always makes sense to return the reference to the resource hosted locally. Any attempt to load balance a request that can be handled locally is an unnecessary burden to the system. Additionally, since a cluster-aware stub is constantly updated with the correct list of servers that are hosting the service, the cluster-aware stub will never make a request to a server that isn't hosting the service. Cluster-aware stubs and EJBs are an interesting topic because:
Replicated Data Objects (HttpSession and Stateful
Session EJBs)
Since HttpSession objects and stateful session EJBs are not designed to survive server crashes, WebLogic Server provides data object replication to help resist failures in enterprise systems. For HttpSession objects, there are several options: JDBC replication, cookie persistence, and in-memory replication. JDBC replication stores session content in a relational database table. This process offers two advantages:. First, persistent storage ensures survival of the session data even if the entire cluster were to become inoperable. Second, storage in a central repository allows any server in a cluster to be able to handle any session. Despite this, JDBC replication has poor performance since every update to a session instance requires synchronization with the database. Cookie persistence involves serialization of the session object into a cookie that is passed between the Web browser and server with each HTTP request. Cookie persistence allows any server access to any session while also providing fast in-memory access to the session's contents. However, there are some drawbacks:
In-memory replication requires routing all requests for a given HttpSession to the server that has that session. This can be done with cookies or URL rewriting. When a clustered server receives an HTTP request unaffiliated with an HttpSession, the server creates a new HttpSession object with a unique ID, registers itself as the primary server, and selects a backup server from those remaining in the cluster. Point-to-point communication between the primary and backup servers is established at this time, to allow for the synchronization of the HttpSession object. The IP addresses and ports of the primary and backup servers are encoded as part of the session ID for the HttpSession.
Load Balancing and HttpSession Fail Over
The HttpClusterServlet, available with the standard WebLogic Server installation, runs in a non-clustered instance of WLS (i.e., a proxy server) and contains the logic necessary to parse the routing information in the WLS-generated session ID. HTTP requests not containing a session ID are load balanced by a round-robin algorithm. HTTP requests that contain a session ID are routed to the server containing the primary HttpSession instance (see Figure 1). When the server hosting the primary instance becomes unavailable, the backup server senses it through the loss of point-to-point communication, promotes itself to primary, and selects a new backup from the remaining clustered servers. Upon the next request, the HttpClusterServlet detects that the original primary server is unavailable and reroutes the request to the specified backup server. The response contains the session ID with revised routing data. The ease of configuring the HttpClusterServlet makes it a valuable tool during the development process. With Web server plug-ins, developers can capitalize on the investment already made on Netscape, Microsoft, and Apache Web server licenses to serve static Web content while delegating requests for dynamic page generation, via servlets and JSPs, to the WebLogic Server. The plug-ins, available as shared or dynamic libraries, provide the same round-robin load balancing and HttpSession routing mechanisms as the HttpClusterServlet. Additionally, the Netscape and Apache plug-ins provide routing based on URL pattern matching. Load-balancing hardware provides built-in firewall capabilities and sophisticated load-balancing algorithms. To consistently route traffic to a server hosting a primary instance, most vendors will either insert their own cookie in the client session (active cookie persistence) or interpret part of an existing cookie as a single numerical differentiator (passive cookie persistence). WebLogic Server in-cluster routing mitigates load-balancing hardware's disregard for the backup server (see Figure 2). When a request is received on a clustered server that has no knowledge of a given session, the routing data stored in the session ID is queried, the server hosting the back instance is contacted, and the receiving server becomes the host to the new primary instance. In other words, the server hosting the backup instance becomes a factory for creating new primary instances, rather than being promoted itself.
Setting Up a Simple Cluster
The entire domain for this exercise is available for download the Web site (www.sys-con.com/weblogic). The downloaded domain files will have the cluster, business components, and proxy configured for some default IP addresses and ports. You can setup your cluster by following the steps listed here or by installing the domain download and re-mapping IP addresses to match those on your machine.
Basic Cluster Configuration with the Administration
Console
To create the server profiles, right click on the Servers folder and select "Configure a New Server.... In the Configuration->General pane, fill in and submit the Name, Listen Port, and Listen Address for each server. Remember that the clustered servers must share the same Listen Port and have unique Listen Address settings. Figure 3 has a screen shot of what our screen looks like when filled out. Please note that, while the Listen Address could be either an IP address or host name, the use of the latter is necessary to run this example. To map IP addresses to host names on your individual computer, add entries to C:\WINNT\system32\drivers\etc\hosts. To create the cluster profile, right click on the Clusters folder and select "Configure a New Cluster...". In the Configuration->General pane, fill in and submit the Name and Cluster Address for the cluster. Set and apply the Multicast Address in the Configuration-> Multicast pane. Finally, add the clustered servers to the Chosen column in the Configuration-> Servers pane. Figures 4, 5, and 6 are screen shots of what our cluster configuration looks like when filled out. All of the configuration data used for the business servers, proxy server, and cluster is summarized in Table 1.
Setting Up the HTTPClusterServlet
Defining Business Content and a Fail Over Mechanism
In the web.xml file of SimpleWebApp, the clustered Web application, XML elements are added to register SimpleServlet with its fully qualified class name and provide a single URL mapping element to allow invocation of the servlet through the alias simple. Listing 2 contains the source code for the SimpleServlet servlet. In the weblogic.xml file of the application, XML elements are added to set the session-related property PersistentStoreType to replicated. This is the only parameter required to enable in-memory replication. Listing 3 lists the configuration files for the SimpleWebApp. The last step for configuring the test application is to deploy it to the cluster. Deployment to a cluster can be accomplished in the Administration Server:
To start the cluster:
If the table does not show three servers receiving updates, try the following troubleshooting measures:
Whew! Granted, that's a lot to swallow, but WLS clustering is straightforward. Its flexibility comes from the number of integration touch points that it offers to architects of e-business systems. Future articles will discuss the implications of EJBs in a cluster and clustering best practices, so keep practicing and reading! YOUR FEEDBACK
BEA WEBLOGIC LATEST STORIES
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 BREAKING NEWS FROM THE WIRES
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||