Exploring Terracotta

32
Exploring Terracotta Alex Miller (@puredanger)

description

How Terracotta enables scaled Spring/Hibernate applications. Presented at Chicago JUG in March 2009 by Alex Miller (http://tech.puredanger.com / @puredanger)

Transcript of Exploring Terracotta

Page 1: Exploring Terracotta

Exploring Terracotta

Alex Miller (@puredanger)

Page 2: Exploring Terracotta

Agenda

• Architecture and scale

• Examinator reference application

• What do people use it for?

• How does it work?

• Terracotta 3.0

Page 3: Exploring Terracotta

Applications in Three Tiers

Server

Database

Client

Page 4: Exploring Terracotta

How do we scale?

Server

Database

Client

Server

Client

Server

Client

Page 5: Exploring Terracotta

But what about failover?

Page 6: Exploring Terracotta

Option 1: Servers share state

Server

Database

Client

Server

Client

Server

Client

Page 7: Exploring Terracotta

How?

• RMI

• JMS

• Custom (JGroups, etc)

Page 8: Exploring Terracotta

Option 2: Database (“stateless”)

Server

Database

Client

Server

Client

Server

Client

Page 9: Exploring Terracotta

Stateless == “State in the database”

• Database load

• Serialization to and from the database

• Network bandwidth

• Object / relational mapping due to impedance mismatch

Page 10: Exploring Terracotta

Option 3: Terracotta!

Server

Client

Terracotta

Server

Client

Terracotta

Server

Client

Terracotta

DatabaseTerracotta

Server

Instance

Terracotta

Server

Instance

Page 11: Exploring Terracotta

Why is this better?

• Hub and spoke vs peer to peer

• Avoid object / relational translation

• Avoid serialization

• Reduce database overload

• Programming model you already know

• Focus on your app, not scalability and high availability

Page 12: Exploring Terracotta

Agenda

• Architecture and scale

• Examinator reference application

• What do people use it for?

• How does it work?

• Terracotta 3.0

Page 13: Exploring Terracotta

Examinator

• Terracotta reference web application

• Online exams

• “Session” use case

• http://reference.terracotta.org

Page 14: Exploring Terracotta

Examinator stack

• Spring-based stack

• MVC

• Web Flow

• Security

• Transactions

• Open source

• Tomcat / Jetty

• Hibernate / JPA

• Site Mesh

• Freemarker

View

Model

Controller

Service

DAO

Domain

Spring Web FlowSpring MVCSitemesh

JPAHibernate

Freemarker

Spring Security

Page 15: Exploring Terracotta

What state should go in Terracotta?

Memory Terracotta Database

Data Lifetime

Appro

priate

ness

Page 16: Exploring Terracotta

Examinator Terracotta Usage

• User registration codes

• Password reset codes

• Exam cache

• Session clustering

• Spring security (via session)

• Spring web flow (via session)

• Exam in progress session - answers, choice ordering, marked to review

Page 17: Exploring Terracotta

Demo

Page 18: Exploring Terracotta

Agenda

• Architecture and scale

• Examinator reference application

• What do people use it for?

• How does it work?

• Terracotta 3.0

Page 19: Exploring Terracotta

Business Use Cases

• Distributed cache

• Clustered HTTP sessions

• Batch processing

• Grid

• Messaging and events

Page 20: Exploring Terracotta

Terracotta Elements

• Replicated sessions

• Async processor

• Cache evictor

• ConcurrentStringMap

• Queues

• Master-worker

• TC Cache

Page 21: Exploring Terracotta

Who Uses It?

• e-Commerce

• Online gaming

• Financial services

• Travel & leisure

• Social networking

Page 22: Exploring Terracotta

Agenda

• Architecture and scale

• Examinator reference application

• What do people use it for?

• How does it work?

• Terracotta 3.0

Page 23: Exploring Terracotta

Core Concepts

• Roots

• Instrumented Classes

• Locks

• Integration Modules

Page 24: Exploring Terracotta

Clustered Heap

App App app = new App();app.run();

Page 25: Exploring Terracotta

Clustered Heap

EmployeeManager employeeMgr = new EmployeeManager();

Object lock = new Object();Map<String,Employee> =

new HashMap<String,Employee>();

EmployeeManager

HashMap employees

Object lock

App

Page 26: Exploring Terracotta

Clustered Heap

EmployeeManager

HashMap employees

Object lock

Employee

App

"U99411"

Employee.ACTIVE == 1

"Gandalf"

Employee employee = new Employee(

“U99411”, “Gandalf”, Employee.ACTIVE);

Page 27: Exploring Terracotta

Clustered Heap

EmployeeManager

HashMap employees

Object lock

"U99411" Employee

App

"U99411"

Employee.ACTIVE == 1

"Gandalf"

employeeMgr.addEmployee(employee);

synchronized(lock) { employees.put(e.getId(), e);}

Page 28: Exploring Terracotta

Clustered Heap

EmployeeManager

HashMap employees

Object lock

"U99411"

"U23526"

Employee

Employee

App

"U99411"

Employee.ACTIVE == 1

"Gandalf"

"U23526"

Employee.ACTIVE = 1

"U99411"

Page 29: Exploring Terracotta

Let’s look at how to do that...

Page 30: Exploring Terracotta

Agenda

• Architecture and scale

• Examinator reference application

• What do people use it for?

• How does it work?

• Terracotta 3.0

Page 31: Exploring Terracotta

Terracotta 3.0

• Server Array Striping - server scalability

• Operations Center / Developer Console - new dashboard, DGC stats

• Cluster events API - topology, data locality

• Application groups - sharing data across heterogeneous applications

• Platform support - Oracle WebLogic 10.2, 10.3 and RHEL 5.0

Page 32: Exploring Terracotta

Thanks!

• Terracotta Open Source JVM clustering:

• http://www.terracotta.org

• Apress: “The Definitive Guide to Terracotta”

• by Ari Zilka, Alex Miller, Geert Bevin, Jonas Boner, Orion Letizi, Taylor Gautier

• Alex Miller

• @puredanger

• http://tech.puredanger.com