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 Video Library
Refcards
Trend Reports

Events

View Events Video Library

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
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

Enterprise AI Trend Report: Gain insights on ethical AI, MLOps, generative AI, large language models, and much more.

2024 Cloud survey: Share your insights on microservices, containers, K8s, CI/CD, and DevOps (+ enter a $750 raffle!) for our Trend Reports.

PostgreSQL: Learn about the open-source RDBMS' advanced capabilities, core components, common commands and functions, and general DBA tasks.

AI Automation Essentials. Check out the latest Refcard on all things AI automation, including model training, data security, and more.

Related

  • SAP Hybris Clusters on Redis
  • Apache Cassandra Horizontal Scalability for Java Applications [Book]
  • Prometheus and Grafana Integration With Java Applications
  • What Do We Know About Tomcat 9.0

Trending

  • Architecture: Software Cost Estimation
  • Sprint Anti-Patterns
  • Initializing Services in Node.js Application
  • How To Optimize Your Agile Process With Project Management Software
  1. DZone
  2. Data Engineering
  3. Databases
  4. Redis-Based Tomcat Session Management

Redis-Based Tomcat Session Management

Learn what Tomcat clustering is and what problems it can solve by working together with Redis.

By 
Nikita Koksharov user avatar
Nikita Koksharov
·
Updated Aug. 23, 21 · Tutorial
Like (19)
Save
Tweet
Share
55.7K Views

Join the DZone community and get the full member experience.

Join For Free

Apache Tomcat clustering can seem a bit overwhelming to someone who doesn't fully understand it, but, actually, it's not that complex. Clustering can be defined as using a combination of load balancing, some form of session replication, and multiple server "workers" to process the balanced load.

What Problems Are Solved by Tomcat Clustering?

Some of the problems that Tomcat clustering is used to solve include the following. First, when a server is receiving too many incoming requests such that it cannot handle them efficiently. Second, when a stateful application requires, in case the server fails, a way to preserve session data. Third, a developer wants a way to change the configuration or to update their applications without interrupting service. These are the main reasons that we need to use Tomcat Cluster. But is there a proper way to use Tomcat Cluster that is particularly good?

What Is Redis?

Redis is an in-memory open-source data project. In fact, it is the most popular in-memory database that is currently available. In particular, Redisson can be used as a Redis Java client. Redisson uses Redis to empower Java applications for companies' use. It is intended to make your job easier and develop distributed Java applications more efficiently. Redisson offers distributed Java objects and services backed by Redis.

How Can Redis Be Used for Tomcat?

Redisson's Tomcat Session Manager allows you to store sessions of Apache Tomcat in Redis. It empowers you to distribute requests across a cluster of Tomcat servers. This is all done in non-sticky session management backed by Redis.

Alternative options might serialize the whole session. However, with this particular Redis Tomcat Manager, each session attribute is written into Redis during each invocation. Thanks to this advantage, Redisson Session Manager beats out other Redis-based managers in storage efficiency and optimized writes. Tomcat Session Management, in this way, is used in the most ideal way possible.

Step 1

Add RedissonSessionManager into tomcat/conf/context.xml

<Manager className="org.redisson.tomcat.RedissonSessionManager"
          configPath="${catalina.base}/redisson.conf" readMode="MEMORY" updateMode="DEFAULT"/>


readMode - read attributes mode. Two modes are available:

  • MEMORY - stores attributes in local Tomcat Session and Redis. Further Session updates propagated to local Tomcat Session using Redis-based events. Default mode.
  • REDIS - stores attributes into Redis only.

updateMode - attributes update mode. Two modes are available:

  • DEFAULT - session attributes are stored into Redis only through setAttribute method. Default mode.
  • AFTER_REQUEST - all session attributes are stored in Redis after each request.

Step 2

Copy two jars into TOMCAT_BASE/lib directory

  • redisson-all-3.10.6.jar

    • for Tomcat 6.x: redisson-tomcat-6-3.10.6.jar

    • for Tomcat 7.x: redisson-tomcat-7-3.10.6.jar

    • for Tomcat 8.x: redisson-tomcat-8-3.10.6.jar

    • for Tomcat 9.x: redisson-tomcat-9-3.10.6.jar

The reason for using Redis Tomcat Manager to do Tomcat Clusters is if you are expecting a lot of web traffic, i.e. if your site will be expanding, or if you just want a little more help to take on the load in order to increase your availability.

What Else Can Redisson Do?

Redis-based Tomcat Session Management is not the only thing Redisson can provide. Once you are done with your cluster project, check it out for its other benefits. Redisson can provide distributed Java applications. It offers different caching implementations like JCache API, Hibernate 2nd Level Cache, and Spring Cache. It supports read/write caching for databases, distributed implementations of ExecutorService and ScheduledExecutorService, and a Java-based MapReduce programming to support "large amounts of data" that is stored in Redis.

Overall, Redisson can do a lot. Tomcat Session Management can seem overwhelming but can be easily resolved with Redisson. Plus, you may find a lot of other features that meet your needs along the way.

Apache Tomcat Session (web analytics) Redis (company) clustering Database application Attribute (computing) Open source Java (programming language) In-memory database hadoop

Opinions expressed by DZone contributors are their own.

Related

  • SAP Hybris Clusters on Redis
  • Apache Cassandra Horizontal Scalability for Java Applications [Book]
  • Prometheus and Grafana Integration With Java Applications
  • What Do We Know About Tomcat 9.0

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: