tomcat cluster - events.static.linuxfound.org · • tomcat clustering overview • session...

45
Keiichi Fujino 1 October 2015 Tomcat Cluster

Upload: others

Post on 03-Jul-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Keiichi Fujino 1 October 2015

Tomcat Cluster

Page 2: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Agenda

• About me

• Tomcat Clustering Overview

• Session Replication

• Channel Component

• Other Cluster features(If time remains)

Page 3: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

About me

• Kanagawa/Japan

• Software Developer since 2002

• Apache Tomcat committer since 2010

[email protected]

Page 4: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Clustering Overview• What is Cluster?

• Performance improvement

• High availability

• Tomcat Clustering

• Cluster membership

• Session Replication

• Load balancing is not a Tomcat feature

• Use mod_jk / mod_proxy_balancer

Page 5: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Cluster Architecture

Host

Engine

Cluster

Context

ManagerClusterManager(template)

Channel

ClusterListener

Valve(ClusterValve)

LifecycleListener

ClusterDeployer

ChannelListener

MembershipListener

ChannelInterceptor

ChannelSender

ChannelReceiver

MembershipService

Create from template

Page 6: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Cluster Architecture• Cluster

• The main component of Tomcat Cluster

• Cluster Manager

• The session manager for the session replication

• Valve(Cluster Valve)

• The same as usual Valve

• Added to the request processing pipeline automatically

Page 7: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Cluster Architecture

• Cluster Deployer

• Sharing of WAR files among cluster nodes

• ClusterListener, LifecycleListener

• Listen cluster messages and events

• Channel

• Performs messaging and grouping among the cluster nodes

Page 8: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Session Replication

Session replication implementations

• All-to-All session replication

• DeltaManager (Default)

• Primary-Secondary session replication

• BackupManager

Tomcat1 Tomcat2

Tomcat4Tomcat3

Replicate to all nodes

Tomcat1 Tomcat2

Tomcat4Tomcat3

Replicate to backup node

primary secondary

Page 9: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Use constraints

• sticky session

• If you use the BackupManager, This is required

• Triggered session create/expire & set/removeAttribute methods

• Make sure that your web.xml describe the <distributable/> element

• Session attributes must implement java.io.Serializable• If some of session attributes does not implement java.io.Serializable, you

should use the sessionAttributeFilter attribute

Page 10: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

How to configure

• Configure Cluster Manager

• DeltaManager or BackupManager

• Configure Channel components

• Enable org.apache.catalina.ha.tcp.ReplicationValve

• Enable org.apache.catalina.ha.session.ClusterSessionListener

• DeltaManager only

Page 11: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Delta Replication

Delta Replication

• Replicate only the changes of session• Not all session data

• Replicate all changes of session at the time of end of request• Not replication per change of session

Page 12: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Delta ReplicationRegister Delta Info

• Add ATTRIBUTE(Attr_A, Value_A)• Add ATTRIBUTE(Attr_B, Value_B)• Remove ATTRIBUTE(Attr_A)• Add ATTRIBUTE(Attr_B, Value_BB)

TYPE ACTION NAME VALUE

ATTRIBUTE SET Attr_A Value_A

ATTRIBUTE SET Attr_B Value_B

ATTRIBUTE REMOVE Attr_A null

ATTRIBUTE SET Attr_B Value_BB

TYPE ACTION NAME VALUE

ATTRIBUTE SET Attr_A Value_A

ATTRIBUTE SET Attr_B Value_B

ATTRIBUTE REMOVE Attr_A null

ATTRIBUTE SET Attr_B Value_BB

Default : recordAllActions=false recordAllActions=true

Page 13: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Session Replication

DeltaManager

• All-to-All session replication

• Default Session Manager in Cluster environment

• For small cluster

Page 14: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

DeltaManager

Architecture

Cluster

channelReplication

ClusterSessionListener

Receive replication Message

DeltaManager

ReplicationValve

create/destroy

Delta replication

Tomcat1

Cluster

channel

DeltaManager

Tomcat2

Page 15: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

DeltaManager

BehaviorTomcat1 Tomcat2

Tomcat4Tomcat3

Replicate create/delta/destroy

Session(Primary)

Session(Non-Primary)

Session(Non-Primary)

Session(Non-Primary)

Page 16: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

DeltaManager

Node FailureTomcat1 Tomcat2

Tomcat4Tomcat3

Session(Primary)

Session(Non-Primary)

Session(Non-Primary)

Session(Non-Primary)

Node Failure

Page 17: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

DeltaManager

Node Recovery

Tomcat1 Tomcat2

Tomcat4Tomcat3

Session(Pri)

Session(Non-Pri)

Session(Pri)

Session(Non-Pri)

Session(Non-Pri)

Session(Non-Pri)

Session(Non-Pri)

Session(Non-Pri)All Session Data Message

Get All session Message

Complete Message

No Session Data

Page 18: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Session Replication

BackupManager

• Primary-Secondary session replication

• For large cluster

Page 19: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

BackupManager

Architecture

channel

Replication

ReplicationValve

create/destroy/delta

Delta replication

Tomcat1

Tomcat2

AbstractReplicatedMap

BackupManager

channel

AbstractReplicatedMap

BackupManager

Tomcat3

channel

AbstractReplicatedMap

BackupManager

Page 20: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

BackupManager

Behavior-create

Tomcat1 Tomcat2

Tomcat4Tomcat3

Replicate sessionId

Session(Primary)

Session(Backup)

Session(Proxy)

Session(Proxy)

Replicate session data

Page 21: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

BackupManager

Behavior-delta

Tomcat1 Tomcat2

Tomcat4Tomcat3

Session(Primary)

Session(Backup)

Session(Proxy)

Session(Proxy)

Replicate delta

Page 22: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

BackupManager

Behavior-destory

Tomcat1 Tomcat2

Tomcat4Tomcat3

Remove session

Session(Primary)

Session(Backup)

Session(Proxy)

Session(Proxy)

Remove session

Page 23: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

BackupManagerNode Failure

Node Failure

Tomcat1

SessionA(Primary)

SessionB(Backup)

SessionC(Proxy)

SessionB(Primary)

SessionA(Backup)

SessionC(Proxy)

SessionA(Primary)

SessionB(Proxy)

SessionA(Proxy)

SessionC(Primary)

SessionA(Backup)

SessionB(Proxy) SessionB(Proxy)

SessionA(Proxy)

SessionC(Backup)

SessionA(Proxy)

SessionB(Backup)

Promote&Select new backup&publish

Select new backup&publish

NOP

NOP NOP

newly backup

newly proxynewly backup

newly proxy

Tomcat2

Tomcat3 Tomcat4

Page 24: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

BackupManager

Access to Primary node

Tomcat1

Tomcat4Tomcat3

Session(Primary)

Session(Proxy)Session(Backup)

Node Failure

Tomcat2

Access

Page 25: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

BackupManager

Access to Backup node

Tomcat1

Tomcat4Tomcat3

Session(Primary)

Session(Proxy)Session(Backup)

Node Failure

Tomcat2

Replicate

Access

Session(Primary) Session(Backup)

Session(Proxy)

Promote newly backup

newly proxy

Page 26: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

BackupManagerAccess to Proxy node

Tomcat1

Tomcat4Tomcat3

Session(Primary)

Session(Proxy)

Session(Backup)

Node Failure

Tomcat2

Session Data

Access

Session(Primary)

Session(Proxy)

Promote

newly proxy

Proxy message

Search Backup

Page 27: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

BackupManagerNode Recovery

Tomcat1 Tomcat2

Tomcat4Tomcat3

SessionA(Backup)

SessionB(Primary)

SessionA(Primary)

SessionB(Proxy)

SessionB(Backup)

SessionA(Proxy)

SessionB(Proxy)

SessionA(Proxy)No Session Data

Send/Receive RPC Message• INIT Message

• STATE Message

• START Message

Send/Receive RPC Message• INIT Message

• START Message

Page 28: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

BackupManagerNode Recovery

Tomcat1 Tomcat2

SessionA(Primary)

SessionB(Primary)SessionB(Proxy)

SessionA(Proxy)No Session Data

Send/Receive RPC Message• INIT Message

• STATE Message

• START Message

SessionA(Backup)

SessionB(Backup)

Session Data

Page 29: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Channel

Channel

• What is Channel ?

• Messaging & Grouping component

• Responsibility

• Membership

• Send channel message

• Receive channel message

Page 30: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Channel Components

Cluster

Channel

ChannelListener

MembershipListener

ChannelInterceptor

ChannelSender

ChannelReceiver

MembershipService

ChannelCoordinator

Page 31: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Channel Components

• MembershipService

• The component which build a cluster group

• Start a multicast receivier thread and a multicast sender thread

Page 32: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Channel Components• ChannelSender

• Send the channel message to another nodes in the cluster group

• Sender Queue size is specified in poolSize attribute

• ChannelReceiver

• Receiving a channel message from other nodes in the cluster group

• Tuning of the maxThreads attribute depends on send option of channel message

Page 33: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Channel Components

• ChannelListener

• Listen received channel messages

• MembershipListener

• Listen add/remove of cluster members

Page 34: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Channel Components

• ChannelInterceptor

• Intercept a channel message and a member detection

• ChannelCoordinator

• Coordinates the ChannelInterceptors

Page 35: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Sample config<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster">・・・ ・・・<Channel className="org.apache.catalina.tribes.group.GroupChannel">

<Membership className="org.apache.catalina.tribes.membership.McastService"address="229.0.0.61“ port="45564“ frequency="500“ dropTime="4000" />

<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"address=“auto“ port=”4004“ autoBind=”100” maxThreads=“25”/>

<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter"><Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"

timeout="5000“ poolSize="25"/></Sender>

<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor" /><Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>

</Channel>・・・ ・・・

</Cluster>

Page 36: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Channel Architecture

Channel

ChannelListener MembershipListener

ChannelCoordinator

ChannelInterceptor(1)

ChannelInterceptor(N)

MembershipService ChannelSender ChannelReceiver

Notify message receive Notify member receive

Membership Messaging Send Message Receive Message

Send Message Receive Message/Member receive

Tomcat1

Page 37: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

ChannelInterceptor

TCPFailureDetector

• Main Features

• Intercept memberDisappeared events.

• Member check at the time of send errors.

• Other Feature

• Manage membership

Page 38: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

ChannelInterceptor

MessageDispatch15Interceptor

• Asynchronous send message

• Use Thread Pool

• maxThreads

• maxSpareThreads

• Make sure

• Cluster’s channelSendOptions attribute = 8 or 10 (8+2)

• BackupManager’s mapSendOptions attribute = 8 or 10 (8+2)

Page 39: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

ChannelInterceptorNotes on use with TCPFailureDetector

• The Order is important

MessageDispatch15Interceptor TCPFailureDetector

MessageDispatch15InterceptorTCPFailureDetector

Session Message

Session Message

• Intercept memberDisappeared• Member check at send errors

• Intercept memberDisappeared• Member check at send errors

Page 40: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

ChannelInterceptorStaticMembershipInterceptor

• The static membership instead of multicast

• Make sure • Disable multicast membership

• Cluster’s channelStartOptions attribute = 3• Enable TcpPingInterceptor for nodes failure detection• Enable TcpFailureDetector for membership management• The order is

TcpPingInterceptor->TcpFailureDetector->StaticMembershipInterceptor

Page 41: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

ChannelInterceptorSample config

<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor"/> <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/> <Interceptor className=

"org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor"><Member className="org.apache.catalina.tribes.membership.StaticMember"

port="4010" host="hostA" uniqueId="{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,2}" />

<Member className="org.apache.catalina.tribes.membership.StaticMember"port="4010" host="hostB" uniqueId="{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,3}" />

</Interceptor>

Page 42: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

ChannelInterceptor

ThroughputInterceptor

• Measuring the send and receive of channel messages

DomainFilterInterceptor

• Filter the members that join cluster group by the domain

Page 43: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Other Cluster featuresJvmRouteBinderValve

• Change jvmRoute of session ID to JvmRoute of the current node

• Enable sticky session again

ClusterDeployer

• Replicate the WAR among clusters

ClusterSingleSignOn

• Replicate SSO information in cluster

ClusterSingleSignOn

Page 44: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Questions?

Page 45: Tomcat Cluster - events.static.linuxfound.org · • Tomcat Clustering Overview • Session Replication • Channel Component • Other Cluster features(If time remains) About me

Thank You