J2EE Clustering Part 2

zhaozj2021-02-16  58

J2EE Clustering Part 2

Use easy way to transfer your application from single machine to the cluster

By Abraham Kang

Translation Tianyu 2002-12-16

http://www.javaworld.com/javaworld/jw-08-2001/jw-0803-extremescale2.html

Summary

Because most developers construct their web applications in non-clustered environments, those applications often crash, stop work. At the second part of this article, Abraham Kang explains the programming related to cluster. , Setting up and manage the problem. With these knowledge, you will be able to write the CLUSTERABLE code from the beginning, so that you will avoid hidden dangers.

In the J2EE frame, a high availability (HA) and scalability infrastructure is provided for the cluster. The cluster refers to the explicit running of your J2EE app on a set of application servers, just like a separate entity. However, when web The behavior performance of these applications is different when applying is a cluster, as they must share application objects through a series and other cluster members. In addition, you will have to pay for additional structural configuration and setting time.

To avoid major web applications rework and redesign, you should consider programming problems related to clusters from your development process. To support intelligent load balancing and fail transfer, you also need to consider critical settings and structural configuration decisions. Finally, you also need to have a management strategy for processing failed.

Read the "J2EE Clustering" series:

· Cluster is critical to good website design; do you understand the basics of Clustering?

· Use easy way to transplant your app from single machine to the cluster

Based on the first part of the knowledge, I will disclose my understanding of the practical application of clusters. Further, it will also study the key points and possible solutions related to the cluster. There is also the advantages and disadvantages of each choice. I will also demonstrate To guide the cluster programming. Finally, I have explained how to prepare for the fault. (Note: This article does not apply the benchmark due to the constraint of the permissions.)

Build your cluster

During the cluster settings, you need to make important decisions. First, you must choose a load balancing method. Second, you must determine how to support server affinity. Finally, you need to decide how to be between cluster nodes Deploy server instance.

Load balancing

You can usually choose a load balancing cluster between two recognized options: DNS Round Robin or Hardware Load Balancers.

DNS ROBIN

DNS is the process of converting logical names (such as www.javaworld.com) into IP addresses. In DNS Round-Robin load balancing, a single logical name can return the IP address of any machine in the cluster.

The advantages of DNS Round-Robin load balancing include:

· Cheap, easy to set

·simple

Disadvantages include:

· Do not support server affinity. When the user receives an IP address, it is cached in the browser. Once the cache expires, the user sends another request for the IP address associated with the logical name. The second request can return The IP address of any other machine in the cluster will cause session loss.

· Do not support HA. Imagine a cluster with N servers. If a server Down is dropped, each of the Nth requests on the DNS server still continues to access the dead machine.

• Cluster change propagation to the Internet requires time. Many companies and ISPS DNS servers cache DNS lookups from the client. Even if the server's DNS list can be dynamically changed, the entrance, distance from other DNS servers It takes a period of time. For example, AOL has a server that has dropped off, after shifting it from the cluster's DNS list list, if the AOL DNS server caches the server entry dropped by this DOWN, AOL's client is still It will try to connect to this Down dropped server. As a result, even if other machines in the cluster are available, the AOL user cannot connect to this site.

· Do not guarantee that the same client is distributed through all the servers in the cluster. If you don't have the DNS server to collaborate to support DNS load balancing, they may only return the first IP address from the original found to, using this IP to handle customers. Did request. Imagine a partner company company company company, all requests are fixed to a single server in the cluster!

Hardware load balancers

In contrast, the hardware load balancer solves most of the problem through a virtual IP address. The hardware load balancer represents only a single IP address of the cluster. The load balancer receives each request, rewriting the other in the cluster. The head of the machine. If you remove some of the machines in the cluster, these changes are immediately effective. The advantages of hardware load balancer include:

· Server affinity --- is not using SSL

· HA Service --- Failure Transfer, Monitoring, etc.

· METRICS --- Activity session, response time, etc.

· Ensure that the same client is distributed through the cluster.

However, the hardware load balancer also shows the disadvantage:

· High cost - different characteristics, $ 10,000 to $ 40,000 inequal

· Setting and structure configuration complex.

Once you have selected the load balancing, you must decide how the cluster supports server affinity.

Server affinity

When using SSL without using the web server agent, the server affinity will have a problem. (Due to the persistence of the session, the server affinity will point the user to a specific server in the cluster). Hardware load balancer relies on cookies or url readings to determine requests Where is the request is SSL encryption, the hardware load balancer cannot read the head, cookies or URL information. To solve this problem, you have two options: Web Server Proxies or SSL Accelerator (SSL Accelerators ).

Web Server Agent (Web Server PROXIES)

In this scenario, for the web server agent, the hardware load balancer is like a DNS load balancer, except this, there is a separate IP address .Web server decrypts SSL request, transfer them to the web server plugin ( Web Server Agent). Once the plugin receives a decrypted request, it can parse the cookies and URL information, followed by redirecting the request to the application server resident in the user session state.

The main advantages of Web server agent include:

Server Affinity with SSL

· No additional hardware (only hardware load balancer)

Disadvantages:

• Hardware load balancer cannot utilize Metrics orientation requests.

• Rely on the use of Additional Strain to extend SSL on the web server.

· Web server agent needs to support server affinity

If most of your site processed must be secure, the SSL Accelerator can increase the flexibility of the cluster topology when supporting server affinity.

SSL Accelerator (SSL Accelerators)

SSL Accelerator Network Hardware Processes the SSL request to the cluster. It is located in front of the hardware load balancer, allowing the hardware load balancer to read encrypted information in cookies, headers, and URLs. Then hardware load balancer uses their own specifications to request. If Select the server affinity by SSL, use this setting to avoid web agents.

The benefits of using the SSL accelerator:

· Support server affinity and SSL's flexible topology (with Web agents or not)

· Off-loaded SSL processes to SSL accelerators, adding scalability

· Central central SSL certificate management

Disadvantages include:

· In order to obtain HA, buy two accelerators require high cost.

· Add the complexity of setting and structural configuration.

Once you have determined the server's affinity setting, you need to subtract your application server instance into the cluster node.

Application server distribution

When distributing the application server instance into the cluster, you must decide if you need to deploy multiple application server instances on a node in the cluster, but also need to determine the total number of nodes in the cluster.

The number of application server instances on a node rely on CPUS, CPU utilization, and available memory.

Under the three conditions below, consider multiple examples in one unit:

· There are three or more loads do not have a saturated CPUS

· The size setting of the instance reactor is too large, causing increased garbage collection time

· Application does not have I / O borders

Determining the best node number in the cluster is an iteration process. First, Profile and Optimize Applications. Second, use load test software to simulate your expectations the highest utilization. Finally, increasing the remaining node processing loads when failure occurs.

Ideal, it is best to push the development version to the implementation, when there is a cluster problem, you can capture them. Unfortunately, developers build most applications on a single machine, then transplant them to the cluster environment. This situation will cause the application to crash and stop working.

Session Storage Guide

To destroy minimization, the basic guidance of the application server is listed below, which uses memory or database session persistence. • Determine all objects and those objects they recursted

In httpsession is serialized, depending on the experience, all objects should implement java.io.serializable on part of its standard.

· In httpsession, no matter how often you change the status of the object, call the session.settribute (...) to change the object and save these changes to a backup server or database.

AccountModel am = (AccountModel) session.getAttribute ( "account"); am.setCreditCard (cc); // You need this so the AccountModel object on the backup receives the // Credit card session.setAttribute ( "account", am) ;

· ServletContext is not serialized, so it does not need to be used as an instance variable. (Unless it is identified as transient), because any direct or indirect object is stored in httpsession. In Servlet 2.3 container, when HttpSessionBindingEvent holds servletContext When reference, it is easier to get a reference to servletContext, which has been confirmed.

· EJB Remotes may not be serialized. When they are not serialization, you need to overload an implicit Serialization mechanism, as shown below (this class does not implement java.io.serializable, because AccountModel has the parent class to serialize. ):

... public class AccountWebImpl extends AccountModel implements ModelUpdateListener, HttpSessionBindingListener {transient private Account acctEjb; ... private void writeObject (ObjectOutputStream s) {try {s.defaultWriteObject (); Handle acctHandle = acctEjb.getHandle (); s.writeObject ( acctHandle);} catch (IOException ioe) {Debug.print (ioe); throw new GeneralFailureException (ioe);} catch (RemoteException re) {throw new GeneralFailureException (re);}} private void readObject (ObjectInputStream s) {try { S.defaultReadObject (); Handle AcctHandle = (Handle) S.ReadObject () Object Ref = acctHandle.GeteJBObject (); acctejb = (Account)

PortableRemoteObject.narrow (ref, Account.class);} catch (ClassNotFoundException cnfe) {throw new GeneralFailureException (cnfe);} catch (RemoteException re) {throw new GeneralFailureException (re);} catch (IOException ioe) {Debug.print ( ioe); throw new GeneralFailureException (ioe);.}} · after recovery session from the disk and in each call HttpSession's setAttribute (...) method, call HttpSessionBindingListener of valueBound (HttpSessionBindingEvent event) method is not called during failover valueBound ( HTTPSESSIONBINGEVENT EVENT method.

Memory session status replication

Memory session status replication is read more complicated than database mobility, because when a single object in HttpSession changes, it is serialized to a backup server. Use database session persistence, when the object in Sessions occurs Changes, the objects in the session are serialized together. A side effect of memory session status is to clone all HttpSession objects, which have a session key. If each of them has a SESSION key storage object independent With different session keys, this is actually no effect. However, if the storage object with session key is highly dependent on other objects in httpsession, the copy will be profit on the backup machine. After failing, your application will continue to run, but some features may not work - for example, the shopping cart may refuse to accept more data items. This problem breeds from your application (updated shopping cart and Show shopping carts), they quote their own copy of the shopping cart. When JSPS tries to display the copy of the shopping cart, the class that will be updated to the shopping cart is changing the copy of its shopping cart. In a single server environment, this The problem will not appear, because the two parts of your application point to the same shopping cart.

This has an example of indirect copy object:

Import java.io. *;

Public Class AAA IMPLEMENTS SERIALIZABLE {

String name;

Pubic void setname (String name) {

THIS.NAME = Name;

}

Public string getname () {

Return Name;

}

}

Import java.io. *;

Public Class BBB IMPLEMENTS SERIALIZABLE {

AAA A;

Public BBB (AAA A) {

THIS.A = a;

}

Pubic void setname (String name) {

a.setname (name);

}

Public string getname () {

Return a.getname ();

}

}

First.jsp on Server1:

<%

AAA a = new aaa ();

a.setname ("ABE");

BBB B = New BBB (a);

// a lopied to backup machine under key "a"

Session.setttribute ("a", a);

// b Is Copied to Backup Machine Under Key "B"

Session.SetaTRibute ("B", B);%>

SECOND.JSP on Server1:

<%

BBB B = (BBB) ​​Session.getaTribute ("B");

B.setname ("Bob");

// b Is Copied to Backup Machine Under Key "B"

// But Object aaa under key "a" HAS the name "ABE"

// and "b" 's aaa Has the name "bob"

Session.SetaTRibute ("B", B);

%>

---> Failure, try contact with third.jsp on Server1 -----> THIRD.JSPSERVER2 on the server2 (backup machine) on the server2 (backup machine): <% = ((Aaa) session.getattribute ("a")). GetName ()%>

Through the object BBB, the name of the object AAA is: <% = ((bbb) session.getattribute ("b")). GetName ()%>

... // end of think.jsp

The expression in the first tag outputs "ABE", and the expression in the second tag output "Bob". On a single server, the expressions in the two tags output "Bob".

In order to understand the invalid session status copy, a cluster object relationship map (CORD) is constructed, as shown below.

JavapetStore Cord.

In this figure, the ellipse indicates a direct storage of the key-value in the httpsession. The rectangle represents the object directly referenced by the storage object with the HttpSession Key. The object pointing to the black arrow is the original object instance variable. Empty arrow indicates inheritance relationship.

Typically, statistical points to the number of arrows of the object, will tell you the copy number generated by this object. If the arrow points to an ellipse, you have to add a total of the total number of arrows, because this ellipse with session key is stored in httpsession. For example, Look at the ellipse of ContactInformation, there is an arrow pointing it, which means there are two copies: one with the session key is directly stored, and the other as an instance variable variable as an AccountWebimpl.

I have to emphasize that because of the complex relationships often lead to your experience, look at ShoppingClientControllerWebimpl; there is an arrow pointing to it, so there are two copies, right? Wrong! There are three copies: a copy by ModelManager, one Through AccountWebimpl, a through RequestProcessor. You don't have to calculate the ShoppingClientControllerWebimpl itself because it does not directly with HttpSession Key storage.

Try another example. Look at the picture, how many modelmanager copies? If the answer is four, you are right. There is a copy from ModelManager itself, because it is with HttpSession Key, There is AccountWebimpl, ShoppingCartWebimpl and RequestProcessor. I didn't calculate the arrows from the RequestToEventTranslator because it didn't directly with HttpSession Key storage, which is the same for ModelManager's references and references from RequestProcessor.

Note: About memory replication, always remember: any object stored with HTTPSession Key will be cloned and sent to the backup machine.

In order to maintain the number of objects, only the original object type, simple object, or independent object with Session Keys in httpsession. If you can't avoid complicated relationships in httpsesion, once the user has failed to transfer, use session. SetAttribute (...) removes the copy. For example, with the actual ModelManager, instead of the ModelManager in AccountWebimpl, you need to call session.setttribute ("Account", AccountWebimplwithRealmodelManager). In most cases, you need to focus on sharing status Copy object. If the object does not have any shared instance variables, you can no matter whether it. The only negative impact: For clients that fail, add the memory usage. After the test is complete, if your cluster is completed Each can fail to transfer, you also need to develop a cluster management policy.

The cluster management policy document defines what will malfunction, how to solve these problems. Generally, these issues have four categories:

1 hardware

2 software

3 network

4 database

Since this is JavaWorld, I will focus on the software. You may have to discuss other problems with system administrators, network administrators, and DBA around you.

If the software on the cluster fails, other members in the cluster must take the responsibility of the server that has dropped from DOWN. In the JSP application, failed transfers appear in the web proxy or hardware load balancer. For example, enter a request from the web agent, the web agent notes the server Down to arrive, so it sends this request to another application server. This application server activates the user's backup session status, complete this request. In the EJB client application, the Remote references the different servers in the cluster until they receive a response.

These failure transfer descriptions seem to be slightly, but we only mention the best situation in failure between requests. When there is a failure during the request, failure transfer is proven to be difficult. Let us see one Examples of JSPS and EJBs are involved.

For our JSP example, imagine a user who is next order on your site, this page seems to be aborted when the user clicks the submission button, and the result is a message, "no data response". In this case, There may have occurred in two cases. The order has been completed, but the server fails before the response page is sent. The other situation is that the server may have failed before saving the order and sending a response. Agent on another server Automatically call the same URL, and reinitialize this transaction, can you trigger a copy? Or return an error to force users to contact some members of your support team??

In our EJB example, imagine that a user is modifying inventory on a Java application. Once the user clicks on the save button, a request arrives at an EJB, but this app returns RemoteException. Similarly, any one in two cases may occur. What may have been saved, but the server may fail before sending a response. Or, the server has failed before doing Inventory changes. EjB Remote automatically re-attempts to distinguish on another server in the cluster Call and stick the risk of copying or inconsistent data?

After trying different failure transfer technologies, I summarize the explicit failure of the transition is full of application servers. You can try to use transaction Tables or transaction identifiers in cookies, but you have a hard work. What is the easiest solution: After the server fails, run a set of stored procedures for finding inconsistency in the database, notifying the organization of interest.

Conclude

This article allows you to understand the cluster, it is very practical. You have already mastered how to set up, program, and maintain J2EE clusters. You also understand questions related to clusters, and possible solutions. With these actual Knowledge, you can set up a J2EE cluster in your work.

But your job has not been completed: You have to develop networks, hardware, and database infrastructure to ensure HA. Developing these services is the easing method of enterprise hosting service. Most Enterprise Managed Services Redundancy, data management and hardware services. You only provide the CLUSTERABLE code.

Good luck and happy clustering.

About author

Abraham Kang is an integrated architect in Infogain's corporate integration solution. He has a year and a half J2EE application server cluster experience. In addition, he is a SUN certified programmer and developer, Oracle 8i professional certification DBA, CCNA, and Ccda .. Abraham wants to thank Jessie Spencer-Cooke, Aleksey Shcherbakov, Raju Chiluvuri, and Roger Plichta their support thank you .resources

J2EE Clustering, "Abraham Kang (JavaWorld):

Part 1: Clustering Technology Is Crucial to Good Website Design; Do you know the basics? (February 2001)

Part 2: Migrate Your Application from a Single Machine to a Cluster, The Easy Way (August 2001)

ENTERPRISE Hosting Services:

LoudCloud

DiGex

Hardware load balancers:

F5 BIG IP

Alteon 180

Enterprise Javabeans, Richard Monson-Haefel (O'Reilly & Associates, 2000; ISBN: 1565928695): http://www.amazon.com/exec/obidos/asin/1565928695/javaworld

Java Pitfalls: Time-Saving Solutions and Workarounds to Improve Programs, Michael C. Daconta (Editor), Eric Monk, J. Paul Keller, Keith Bohnenberger (John Wiley & Sons, 2000; ISBN: 0471361747): http: // www. Amazon.com/exec/obidos/asin/0471361747/javaworld

"Flatten Your Objects": http://www.javaworld.com/javaworld/jw-07-2000/jw-0714-FLATTEN.HTML

For a good look at the Canonical Form, Read Bill Venners' "The Canonical Object Idiom": http://www.javaworld.com/javaworld/jw-10-1998/jw-10-techniques. HTML

For more information on high availability, see the high-availability linux project: http://www.linux-ha.org/

"Get the App Out," Chang Sau Sheong (JavaWorld, January 2001) describes the ins and outs of J2EE assembly and deployment: http://www.javaworld.com/javaworld/jw-01-2001/jw-0119-j2eeassembly .html

转载请注明原文地址:https://www.9cbs.com/read-24049.html

New Post(0)