DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Integrating AWS With Salesforce Using Terraform
  • Structured Logging
  • Introduction To Git
  • Authorization: Get It Done Right, Get It Done Early

Trending

  • Integrating AWS With Salesforce Using Terraform
  • Structured Logging
  • Introduction To Git
  • Authorization: Get It Done Right, Get It Done Early
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Tomcat Cluster in the Cloud

Tomcat Cluster in the Cloud

Marina Sprava user avatar by
Marina Sprava
·
Jul. 22, 13 · Interview
Like (0)
Save
Tweet
Share
3.99K Views

Join the DZone community and get the full member experience.

Join For Free

jelastic paas was specially designed for huge clustered application hosting. as we already demonstrated in our previous posts, jelastic provides session replication between pairs of server nodes with a the help of multicast and load balancer, which redirects requests to each server. such an approach guarantees session exchange between the nodes through the local net and eliminates the need to use additional software or memcached. as a result, session data is copied between servers providing high reliability, scalability and perfect fail-over capabilities.

today we will show you how to take a deeper look into clustering technology used in jelastic by the example of the tomcat application server.

tomcat cluster

on the above scheme you can see a tomcat cluster which consists of two servers and one load balancer, which handles all requests and distributes them to various nodes, according to availability and server load.

in case when one of the servers fails, the users, who were on that node get automatically switched to the other instance of this tomcat cluster. thanks to the replication, the other instance already has all the sessions of the failed node, so end-users never notice any change. also you can create multiple tomcat clusters in jelastic, so that in the highly unlikely event of whole cluster failing, users get redirected to another cluster.

to get a highly available tomcat cluster in jelastic, all you need is just click the create environment button, select tomcat 6 or 7 as the application server you want to use and switch on high availability for it.

tomcat cluster environment

note: don’t confuse horizontal scaling and ha mode in jelastic. in the first case you have multiple servers and the load is distributed evenly between the chosen number of instances with the help of load balancer. switching on of high availability mode sets replication between pair or few pairs of servers using multicast membership.

now let’s dive into the technology to see what happens when you switch on the ha button and how the tomcat cluster works on jelastic.

when you click ha a special tomcat config file is generated for each node by our system, which is called jelastic-ha.xml . here is an example:

<cluster classname="org.apache.catalina.ha.tcp.simpletcpcluster"
       channelsendoptions="4">
 
 <manager classname="org.apache.catalina.ha.session.deltamanager"
       expiresessionsonshutdown="false"
       notifylistenersonreplication="true"/>
 
 <channel classname="org.apache.catalina.tribes.group.groupchannel">
 
  <membership classname="org.apache.catalina.tribes.membership.mcastservice"
        address="228.0.0.4"
        port="${magicport}"
        frequency="500"
        droptime="3000"/>
 
  <receiver classname="org.apache.catalina.tribes.transport.nio.nioreceiver"
        address="${receiverip}"
        port="4000"
        autobind="100"
        selectortimeout="5000"
        maxthreads="6"/>
 
  <sender classname="org.apache.catalina.tribes.transport.replicationtransmitter">
  <transport classname="org.apache.catalina.tribes.transport.nio.pooledparallelsender"/>
  </sender>
 
  <interceptor classname="org.apache.catalina.tribes.group.interceptors.tcpfailuredetector"/>
  <interceptor classname="org.apache.catalina.tribes.group.interceptors.messagedispatch15interceptor"/>
 </channel>
 
  <valve classname="org.apache.catalina.ha.tcp.replicationvalve"
      filter=""/>
  <valve classname="org.apache.catalina.ha.session.jvmroutebindervalve"/>
 
  <clusterlistener classname="org.apache.catalina.ha.session.jvmroutesessionidbinderlistener"/>
  <clusterlistener classname="org.apache.catalina.ha.session.clustersessionlistener"/>
</cluster>

let’s look at the details of this file:

1. here is the major element, inside which all the other cluster elements are configured.

<cluster classname="org.apache.catalina.ha.tcp.simpletcpcluster"
        channelsendoptions="4">

the channelsendoptions flag is attached to every message sent by simpletcpcluster class or any objects that are calling the simpletcpcluster.send method.

2. the deltamanager uses the simpletcpcluster.send method to send information though the channel.

<manager classname="org.apache.catalina.ha.session.deltamanager"
      expiresessionsonshutdown="false"
      notifylistenersonreplication="true"/>

3. the group communication framework used inside tomcat called tribes , is used as the channel element here. it encapsulates everything that has to do with membership, logic and communication.

<channel classname="org.apache.catalina.tribes.group.groupchannel">

4. membership is made using multicast . tomcat cluster separation consists of a multicast address and port number. communication between nodes is realized over tcp.

<membership classname="org.apache.catalina.tribes.membership.mcastservice"
     address="228.0.0.4"
     port="${magicport}"
     frequency="500"
     droptime="3000"/>

{magicport} is a unique port number for the cluster, which is generatedon the fly from the java arguments.

5. tribes’ logic of sending and receiving data includes two components: sender and receiver. the receiver is responsible for data receiving. there is a thread pool in this element which has a maxthreads and minthreads setting. the address attribute is the host address that will be broadcasted by the membership component to the other nodes.

<receiver classname="org.apache.catalina.tribes.transport.nio.nioreceiver"
     address="${receiverip}"
     port="4000"
     autobind="100"
     selectortimeout="5000"
     maxthreads="6"/>

6. the sender component is responsible for sending messages to other nodes. the sender includes the replicationtransmitter , a special shell component, and transport sub component. messages can be sent concurrently with the nio sender and parallel with pool of senders.

<sender classname="org.apache.catalina.tribes.transport.replicationtransmitter">
 <transport classname="org.apache.catalina.tribes.transport.nio.pooledparallelsender"/>
</sender>

7. the elements of the tribes stack interceptors are:

  • tcpfailuredetector – verifies crashed members via tcp
  • messagedispatch15interceptor – dispatches messages to a thread pool to send message asynchronously
<interceptor classname="org.apache.catalina.tribes.group.interceptors.tcpfailuredetector"/>
 <interceptor classname="org.apache.catalina.tribes.group.interceptors.messagedispatch15interceptor"/>
</channel>

8. the cluster uses valves to track requests to web applications:

  • replicationvalve finds out when the request has been completed and initiates the replication
  • jvmroutebindervalve is responsible for backing up your data
<valve classname="org.apache.catalina.ha.tcp.replicationvalve"
      filter=""/>
<valve classname="org.apache.catalina.ha.session.jvmroutebindervalve"/>

9. the simpletcpcluster is a sender and receiver of the channel object, so components are registered as listeners to this cluster.

<clusterlistener classname="org.apache.catalina.ha.session.jvmroutesessionidbinderlistener"/>
<clusterlistener classname="org.apache.catalina.ha.session.clustersessionlistener"/>

as you can see, setting up high availability manually is possible, but is quite involved and needs additional research and knowledge. we automated the configuration for you and now you can set up high availability for every java application server that we support. from every one here at jelastic – enjoy!









clustering Apache Tomcat Cloud

Published at DZone with permission of Marina Sprava, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Integrating AWS With Salesforce Using Terraform
  • Structured Logging
  • Introduction To Git
  • Authorization: Get It Done Right, Get It Done Early

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: