Advanced messaging with Apache ActiveMQ

51
A Progress Software Company Advanced Messaging with Apache ActiveMQ Bosanac Dejan May 2011 1

description

Features of ActiveMQ message broker for dealing with high load, scaling and high-availability

Transcript of Advanced messaging with Apache ActiveMQ

Page 1: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

FuseSource Confidential

A Progress Software Company

Advanced Messaging with Apache ActiveMQ

Bosanac DejanMay 2011

1

Page 2: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company2

About me

Bosanac Dejan Senior Software Engineer at FUSESource - http://

fusesource.com Apache ActiveMQ committer and PMC member Co-author of ActiveMQ in Action

Page 3: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

What we are going to cover?

What is ActiveMQ The Basics Flow control Scaling High Availability Future Conclusion

3

Page 4: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

FuseSource Confidential

A Progress Software Company

What is ActiveMQ?

4

Page 5: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Apache ActiveMQ

Apache ActiveMQ• Leading Open Source messaging platform• Supported Java Standards:

o JMS 1.1, J2EE 1.4, JCA 1.5 and XA

Reliable, high performance messaging• Out-performs many legacy proprietary message queues• Configurable for many different deployments

Multi-Protocol/Multi-Language Support

5

Page 6: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Background

ActiveMQ started in 2005 at CodeHaus Moved to Apache Software Foundation in 2006 1,117,537 lines of code 24 committers Now the most widely used open source messaging

system on the planet

6

Page 7: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

FuseSource Confidential

A Progress Software Company

The Basics

7

Page 8: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Messaging is

Loosely coupled exchange of messages between applications

Location transparency Can be persistent or non-persistent Can be transactional

8

Page 9: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Topics

9

Page 10: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Topics

One message goes to 0-to-many consumers based on the current subscribers

Think like mailing lists or discussion forums Ideal for publishing business events Distributed observer pattern Allows one part of your system to notify anyone

else who may be interested in an event

10

Page 11: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Queues

11

Page 12: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Queues

Messages are load balanced across many consumers Each message goes to exactly one consumer Consumers compete for messages Its easy to browse and monitor queues Ideal for grid style applications

12

Page 13: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Challanges

Create a general messaging platform Support variety of use-cases

• Large number of clients• Large number of destinations• Slow consumers

Provide enterprise feaures• Security• High availability• Management• etc

13

Page 14: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

FuseSource Confidential

A Progress Software Company

Flow Control

14

Page 15: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Flow Control - Why?

Dealing with deep queues Dealing with slow consumers We want to prevent broker from being flooded with

messages We want to prevent broker running out of memory and

other resources

15

Page 16: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Flow Control - How?

Message Cursors Producer Flow Control

16

Page 17: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Flow Control - Cursors

17

Page 18: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Flow Control - Store-based Cursor

18

Page 19: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Flow Control - Non-persistent cursor

19

Page 20: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Flow Control - Limits

20

<destinationPolicy> <policyMap> <policyEntries> <policyEntry queue=">" memoryLimit="10mb"/> </policyEntries> </policyMap></destinationPolicy>

<systemUsage> <systemUsage> <memoryUsage> <memoryUsage limit="256 mb" /> </memoryUsage> <storeUsage> <storeUsage limit="100 gb" /> </storeUsage> <tempUsage> <tempUsage limit="10 gb" /> </tempUsage> </systemUsage></systemUsage>

Per destination

System settings

Page 21: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Flow Control - Producer Flow Control

Throttling producer speed to the speed of consumers

21

Page 22: Advanced messaging with Apache ActiveMQ

<policyEntry queue=">" producerFlowControl="true" memoryLimit="1mb"> <pendingQueuePolicy> <vmQueueCursor/> </pendingQueuePolicy></policyEntry>

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Flow Control - VM Cursor

22

Page 23: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

FuseSource Confidential

A Progress Software Company

Scaling

23

Page 24: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Scaling - Types

Vertical scaling Horizontal scaling Traffic partitioning

24

Page 25: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Vertical Scaling

Increase load capacity using a single broker can handle.

Problems:• Thread count• Memory usage• CPU usage

25

Page 26: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Vertical Scaling - Threads

What are threads used for• For Connections - Thread per Connection (blocking transport)• For Dispatching - Thread per Destination

26

Page 27: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Vertical Scaling - Number of Connections

Use non-blocking transport

<transportConnectors> <transportConnector name="nio" uri="nio://0.0.0.0:61616"/> </<transportConnectors>

Enables handling large number of clients

27

Page 28: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Vertical Scaling - Number of Destinations

Don’t use dedicated task runner

ACTIVEMQ_OPTS="-Dorg.apache.activemq.UseDedicatedTaskRunner=false"

Use optimized dispatch for queues<destinationPolicy> <policyMap> <policyEntries> <policyEntry topic=">" optimizedDispatch="true">

... </policyEntry> </policyEntries> </policyMap></destinationPolicy>

28

Page 29: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Vertical Scaling - Memory

Give broker enough memory

ACTIVEMQ_OPTS="-Xmx2048M -Dorg.apache.activemq.UseDedicatedTaskRunner=false"

Configure big enough memory usage

<systemUsage> <systemUsage> <memoryUsage> <memoryUsage limit="1024 mb" /> </memoryUsage> ...

</systemUsage></systemUsage>

29

Page 30: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Vertical Scaling - CPU

Disable tight encoding

It uses more CPU to create smaller packets

uri = "failover://(tcp://localhost:61616wireFormat.tightEncodingEnabled=false)";

30

Page 31: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Vertical Scaling - Conclusion

There is a limit to the scalability a single machine can give

31

Page 32: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Horizontal Scaling

Increase load capacity using networked brokers

Concepts: Network of Broker

32

Page 33: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Horizontal Scaling - Network of Brokers

33

Page 34: Advanced messaging with Apache ActiveMQ

<networkConnector name="broker1-broker2" uri="static:(tcp://broker2:61617)" dynamicOnly="true" prefetchSize="1000" conduitSubscriptions="true" decreaseNetworkConsumerPriority="true" suppressDuplicateTopicSubscriptions="true" networkTTL="3"> </networkConnector>

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Horizontal Scaling - NOB Usage

34

Configuration

failover://(tcp://broker1:61616,tcp://broker2:61616)?randomize=true

Connecting

Page 35: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Horizontal Scaling - Conclusion

More latency in processing messages Beware of complex topologies

35

Page 36: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Hybrid Scaling

Partition traffic to more non-connected brokers

36

Page 37: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Hybrid Scaling - Conclusion

Pros• You can use all the tuning techniques used in Vertical scaling• Have better Horizontal scaleability than using Network Of

Brokers (Less broker cross talk) Cons

• Added complexity required on the end user Application

37

Page 38: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

FuseSource Confidential

A Progress Software Company

High Availability

38

Page 39: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

High Availability

Pure Master/Slave JDBC Master/Slave Shared File System Master/Slave

39

Page 40: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Pure Master-Slave

40

Page 41: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Pure Master-Slave

Shared nothing Fully replicated

• All messages• All acknowledgements• All transactions

Slave does not start any transports or network connections

41

Page 42: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

JDBC Master-Slave

42

Page 43: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

JDBC Master-Slave

Extreme reliability – but not as fast Recommended if already using an enterprise database No restriction on number of slaves Simple configuration

43

Page 44: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Shared Storage Master-Slave

44

Page 45: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Shared Storage Master-Slave

Recommended if you have a SAN No restriction on number of slaves Simple configuration N.B. – ensure file locking works – and times out – NFSv4

good!

45

Page 46: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

FuseSource Confidential

A Progress Software Company

Future

46

Page 47: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Future - ActiveMQ Apollo

http://activemq.apache.org/apollo

ActiveMQ 5.x reached scalability and performance limits with the current architecture

New broker core

47

Page 48: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Future - ActiveMQ Apollo

Reactor Based Thread Model Scala 2.8 Implementation Protocol Agnostic REST Based Management

48

Page 49: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Future - ActiveMQ Apollo Performance

49

http://hiramchirino.net/blog

10 producers/10 consumerssingle topicusing Stomp 20 byte payload

Page 50: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Conclusions

Dynamic community Leading in terms of messaging innovation Built for Enterprise Scalable, Good Performance, Reliable

50

Page 51: Advanced messaging with Apache ActiveMQ

Copyright © 2011 Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved. A Progress Software Company

Questions?

ActiveMQ Web sites: • http://activemq.apache.org/• http://fusesource.com/products/enterprise-activemq/

Blog: • http://www.nighttale.net/

Twitter: • http://twitter.com/dejanb• http://twitter.com/fusenews

51