What are the requirements for a web application for working in a clustered environment?

I need to check if an existing web application is ready for deployment in a clustered environment.

Cluster :
Several Linux boxes. The flow is controlled by a load balancer that uses a simple round robin algorithm with a sticky session.
Application A stand-alone (hopefully) Java application that retrieves content from the back office and formats it accordingly.



I have access to the source code. What should I check in the code to make sure that it will work in the cluster?

  • Make sure that something is not cached in the memory or file system where the application state is stored.
  • ... Something else?
+6
source share
4 answers

If you use EJB (which is recommended when accessing the database), here is a list of restrictions:

http://java.sun.com/blueprints/qanda/ejb_tier/restrictions.html

I assume that such restrictions apply to the web application.

0
source

The easiest way to test the application is to start with the fact that it runs on two servers with the same data, so when they start, both are in the same state. Suppose that the user performs the operation, the browser makes two consecutive HTTP requests in your web application - you will need to click web server 1 with the first call and web server 2 with the second call; then try the other way around, then both requests will go to the same web server - and if you get the same result every time you are likely to get a ready-made cluster application. (This does not mean that the IS application is ready for the cluster, as there may be states of objects, etc., which are stored in memory, which are not so easy to notice from the interface, but this gives you a higher probability that MAY be FREE OK to run in the cluster.)

0
source

If this is truly β€œstateless”, there would be no problem, you could make any request to any server at any time, and everything will work. Most things are not so easy, so any state should either be transmitted to and from the page when it moves from the client to the server, or stored on the back panel, and has some kind of token transferred back and forth to extract it from any The shared data store you use to do this. If they use HttpSession, then everything that is retrieved from the session, if changed, should be returned to the session with session.setAttribute (key, value). This attribute attribute acts as a signal that everything that is stored in the session should be replicated to the backup servers. Make sure that everything that is stored in the session implements, and in fact, Serializable. Some servers allow you to store objects (I look at you in weblogic), but then throw an exception when it tries to replicate the object. I had many colleagues complaining that the need to postpone material for the session should be redundant, and perhaps this should happen, but this is just how everything works.

0
source

Having a condition is not a big problem, if done correctly. In any case, all applications have a state. Even if you use multiple static files, the contents of the file associated with the URL are indeed part of the state.

The problem is how this condition spreads and divides.

  • The state inside the user session has no problems. Use the session replication mechanism (slower, but without losing the session when the node crashes) or the session limiting load balancer, and your problem is solved.

All other general conditions are indeed a problem. In particular, even the state of the cache must be general and perfectly consistent, otherwise an update on one page can generate different results in a random order, depending on the witch web server and, thus, the cache that you hit.

You can still cache data using shared cached (e.g. ehcache) or not return to the session.

I think it’s quite difficult to make sure that the application will really work in a clustered environment, because a singleton in some obscure service, a static member somewhere, can potentially produce strange results. You can check the overall architecture for sure, but you will need to actually do and perform some validation test before entering production.

0
source

Source: https://habr.com/ru/post/887459/


All Articles