29
© JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban ([email protected]) Lead JGroups, Manager Clustering Group

© JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban ([email protected]) Lead JGroups, Manager Clustering Group

Embed Size (px)

Citation preview

Page 1: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

© JBoss Inc. 2006

JBoss Clustering An Overview

Bela Ban ([email protected])Lead JGroups, Manager Clustering Group

Page 2: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

2

© JBoss Inc. 2006

Topics

• What is clustering?• JBoss/JEMS Clustering Components

JGroups, JBoss Cache, HA-JNDI, SLSBs, SFSBs, HTTP session replication, Entity beans, EJB3 and POJO Clustering

Page 3: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

3

© JBoss Inc. 2006

Why JBoss Clustering?

• Transparent No stub re-compiling! Client doesn’t know about clustering

aspect Cluster is maintained automatically Modular/stack approach

• Open source No extra cost to activate clustering Fairly robust 24/7 production support

Page 4: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

4

© JBoss Inc. 2006

Clustering Terminology

• Scalability I want to handle x times the number of concurrent access than

what I have now• High availability

Services are accessible with reasonable (and predictable) response times at any time

E.g., 99.999 (5 Nines in Telco)• Load balancing

A way to obtain high availability and better performance by dispatching incoming requests to different servers

Session affinity (or stickiness)• Failover

Process can continue when it is re-directed to a “backup” node because the original one fails

State needs to be available on backup• Fault tolerance

A service that guarantees strictly correct behavior despite system failure

Page 5: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

5

© JBoss Inc. 2006

Clustering Overview

Load Balancer

State Replication

Failover

R1

R1

R2

R2

R3

R3

Page 6: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

6

© JBoss Inc. 2006

JBoss Thin Client Clustering

• Front end load balancer Software

• Apache httpd and JBossWeb Apache with mod_jk/mod_proxy JBossWeb (Tomcat on steroids)

Hardware• F5 Big IP

Page 7: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

7

© JBoss Inc. 2006

JBoss Fat Client Clustering

• Client uses smart proxy retrieved from JNDI• HA smart proxy

Based on Remoting (EJB3.0) or RMI (EJB2.1) Has load balancing policy, e.g., Round-Robin Has failover capability (sticky), e.g., detect call

failure

• HA smart proxy has logic inside• Logic is pluggable, users can provide their

own Failover policy Load balancing, e.g. based on load or weight

Page 8: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

8

© JBoss Inc. 2006

Running JBoss Cluster – Basic Steps

• Use JBoss’ “all” configuration run.bat -c all ./run.sh -c all

• The “all” configuration contains everything needed for clustering: It has all the libraries for clustering

• JGroups.jar, jboss-cache.jar Clustered beans (cluster-service.xml) HA-JNDI HTTP session replications (tc5-cluster-

service.xml) Farming HA-JMS

Page 9: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

9

© JBoss Inc. 2006

Clustering divided in 3 parts

• Client-cluster communication Formerly HA-RMI, no HA-Remoting Load balancing and failover logic for fat

clients

• State replication (inside cluster) JBoss Cache

• HTTP session, SFSBs, DistributedState

• Cluster communication (inside cluster) Method calls across all cluster nodes

• Cache invalidation, HA-JNDI, Farming

Page 10: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

10

© JBoss Inc. 2006

Clustering Stack

JGroups

JBossCache

DRM

HA

-JN

DI

HT

TP

SF

SB

En

tity

Hibernate

Distributed RPC,

Membership

Me

ssa

gin

g

HAServices

DRM

Fa

rmin

gHA-

SingletonH

A-

Re

mo

ting

Dis

trib

ute

d

Sta

te

jBp

m

Page 11: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

11

© JBoss Inc. 2006

What is JGroups?

• A reliable group messaging library• Reliable messaging

Sequence ordering• FIFO or total ordering

Flow control Acknowledgement Fragmentation

• Manage group membership Join Leave Shun

Page 12: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

12

© JBoss Inc. 2006

What is JBoss Cache?

• An in-memory, replicated, transactional, persistent, and fine-grained cache system

• Uses JGroups as the messaging layer• Ideal for state replication

Transactional Persistent (and passivation) Fine-grained field-level replication Sub-partitioning, Buddy Replication

Page 13: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

13

© JBoss Inc. 2006

HA-JNDI

• Clustered JNDI

Node 1

HA-JNDI

JNDI

Node 2

JNDI

Node 3

HA-JNDI

JNDI

HA-JNDI

Partition "Main"

Page 14: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

14

© JBoss Inc. 2006

• Local proxies Local proxies have direct reference to container localInvoke() creates invocation in container

• Remote proxies Remote proxies create invocation on client (method, args,

ObjectName) Communicate via Remoting framework

HA Smart Proxies

Client JVM

Dispatcher

Dispatcher

Server JVM

011101

Typed Interface

Remote Proxy

RemotingConnectorRemotingConnector

AOP ContainerInvocation

Port 3873ClientClient

dynamicInvoke(Invocation)

localInvoke(Method, args)

Local clientLocal client

Typed Interface

Local Proxy

JBoss Remoting

Page 15: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

15

© JBoss Inc. 2006

JBoss Remoting

• JBoss Remoting is a framework with a single, simple API for making network based invocations and other network related services.

• Client – the external API access point for client code.• Client/Server Invoker – protocol specific implementation. For example,

SocketClientInvoker and SocketServerInvoker.• Invocation Handler – end target interface implemented by user that

receives the invocation from the client.

Page 16: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

16

© JBoss Inc. 2006

SFSB Configuration in EJB 2

<enterprise-beans> <session> <ejb-name> ClusteredSessionBean </ejb-name> <jndi-name> ClusteredSessionBean </jndi-name> <clustered>True</clustered> <cluster-config> <partition-name>MyPartition</partition-name> <home-load-balance-policy> org.jboss.ha.framework.interfaces.RoundRobin </home-load-balance-policy> <bean-load-balance-policy> org.jboss.ha.framework.interfaces.FirstAvailable </bean-load-balance-policy> </cluster-config> </session>

<enterprise-beans> <session> <ejb-name> ClusteredSessionBean </ejb-name> <jndi-name> ClusteredSessionBean </jndi-name> <clustered>True</clustered> <cluster-config> <partition-name>MyPartition</partition-name> <home-load-balance-policy> org.jboss.ha.framework.interfaces.RoundRobin </home-load-balance-policy> <bean-load-balance-policy> org.jboss.ha.framework.interfaces.FirstAvailable </bean-load-balance-policy> </cluster-config> </session>

Page 17: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

17

© JBoss Inc. 2006

import org.jboss.ejb3.remoting.Clustered;

@Stateful

@Clustered (loadBalancePolicy = FirstAvailable.class, partition = ”MyPartition”)

public class ClusteredSessionBean implements ClusteredSession {

}

import org.jboss.ejb3.remoting.Clustered;

@Stateful

@Clustered (loadBalancePolicy = FirstAvailable.class, partition = ”MyPartition”)

public class ClusteredSessionBean implements ClusteredSession {

}

SFSB Configuration in EJB3

Page 18: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

18

© JBoss Inc. 2006

Entities

• Use JBoss Cache as Hibernate’s 2nd level cache Default cache in ejb3-entity-cache-service.xml

• jboss.cache:service=EJB3EntityTreeCache Configure in META-INF/hibernate.cfg.xml per app

Page 19: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

19

© JBoss Inc. 2006

Entities

<hibernate-configuration>

<session-factory>

<!-- Clustered cache with TreeCache -->

<property name="cache.provider_class">org.jboss.ejb3.entity.TreeCacheProviderHook</property>

<!– Object Name of cache to use -->

<property name="treecache.mbean.object_name">jboss.cache:service=EJB3EntityTreeCache</property>

<!-- Define cached entities and collections -->

<class-cache class="org.jboss.ejb3.tutorial.clusteredentity.bean.Customer" usage="transactional"/>

<class-cache class="org.jboss.ejb3.tutorial.clusteredentity.bean.Contact" usage="transactional"/>

<collection-cache collection="org.jboss.ejb3.tutorial.clusteredentity.bean.Customer.contacts" usage="transactional"/>

</session-factory>

</hibernate-configuration>

<hibernate-configuration>

<session-factory>

<!-- Clustered cache with TreeCache -->

<property name="cache.provider_class">org.jboss.ejb3.entity.TreeCacheProviderHook</property>

<!– Object Name of cache to use -->

<property name="treecache.mbean.object_name">jboss.cache:service=EJB3EntityTreeCache</property>

<!-- Define cached entities and collections -->

<class-cache class="org.jboss.ejb3.tutorial.clusteredentity.bean.Customer" usage="transactional"/>

<class-cache class="org.jboss.ejb3.tutorial.clusteredentity.bean.Contact" usage="transactional"/>

<collection-cache collection="org.jboss.ejb3.tutorial.clusteredentity.bean.Customer.contacts" usage="transactional"/>

</session-factory>

</hibernate-configuration>

Page 20: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

20

© JBoss Inc. 2006

Future

@Entity

@Replicated(mode=asynchronous,type=BuddyReplication,BackupCopies=1)

public class Pojo {

@id

long key;

@transient

int cacheID;

}

@Entity

@Replicated(mode=asynchronous,type=BuddyReplication,BackupCopies=1)

public class Pojo {

@id

long key;

@transient

int cacheID;

}

• Common set of annotations @Replicated, @Singleton, @N-lton, @Farmed,

@Remote

• Integration into EJB3 (detach and attach extended to replication)

Page 21: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

21

© JBoss Inc. 2006

HTTP Session Replication

• JBossWeb• Replication granularity

Session Modified attributes Modified fields

• Implemented using JBoss Cache

Page 22: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

22

© JBoss Inc. 2006

Granularity: SESSION

• Entire http session is replicated• User defines whether getAttribute()

call marks a session as dirty If attribute value is mutable, the

application can modify session state without calling setAttribute()

Operates blindly (application may not have changed the object)

After each HTTP request the entire session is serialized and replicated

Page 23: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

23

© JBoss Inc. 2006

Granularity: SESSION

// … if replication triggered by getAttribute() is disabled:

Pojo pojo = (Pojo)session.getAttribute(“pojo”);

pojo.setName(“Ben”);

session.setAttribute(“pojo”, pojo); // Done manually to replicate the session

// … if replication triggered by getAttribute() is enabled:

Pojo pojo = (Pojo)session.getAttribute(“pojo”); // Session will be replicated

return pojo.getName(); // Pojo was not actually changed

// … if replication triggered by getAttribute() is disabled:

Pojo pojo = (Pojo)session.getAttribute(“pojo”);

pojo.setName(“Ben”);

session.setAttribute(“pojo”, pojo); // Done manually to replicate the session

// … if replication triggered by getAttribute() is enabled:

Pojo pojo = (Pojo)session.getAttribute(“pojo”); // Session will be replicated

return pojo.getName(); // Pojo was not actually changed

Page 24: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

24

© JBoss Inc. 2006

Granularity: ATTRIBUTE

• Only attributes marked as dirty are replicated. More efficient than session granularity User still needs to manage object relationship

• Can still configure whether getAttribute() marks the attribute as dirty

Pojo pojo = (Pojo)session.getAttribute(“pojo”);

pojo.setName(“Ben”);

session.setAttribute(“pojo”, pojo); // Only attribute “pojo” gets replicated!

Pojo pojo = (Pojo)session.getAttribute(“pojo”);

pojo.setName(“Ben”);

session.setAttribute(“pojo”, pojo); // Only attribute “pojo” gets replicated!

Page 25: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

25

© JBoss Inc. 2006

Granularity: FIELD

• Replication is on Pojo field level where Pojo has to be instrumented with AOP Annotation or XML

• Object relationships are maintained• Available beginning with JBoss 4.0.4

Person joe = (Person)session.getAttribute(“joe”);

joe.setName(“joe”); // Only this field gets replicated.

Person mary = (Person)session.getAttribute(“mary”);

mary.setAge(41); // Only this field gets replicated.

Address addr = new Address(“San Jose”, 95123);

joe.setAddress(addr);

mary.setAddress(addr); // addr only gets replicated once; shared ref is maintained

Person joe = (Person)session.getAttribute(“joe”);

joe.setName(“joe”); // Only this field gets replicated.

Person mary = (Person)session.getAttribute(“mary”);

mary.setAge(41); // Only this field gets replicated.

Address addr = new Address(“San Jose”, 95123);

joe.setAddress(addr);

mary.setAddress(addr); // addr only gets replicated once; shared ref is maintained

Page 26: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

26

© JBoss Inc. 2006

Granularity: FIELD

• When a Pojo object size is huge, e.g., a long List of size 100K, field level replication is efficient!

Subsription subs = (Subscription)session.getAttribute(“subscription”);// What if list is size of 100K?List mailingList = (List)subs.getMailingList(); Person joe = findSubscriber(“joe”, mailingList);joe.getAddress().setZip(94086); // Only replicates this field!!

Subsription subs = (Subscription)session.getAttribute(“subscription”);// What if list is size of 100K?List mailingList = (List)subs.getMailingList(); Person joe = findSubscriber(“joe”, mailingList);joe.getAddress().setZip(94086); // Only replicates this field!!

Page 27: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

27

© JBoss Inc. 2006

Clustering – Configuration

• Session replication is enabled per web application in WEB-INF/web.xml

• Add <distributable/> to your webapp• JBoss specific stuff (async vs sync

replication) goes into WEB-INF/jboss-web.xml

Page 28: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

28

© JBoss Inc. 2006

Links

• Details on Clustering Documentation

• http://docs.jboss.com JBoss AS chapters 16 (Clustering) & 17

(JBossCache and JGroups) http://www.jboss.com/products/jbosscache http://www.jboss.com/products/jgroups

Webinars• http://www.jboss.com/services/

online_education Training

• http://www.jboss.com/services/training/clustering (next: Berlin March 21-24)

Page 29: © JBoss Inc. 2006 JBoss Clustering An Overview Bela Ban (bela@jboss.com) Lead JGroups, Manager Clustering Group

© JBoss Inc. 2006

Questions ?