21
Building High Scalability Apps with Terracotta David Reines Senior Architect Object Partners Inc. [email protected] twitter: dhreines

Building High Scalability Apps With Terracotta

Embed Size (px)

DESCRIPTION

Senior Architect David Reines will present the simple yet powerful clustering capabilities of Terracotta. David will include a brief overview of the product, an in-depth discussion of Terracotta Distributed Shared Objects, and a live load test demonstrating the importance of a well designed clustered application. David Reines is a Senior Consultant at Object Partners Inc. He has lead the development efforts of several mission-critical enterprise applications in the Twin Cities area. During this time, he has worked very closely with numerous commercial and open source JEE technologies. David has always favored a pragmatic approach to selecting enterprise application technologies and is currently focusing on building highly-concurrent distributed applications using Terracotta.

Citation preview

Page 1: Building High Scalability Apps With Terracotta

Building High Scalability Apps with Terracotta

David ReinesSenior Architect

Object Partners Inc.

[email protected]: dhreines

Page 2: Building High Scalability Apps With Terracotta

Agenda

Terracotta OverviewProductsDistributed Shared Objects (DSO)

ArchitectureDistributed Shared Objects

Roots and Instrumented ClassesLocksData StructuresObject Identity

Designing to ScaleDemo

Page 3: Building High Scalability Apps With Terracotta

Terracotta Overview

Terracotta is an open source software solution that provides JVM-level clustering.

Plugs into the Java Memory ModelUtilizes bytecode manipulation

ConsistentCreates a virtual heap across multiple nodesProvides highly optimized cluster-wide locking

AvailableTerracotta active/standby servers provide high-availabilityData persisted to disk to survive certain disaster scenarios

Terracotta Server Array provides "linear" scalability

Page 4: Building High Scalability Apps With Terracotta

Terracotta Products

Terracotta ProductsDistributed Ehcache

cache eviction algorithmswrite-through/write-behindJTA support (XA compliant)monitoring

Distributed Ehcache for HibernateJob Store for QuartzWeb Session ClusteringSpring Framework Clustering

Distributed Shared Objectsthe foundation of Terracotta Products

Page 5: Building High Scalability Apps With Terracotta

Terracotta Architecture

Client JVM(s) (L1)Application logicCommunicates with active Terracotta server(s)Supports numerous standard containersUtilize Terracotta Integration Modules (TIMs)

Terracotta Server(s) (L2) Data management

data storage (memory and disk)full-fill L1 data requests/change broadcastsdistributed garbage collection

Lock managementActive server(s) replicate data to standby server(s) in real-time

Page 6: Building High Scalability Apps With Terracotta

Deployment Options

Permanent StorageRecommended for high-availability modeStores data to disk (Berkeley-DB)Disk speed will impact performance

Active/StandbyAllows for high availabilityActive server "elected" at start-upAutomatic failover if active fails

Terracotta Server Array (Enterprise Only)Provides "linear" scalabilityMultiple active/standby "mirror groups"Transparent to the application tier

Page 7: Building High Scalability Apps With Terracotta

Terracotta Cluster

Page 8: Building High Scalability Apps With Terracotta

Open Source vs. Enterprise

Open Source VersionProduction readyHigh availabilityVery high throughput and performanceDeveloper consoleLimited to a single active server

Enterprise VersionTerracotta Server Array (Terracotta FX)Additional Enterprise Operations and Management ToolsProduction back-up and restore Certified Patches, Support

Simple upgrade from open source to enterprise version.

Page 9: Building High Scalability Apps With Terracotta

Distributed Shared Objects (DSO)

As a developer, you may never need to work directly with Terracotta DSOs.

Terracotta products such as Ehcache hide the complexity of DSOs from developers.

The concepts are still important because DSOs provide the foundation for Terracotta's products.

If needed, developers can still utilize DSOs directly.

Page 10: Building High Scalability Apps With Terracotta

RootRoot

Applications define root(s)A root and it's references are clusteredA root cannot be changed

/** * Singleton CustomerService. */private class CustomerService {@Rootprivate ConcurrentDistributedMap<Long, Customer> customers;}

Page 11: Building High Scalability Apps With Terracotta

Instrumented Classes

Instrumented ClassShared objects must be instrumentedSerializable not requiredRoot container is automatically instrumented

/** * Shared Customer. */@InstrumentedClasspublic class Customer {...}

Page 12: Building High Scalability Apps With Terracotta

Locks

Terracotta LocksProvide cluster-wide synchronizationProvide a means for terracotta "transactions"Modifications to clustered objects must occur within a clustered lock.Utilizes standard Java synchronization syntax

Lock Supportread/writesynchronous-writeReentrantReadWriteLock

Lock OptimizationGreedy locks - once obtained, no need to contact server

Page 13: Building High Scalability Apps With Terracotta

Object Identity

Objects are assigned a cluster-wide ObjectId

Object identity is maintained cluster-wide!

Multiple objects can reference the same object instance cluster-wide

Only data changes are broadcast

Not completely true when using ehcache serialization mode.Good reasons for either option. Ehcache provides the flexibility to choose per cache.

Page 14: Building High Scalability Apps With Terracotta

Designing to Scale

Partial Loading and Locality of Reference

To properly scale an application can utilize partial loading to maintain a good locality of reference .

Page 15: Building High Scalability Apps With Terracotta

Partial Loading

Consider the following example:

Map<String, ReallyBigObject>

Loading all elements into each node limits scalability.

Partial Loading a MapTerracotta faults the keys into each node in the clusterValues are faulted into node(s) as needed

Data Structures Supporting Partial LoadingDSO Data Structures Guide(i.e. LinkedBlockingQueue)

Page 16: Building High Scalability Apps With Terracotta

Locality of Reference

Always access and update the same data on the same node.

For example, CustomerId 100 is always accessed on Client JVM #1

BenefitsUses partial loading Minimizes lock recalls - greedy locksMinimizes fault ratesMinimizes flush ratesMinimizes change broadcastsReduces L1 garbage collection cycles

Page 17: Building High Scalability Apps With Terracotta

Locality of Reference (cont)

Potential Routing OptionsLoad-balancers (i.e. session, url or header properties)Custom Client Libraries

Potential Routing KeysHttpSession IdCustomerIdUserIdetc...

FailoverIf a node fails, route requests to another serverObjects transparently fault into memory

Page 18: Building High Scalability Apps With Terracotta

Designing to Scale

* Transparent Failover

Page 19: Building High Scalability Apps With Terracotta

Demo

Page 20: Building High Scalability Apps With Terracotta

Referenceshttp://www.terracotta.org/documentation/ga/product-documentation-1page

http://www.terracotta.org/confluence/display/docs/Concept+and+Architecture+Guide

http://blog.terracottatech.com/archive/2005/08/object_identity.html

Page 21: Building High Scalability Apps With Terracotta

http://www.terracotta.org/confluence/display/docs/DSO+Data+Structures+Guide

Data Structures (via terracotta.org)