Velocity Conference '13: Asynchronous messaging for performance optimization, featuring RabbitMQ


Published on

How do Google, Twitter, and Instagram ensure fast application performance at scale? One technique is asynchronous messaging using RabbitMQ to prevent application bottlenecks. In this session, we’ll cover common asynchronous messaging patterns and how to implement them in RabbitMQ, common pitfalls to avoid, and how to cluster RabbitMQ for increased scalability and reliability.

Published in: Technology
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Now that I’ve provided some background on what AMQP, it is time to explain a few key AMQP concepts. Like most messaging platforms, RabbitMQ supports the concept of point to point messaging, which is just a fancy way of saying, I have a single message that needs to be sent to a single recipient. In AMQP we use a “Direct Exchange” to do point to point messaging.The cornerstone of AMQP is the concept of an “exchange”. Exchanges are stateless message routers that handle all incoming messages. You will bind an exchange to a message queue, in this case, we will create a “binding” called “marriott” that will route hotel booking messages from the exchange to the “marriott” queue. The “P” icon is for message producers. A message producer will send a message using a “routing” key. I this case, the routing key will match the binding name, but that is not a requirement. “C” stands for a message consumer. Message consumers will connect directly to the RabbitMQ server and queue. You can have as many consumers as you want and those consumers usually stay connected to the messaging system and pull messages as fast as they can process them. The message producer will send message one, two and three. Each message will be queued in a “Weak FIFO” order and processed first in/first out style. It is important to note that RabbitMQ does not guarantee message ordering and it is a bad idea to require message ordering for application to application communication, because it is a performance killer.
  • Fan-out exchanges have all of the same characteristics of a Direct Exchange except for one key difference. A Fanout exchange is known as a “publish-subscribe” mechanism, which is a fancy way of saying that I need to send a single message to multiple recipients, very similar to an email distribution list. Any queue bound to a fan-out exchange will receive any message sent to the exchange. And, message consumption of each queue will be dependent on the number of consumers and speed of message consumption.
  • The fan-out exchange provides a simple publish-subscribe model, but AMQP also supports a more powerful content based router mechanism called a topic exchange. In this example, we have three different queues, one for all hotel bookings, whether they are made via orbitz, travelocity or expedia, one for just orbitz bookings and another for orbitz bookings to the marriott hotel chain. We will use a binding pattern to control message flow. For the first queue, any message that has a routing key that starts with “booking.” will go to the all_bookings queue because we are using the pound sign, a multi-word pattern symbol. The second queue is bound by an asterisk which will match all single word values. Our last binding requires an exact match because it doesn’t use an asterisk or pound symbol.The first message goes to all three queues. The second message doesn’t match the routing key pattern for queue #3. The third message only matches our least specific filter, “all_bookings”.
  • Design guidance from that “easy to use” isn’t in this copy. That’s because it’s implied with the tagline “messaging that just works” and the extensive list of tutorial links.
  • More:
  • James Manyika et al. “Big data: The next frontier for innovation, competition and productivity”, McKinsey Global Institute, Tech rep. May 2011
  • Velocity Conference '13: Asynchronous messaging for performance optimization, featuring RabbitMQ

    1. 1. 1Pivotal Confidential–Internal Use Only 1Pivotal Confidential–Internal Use Only Asynchronous Messaging for Performance Optimization Al Sargent Director, Product Marketing Pivotal Velocity Conference 2013 June 20, 2013
    2. 2. 2Pivotal Confidential–Internal Use Only About me  Now: Application Fabric team @ Pivotal  Previously: SpringSource/VMware/RabbitMQ since 2010  Earlier: Sauce Labs, Wily, Mercury, Oracle
    3. 3. 3Pivotal Confidential–Internal Use Only Diagram adapted from History of Messaging
    4. 4. 4Pivotal Confidential–Internal Use Only Typical use cases for Messaging  Event I need to know when to do something  Data fragment I need to give you a piece of this data without you needing to understand the whole schema  Routing Control who gets which message, without changing sender and receiver  Publish Tell everyone who wants to know about this  Batch Producer and consumer can run at independent times  Telemetry Metadata on servers, devices, etc.  Load share Add more consumers to scale up
    5. 5. 5Pivotal Confidential–Internal Use Only AMQP introduction • AMQP (Advanced Message Queuing Protocol) is an open standard application layer protocol for message oriented middleware – It is an open protocol (like TCP, HTTP, SMTP, and so on) • The defining features of AMQP are: – Message orientation – Queuing – Routing (including point-to-point and publish-and-subscribe) – Reliability – Security • AMQP mandates the behaviour of the messaging provider and client – Implementations from different vendors are truly interoperable – Previous attempts to standardise middleware have focussed at the API level • This approach did not create interoperability – Instead of merely defining an API, AMQP defines a wire-level protocol • A wire-level protocol is a description of the format of the data that is sent across the network as a stream of octets • Any tool that can create and interpret messages that conform to the defined wire-level protocol can interoperate with any other compliant tool, irrespective of implementation language
    6. 6. 6Pivotal Confidential–Internal Use Only AMQP motivation • AMQP was born of frustration! – Message oriented middleware needs to be everywhere in order to be useful, but… – Traditionally dominant solutions are typically very proprietary • They are frequently too expensive for everyday use • They invariably do not interoperate – The above issues with proprietary solutions have resulted in numerous home-grown developments • Custom middleware solutions • Custom adaptors – The net result for a large enterprise is middleware hell • Hundred’s of applications, thousand’s of links • Every other connection is different • Massive waste of effort – Costly to implement – Costly and difficult to maintain
    7. 7. 7Pivotal Confidential–Internal Use Only AMQP Comparison with other protocols AMQP can accommodate all of the above as use-cases… and switch between them (open, ubiquitous, and adaptable) Protocol Comments SMTP Unreliable, slow HTTP Synchronous, semi-reliable, no routing XMPP No delivery fidelity or queue management FTP Point to point, transient, does not work well with NAT/SSL MQ Exactly once TCP At least once, reliable but short lived, no application-level state management UDP Fast but has no delivery guarantees
    8. 8. 8Pivotal Confidential–Internal Use Only AMQP scales of deployment Type of deployment Possible scenario Developer/casual use 1 server, 1 user, 10 queues, 1 message per second Production application 2 servers, 10-100 users, 10-50 queues, 25 messages per second Departmental mission critical application 4 servers, 100-500 users, 50-100 queues, 250 messages per second Regional mission critical application 16 servers, 500-2,000 users, 100-500 queues and topics, 2,500 messages per second Global mission critical application 64 servers, 2K-10K users, 500-1000 queues and topics, 25,000 messages per second Market data (trading) 200 servers, 5K users, 10K topics, 250K messages per second As well as volume, the latency of message transfer is often important; AMQP implementations can deliver messages with latencies of less than 200μs AMQP implementations can cover deployment at different levels of scale ranging from trivial to the mind-boggling... no job too big or too small.
    9. 9. 9Pivotal Confidential–Internal Use Only AMQP concepts Each message is stateless Consumers create queues; these buffer messages for push to consumers Queues are stateful, ordered, and can be persistent, transient, private, shared. Exchanges are stateless routing tables. Consumers tell queues to bind to named exchanges; each binding has a pattern e.g. “tony” or “*.ibm.*” Producers send messages to exchanges with a routing key e.g. “tony”, or ordered set of keys e.g. “” Exchanges route messages to queues whose binding pattern matches the message routing key or keys
    10. 10. 10Pivotal Confidential–Internal Use Only M3M1 M2 AMQP direct exchanges Queue BindingRouting key • Point to point messaging • A single message that needs to be sent to a single recipient • Can have multiple consumers (load will be balanced across them)
    11. 11. 11Pivotal Confidential–Internal Use Only AMQP fan-out exchange • A fan-out exchange is a “publish-subscribe” mechanism • Used to send a single message to multiple recipients (very similar to an email distribution list) • Any queue bound to a fan-out exchange will receive any message sent to the exchange • Message consumption of each queue will be dependent on the number of consumers and speed of message consumption M3M1 M2 M3M1 M2 M3M1 M2 Queue 1 Queue 1 Queue 3 Same message sent to multiple queues/recipients
    12. 12. 12Pivotal Confidential–Internal Use Only M1 M2 M1 M2 M3 M1 AMQP topic exchange Queue 1 Queue 2 Queue 3 Binding pattern B Binding pattern C Binding pattern A • Content-based routing mechanism • Messages posted to queues based on binding pattern (PCRE used) • Very powerful mechanism
    13. 13. 13Pivotal Confidential–Internal Use Only RabbitMQ: Modern Messaging for the Cloud Multi-geo, cloud-scale Message Bus RabbitMQ Message Broker AMQP, JMS, MQTT, STOMP, HTTP, HTTPS… Point-to-point and pub-sub Virtual hosts, dynamic configuration Cluster within single datacenter Federate across multiple datacenters Cloud Services DevicesApplications
    14. 14. 14Pivotal Confidential–Internal Use Only RabbitMQ: Run Everywhere, Connect Anything Hundreds of other clients C Frameworks Languages Operating Systems
    15. 15. 15Pivotal Confidential–Internal Use Only • Problem: A tightly coupled Grails Application is serving ads to a web page. Ads are refreshed every four hours, using a synchronous batch update process. Then, a new business guideline is introduced, which requires the refresh rate of the ads to be increased by 50 percent. • Solution: To increase the refresh rate without putting additional strain on the existing servers, employ a solution utilizing RabbitMQ. Instead of having a Quartz Job run every four hours to call one service, reconfigure the Quartz Job to run every hour and post messages to a queue. Once a message becomes available on the queue, other servers are on standby to read it and then refresh the given segment of ads. • Benefits of using RabbitMQ: – separate requests and actions – scalability – ease of increasing processing capabilities – ability to have apps coded in different languages communicate with one another – great for batch processing in an asynchronous manner Leveraging RabbitMQ to decouple a webapp Synchronous batch update process RabbitMQ solution
    16. 16. 16Pivotal Confidential–Internal Use Only Government of India: UIADI • One of the largest IT projects ever • Biggest online identity project in the world • Enabling social services and microfinance for 1.2 billion people • Very significant countrywide infra with many moving parts
    17. 17. 17Pivotal Confidential–Internal Use Only
    18. 18. 18Pivotal Confidential–Internal Use Only BBC Zeitgeist Zeitgeist is a prototype developed by BBC Research & Development to discover and track the most shared BBC webpages on Twitter.
    19. 19. 19Pivotal Confidential–Internal Use Only Number of connected devices is growing Source: McKinsey, May 2011
    20. 20. 20Pivotal Confidential–Internal Use Only 1 Sensor with MQTT client 2 Pivotal RabbitMQ 3 Spring AMQP Spring Hadoop & XD Pivotal tc Server 4 Pivotal HD Use Case: Big Data Applications How Pivotal components fit together
    21. 21. 21Pivotal Confidential–Internal Use Only • The rabbitmq-management plugin provides an HTTP-based API for management and monitoring the RabbitMQ broker • Two tools are provided that use this API: • A powerful browser-based UI • A powerful command line tool (rabbitmqadmin) • rabbitmqadmin can perform the same actions as the web-based UI, and is convenient for use when scripting • Or you can use the API to develop your own tools... RabbitMQ: management and monitoring
    22. 22. 22Pivotal Confidential–Internal Use Only RabbitMQ: management and monitoring
    23. 23. 23Pivotal Confidential–Internal Use Only RabbitMQ: management and monitoring
    24. 24. 24Pivotal Confidential–Internal Use Only