Clustering with Tomcat. Introduction. O'Reilly Network: Clustering with Tomcat. by Shyam Kumar Doddavula 07/17/2002



Similar documents
Load Balancing Web Applications

Chapter 10: Scalability

Web Application Hosting Cloud Architecture

Oracle WebLogic Server 11g: Administration Essentials

Architecting ColdFusion For Scalability And High Availability. Ryan Stewart Platform Evangelist

STREAMEZZO RICH MEDIA SERVER

Introduction to Sun ONE Application Server 7

Apache Jakarta Tomcat

Chapter 2 TOPOLOGY SELECTION. SYS-ED/ Computer Education Techniques, Inc.

Oracle WebLogic Server 11g Administration

Web Application Firewalls: When Are They Useful? OWASP AppSec Europe May The OWASP Foundation

Tomcat 5 New Features

CHAPTER 1 - JAVA EE OVERVIEW FOR ADMINISTRATORS

Load Balancing using Pramati Web Load Balancer

LOAD BALANCING TECHNIQUES FOR RELEASE 11i AND RELEASE 12 E-BUSINESS ENVIRONMENTS

Scaling Progress OpenEdge Appservers. Syed Irfan Pasha Principal QA Engineer Progress Software

Architectural Overview

Oracle WebLogic Foundation of Oracle Fusion Middleware. Lawrence Manickam Toyork Systems Inc

This training is targeted at System Administrators and developers wanting to understand more about administering a WebLogic instance.

INCREASE SYSTEM AVAILABILITY BY LEVERAGING APACHE TOMCAT CLUSTERING

Scaling Web Applications in a Cloud Environment using Resin 4.0

Virtual Credit Card Processing System

DNS ROUND ROBIN HIGH-AVAILABILITY LOAD SHARING

BlackBerry Enterprise Server for Microsoft Exchange Version: 5.0 Service Pack: 2. Administration Guide

What Is the Java TM 2 Platform, Enterprise Edition?

Chapter 1 - Web Server Management and Cluster Topology

Setting Up B2B Data Exchange for High Availability in an Active/Active Configuration

MID-TIER DEPLOYMENT KB

Deployment Topologies

LICENSE4J AUTO LICENSE GENERATION AND ACTIVATION SERVER USER GUIDE

ELIXIR LOAD BALANCER 2

Oracle Collaboration Suite

<Insert Picture Here> WebLogic High Availability Infrastructure WebLogic Server 11gR1 Labs

Code:1Z Titre: Oracle WebLogic. Version: Demo. Server 12c Essentials.

Infor Web UI High Availability Deployment

Configuration Management of Massively Scalable Systems

Apache Tomcat Clustering

Intro to Load-Balancing Tomcat with httpd and mod_jk

JReport Server Deployment Scenarios

Creating Web Farms with Linux (Linux High Availability and Scalability)

zen Platform technical white paper

Apache Tomcat. Tomcat Clustering: Part 2 Load balancing. Mark Thomas, 15 April Pivotal Software, Inc. All rights reserved.

No.1 IT Online training institute from Hyderabad URL: sriramtechnologies.com

Capacity Planning Guide for Adobe LiveCycle Data Services 2.6

Glassfish Architecture.

EWeb: Highly Scalable Client Transparent Fault Tolerant System for Cloud based Web Applications

Apache Stratos (incubating) M5 Installation Guide

Course Description. Course Audience. Course Outline. Course Page - Page 1 of 5

Dependency Free Distributed Database Caching for Web Applications and Web Services

Oracle BI Publisher Enterprise Cluster Deployment. An Oracle White Paper August 2007

StreamServe Persuasion SP5 StreamStudio

Oracle EXAM - 1Z Oracle Weblogic Server 11g: System Administration I. Buy Full Product.

White Paper: 1) Architecture Objectives: The primary objective of this architecture is to meet the. 2) Architecture Explanation

FAQs for Oracle iplanet Proxy Server 4.0

Building Java Servlets with Oracle JDeveloper

S y s t e m A r c h i t e c t u r e

A Java proxy for MS SQL Server Reporting Services

Apache Tomcat. Load-balancing and Clustering. Mark Thomas, 20 November Pivotal Software, Inc. All rights reserved.

BlackBerry Enterprise Service 10. Secure Work Space for ios and Android Version: Security Note

Using Tomcat with CA Clarity PPM

Enhanced Connector Applications SupportPac VP01 for IBM WebSphere Business Events 3.0.0

Mobile Devices: Server and Management Lesson 05 Service Discovery

3-Tier Architecture. 3-Tier Architecture. Prepared By. Channu Kambalyal. Page 1 of 19

SCALABILITY AND AVAILABILITY

5 Days Course on Oracle WebLogic Server 11g: Administration Essentials

WEBAPP PATTERN FOR APACHE TOMCAT - USER GUIDE

Introduction 1 Performance on Hosted Server 1. Benchmarks 2. System Requirements 7 Load Balancing 7

MIDDLEWARE 1. Figure 1: Middleware Layer in Context

LinuxWorld Conference & Expo Server Farms and XML Web Services

GRAVITYZONE HERE. Deployment Guide VLE Environment

Oracle Identity Analytics Architecture. An Oracle White Paper July 2010

Tushar Joshi Turtle Networks Ltd

Building Web Services with XML Service Utility Library (XSUL)

Amazon Elastic Beanstalk

WebLogic Server 11g Administration Handbook

WEBLOGIC ADMINISTRATION

Exploring Oracle E-Business Suite Load Balancing Options. Venkat Perumal IT Convergence

Siemens PLM Connection. Mark Ludwig

Active-Active and High Availability

High Performance Cluster Support for NLB on Window

MagDiSoft Web Solutions Office No. 102, Bramha Majestic, NIBM Road Kondhwa, Pune Tel: /

create-virtual-server creates the named virtual server

White Paper March 1, Integrating AR System with Single Sign-On (SSO) authentication systems

IBM WEBSPHERE LOAD BALANCING SUPPORT FOR EMC DOCUMENTUM WDK/WEBTOP IN A CLUSTERED ENVIRONMENT

Deploying Windows Streaming Media Servers NLB Cluster and metasan

Uptime Infrastructure Monitor. Installation Guide

Learning GlassFish for Tomcat Users

CatDV Pro Workgroup Serve r

This presentation covers virtual application shared services supplied with IBM Workload Deployer version 3.1.

Configuring Nex-Gen Web Load Balancer

Cognos8 Deployment Best Practices for Performance/Scalability. Barnaby Cole Practice Lead, Technical Services

JBS-102: Jboss Application Server Administration. Course Length: 4 days

Building a Scale-Out SQL Server 2008 Reporting Services Farm

NetBeans IDE Field Guide

Learn Oracle WebLogic Server 12c Administration For Middleware Administrators

TIBCO Administrator User s Guide. Software Release March 2012

DEPLOYMENT GUIDE Version 1.0. Deploying the BIG-IP LTM with Apache Tomcat and Apache HTTP Server

VERITAS Cluster Server Traffic Director Option. Product Overview

Transcription:

Page 1 of 9 Published on The O'Reilly Network (http://www.oreillynet.com/) http://www.oreillynet.com/pub/a/onjava/2002/07/17/tomcluster.html See this if you're having trouble printing code examples Clustering with Tomcat by Shyam Kumar Doddavula 07/17/2002 This article describes how Web applications can benefit from clustering and presents a clustering solution that we developed for the Jakarta Tomcat Servlet Engine to provide high scalability, load-balancing, and high availability using JavaSpaces technology. Introduction With the increasing use of Web-based applications, scalability and availability are critical for their success. Implementing a clustering solution for the servers hosting the Web applications is a simple, cost-effective solution. JavaSpaces technology provides a distributed shared memory model that can be used to design a clustering solution. Unlike typical distributed system solutions, which revolve around enabling remote procedure calling or exchanging messages, solutions using this technology revolve around the ability to pass objects around. These objects typically carry all of the information needed to perform a task on a remote system, including even the code as needed, using an associative, shared, distributed memory. JavaSpaces provides a simple set of write, read, and take operations, which allow processes to put an object in the space, get a copy of an object, or take out an object from space.

Page 2 of 9 Figure 1. A distributed system using JavaSpaces (Reprinted with permission from Sun Microsystems) JavaSpaces is a core Jini technology service. The Jini programming model, with its leasing model and dynamic service discovery, provides the infrastructure needed to create a self-configuring dynamic distributed system. See the resource section for further information on these technologies. The JavaSpaces technology, combined with the Jini programming model, thus offers high spatial and temporal decoupling, making it possible to design a distributed system that is highly scalable, fault-tolerant, and dynamically configurable. In this article, we will describe a simple clustering solution for the Jakarta Tomcat servlet engine (Catalina 4.x), a popular open source implementation of the Servlet API, using these technologies. Why Clustering? Clustering solutions usually provide: Scalability High Availability Load Balancing Scalability The key question here is, if it takes time T to fulfill a request, how much time will it take to fulfill N concurrent requests? The goal is to bring that time as close to T as possible by increasing the computing resources as the load increases. Ideally, the solution should allow for scaling both vertically (by increasing computing resources on the server) and horizontally (increasing the number of servers) and the scaling should be linear.

Page 3 of 9 High Availability The objective here is to provide failover, so that if one server in the cluster goes down, then other servers in the cluster should be able to take over -- as transparently to the end user as possible. In the servlet engine case, there are two levels of failover capabilities typically provided by clustering solutions: Request-level failover Session-level failover Request-level Failover. If one of the servers in the cluster goes down, all subsequent requests should get redirected to the remaining servers in the cluster. In a typical clustering solution, this usually involves using a heartbeat mechanism to keep track of the server status and avoiding sending requests to the servers that are not responding. Session-level Failover. Since an HTTP client can have a session that is maintained by the HTTP server, in session level failover, if one of the servers in the cluster goes down, then some other server in the cluster should be able to carry on with the sessions that were being handled by it, with minimal loss of continuity. In a typical clustering solution, this involves replicating the session data across the cluster (to one other machine in the cluster, at the least). Load Balancing The objective here is that the solution should distribute the load among the servers in the cluster to provide the best possible response time to the end user. In a typical clustering solution, this involves use of a load distribution algorithm, like a simple round robin algorithm or more sophisticated algorithms, that distributes requests to the servers in the cluster by keeping track of the load and available resources on the servers. Our Solution Typical clustering solutions use a client-server paradigm to implement a distributed system as a solution, but they have limited scalability. In the space paradigm that is used here, a request is fulfilled by having an object move from one machine to another, carrying with it the present state of execution and everything else needed, including the (byte)code, if needed, using an associative, distributed, shared memory. Let us examine how the Jakarta Tomcat Servlet engine works. It uses a connector and a processor to receive and fulfill requests, as shown in Figure 2.

Page 4 of 9 Figure 2. Architecture of a Stand-alone Tomcat Servlet Engine The connectors abstract the details of receiving the request from different sources, while the processor abstracts the details of fulfilling the requests. Figure 3 below shows the architecture of our proposed clustering solution.

Page 5 of 9 Figure 3. Architecture of the Clustered Tomcat Servlet Engine The Cluster Server Connector receives the requests from the clients, and the Cluster Server Processor encapsulates the requests into RequstEntry objects and writes them into the JavaSpace. The Cluster Worker Connector then takes these requests from the JavaSpace and the Cluster Worker Processor then fulfills the request. There can be multiple instances of these Cluster Servers and Cluster Workers, and they can be distributed across a number of machines.

Page 6 of 9 The RequestEntry is defined as follows: public class RequestEntry extends net.jini.entry.abstractentry { private static int ID = 0; public RequestEntry(){ id = String.valueOf(ID++); public String id; public RemoteSocketInputStream input; public RemoteOutputStream output; The id field identifies a request. The input field is an object of type RemoteSocketInputStream that provides access to the input stream of a socket on a remote machine, and the output field is of type RemoteOutputStream that provides access to a remote output stream. When a request is received, the socket's input and output streams are wrapped with the remote stream implementations that make them accessible from a remote machine. A request entry is created with these remote streams and written into the JavaSpace by the Cluster Server Processor as in the code below: /** * Process an incoming HTTP request on the Socket that has been assigned * to this Processor. Any exceptions that occur during processing must be * swallowed and dealt with. * * @param socket The socket on which we are connected to the client */ private void process(socket socket) { RemoteSocketInputStream input = null; RemoteOutputStream output = null; try{ //had to synchronize because of a threading problem with the TC class loader synchronized(this.getclass()){ input = new RemoteSocketInputStreamImpl(socket, connector.getport()); output = new RemoteOutputStreamImpl(socket.getOutputStream()); log("socket address = " + input.getsocketaddress() +

Page 7 of 9 ", port " + input.getserverport()); RequestEntry entry = new RequestEntry(); entry.input = input; entry.output = output; requestgenerator.write(entry); catch(exception ex){ log("parse.request", ex); The Cluster Worker Connectors/Processors then take these entries and fulfill the requests, as shown in the code below: public void run() { //process requests until we receive a shutdown signal while (!stopped) { log("waiting for entry in JavaSpace"); RequestEntry requestentry = null; try{ synchronized(this){ requestentry = (RequestEntry)requestReader.take(); catch(exception ex){ log("internal error while getting request entry from JavaSpace", ex); log("got an entry " + requestentry); // process the request if (requestentry!= null) process(requestentry); What Does Our Solution Provide? This solution provides high scalability, because as the load increases, the number of Cluster Workers can be increased; also, these Cluster Workers can

Page 8 of 9 be distributed across different machines. There can be multiple instances of the JavaSpace Service running on different machines, forming groups, and the Cluster Servers can decide to write to any of them, thus keeping the network traffic that is generated manageable. The Cluster Servers and Workers use the Jini service discovery mechanism to find these JavaSpaces service implementations, so their locations do not need to be hard-coded. Thus, the solution is dynamically configurable. Use of the Jini leasing model allows additional resources to be added without bringing down the whole system. Similarly, existing resources can be taken down gracefully by not renewing the jini licenses and taking them out after the existing licenses expire. Since the distribution of requests to the different servers in the cluster is by pull rather than by push, there is no question of requests getting directed to servers that have gone down, thus providing request-level fail-over. In this solution, the session information is placed in the JavaSpaces and retrieved later using the Session ID provided by the HTTP client when needed. Thus, it provides session-level fail-over because even if the server that originally created the session dies, some other server in the cluster can carry on with the session. Since we're using the Jini leasing model, we can set a time after which the session entries in the JavaSpaces expire to the session timeout interval; this takes care of purging expired session data. Since the distribution of load is based on pull, there is automatic load balancing, as the servers with more free resources are going to pull more work. This design shifts the responsibilities of maintaining the session data to the JavaSpaces, and since there are different implementations of the JavaSpaces services that can provide persistence and also transactional capabilities, it becomes easier to provide persistent sessions if needed. Related Series: Using Tomcat Embedding Tomcat Into Java Applications -- James Goodwill shows how to create a Java application that manages an embedded version of the Tomcat JSP/servlet container. Using SOAP with Tomcat -- The Apache SOAP Project is an open source Java implementation of SOAP. This article examines how you can can create and deploy SOAP services with Apache's RPC model. Using Tomcat 4 Security Realms -- In part 4 of his Using Tomcat series, James Goodwill covers Tomcat 4, focusing on security realms using both memory and JDBC realms (with a MySQL database example). Deploying Web Applications to Tomcat -- James Goodwill takes us through the web application deployment process for the Apache Tomcat Web server. Installing and Configuring Tomcat -- James Goodwill covers the installation and configuration for the Tomcat Web Server. Java Web Applications -- James Goodwill discusses the definition, directory structure, deployment descriptor, and packaging of a Tomcat web application. Currently, we are using the space as a bag to hold the requests, but it is possible (with minor modification) to make it behave as a channel, as described in the article "Build and use distributed data structures in your JavaSpaces". Similarly, it is possible to implement a filtering service that will filter these requests; it is also possible to implement a service to prioritize these requests thus providing QoS capabilities. Limitations of Our Solution There can be more than one Cluster Server, and it makes no difference to how it all works, but HTTP clients typically use a URL to access Web resources, and the clients need to perceive the cluster as a single machine with one IP address (for server affinity), thus requiring a single Cluster Server.

Page 9 of 9 Thus, this can be single point of failure, but this limitation can be overcome by using a hardware load balancer (even then, the load balancer itself is a single point of failure), in which case this solution can be used as the Web server proxy (as described in articles on J2EE Clustering by Abraham Kang), or by using other techniques to let more than one machine serve a single domain name. Another technique is described in the article "ONE-IP: Techniques for Hosting a Service on a Cluster of Machines". Conclusions This solution provides high scalability, high availability, and good load balancing capabilities that are comparable with any other software solution. It needs low maintenance because of the dynamic self-configuration capabilities, and has good promise for implementing QoS capabilities. Download the source code for the solution. Resources "Load Balancing Web Applications," by Vivek Viswanathan (OnJava.com) Articles on J2EE Clustering by Abraham Kang (JavaWorld) "ONE-IP: Techniques for Hosting a Service on a Cluster of Machines," by Damani et. al. (Bell Laboratories, Lucent Technologies.) The "Make Room for JavaSpaces" series by Eric Freeman and Susanne Hupfer (JavaWorld) Shyam Kumar Doddavula works as a Technical Specialist for Infosys Technologies in SETLabs, the R&D division of the company. Return to ONJava.com. oreillynet.com Copyright 2003 O'Reilly & Associates, Inc.