SlideShare une entreprise Scribd logo
1  sur  36
High scale flavor
(recipes for message
      queueing)

             Tomas (t0m) Doran
                London Perl
              Workshop 2010
What is message
       queueing.
• In it’s simplest form, it’s just a list.
• 1 (or more) ‘producers’ (writers)
• 1 (or more) ‘consumers’ (readers)
• Queue if rate of production > rate of
  consumption
Why do I want it?
• Decouples producers and consumers
  (probably across the network).
• Lets you manage load, and spikes in load
  (only n consumers).
• In a web environment - lets you serve
  more pages, quicker.
What is the problem
  with web apps?
• App servers take a lot of RAM
• Context switching expensive
• A lot of apps think like a CGI.
• Making the user wait IS HORRIBLE.
• Anything but very fast pages is fail.
One page request per CPU core
   Even if extra context switching has zero overhead
    you serve people sooner if you queue requests.

       A     B       A   B     A     B       A   B

                 A                       B

  A finishes significantly before B in the lower diagram
            B finishes at the same time in both
N.B. This explicitly assumes you never wait on external IO
                       (e.g. a database)
What are the solutions
• Use a PAL (Page Assembly Layer) - e.g.
  Varnish
• Defer doing work inside the web request
  to a queue
• AJAX (heavy javascript) apps making many
  requests make this even more important.
• If your requests are all small and fast then
  you can win by doing multiple small
  requests rather than one expensive one
Message queueing

• Many many flavors.
 • Going to cover options available right
     now in perl
• First, a little theory
Messaging Topologies
• I.e. how producers and consumers interact
  together through the message broker
• 3 common patterns - considerably more
  complex applications possible.
• Even within these there is additional
  complexity to consider, e.g. message
  durability.
1: Publish-Subscribe
• ‘Topic’ in ActiveMQ
• Anonymous queues in AMQP
• One (or more) publishers
• Zero (or more) consumers
• Every consumer gets every message
• Messages discarded if no consumers
• E.g. log message listener(s)
2: Queue(s)
• One or more producers
• One or more consumers
• Each message delivered to exactly one
  consumer
• Messages ‘queued’ (possibly to disk)
• E.g. Job queue with worker pool allowing
  you to work efficiently through high load
  spikes
3: Request / Response

• Create anonymous queue for replies
• Publish to well known queue(s), include
  return address
• Wait for reply.
• Arrange for messages to be discarded if
  you stop listening for the reply.
STOMP
• Streamed Text Oriented Messageing
  Protocol
• Simple. Interoperable.
• You probably want to use ActiveMQ
• Net::STOMP
• Simple semantics: Queues and Topics
• You can build the 3 simple patterns from
  these
ActiveMQ - Topics
• Publish / subscribe semantics.
• Message goes to all the subscribers
• Zero or more subscribers
• Messages thrown away if no subscribers
• Safe (cannot fill up server with undelivered
  messages)
ActiveMQ - Queues
• Load balancer semantics.
• Each message - 1 consumer.
• Messages queued.
• Multiple consumers
• Ack required (auto-ack possible)
• Danger will robinson!
AMQP
• More complex than STOMP
• Wiring of message routing is part of the
  protocol.
• All your clients know (at least half) of the
  wiring.
• Different topologies depending on routing
  configuration.
• Nice when your server dies - no ‘current
  config’
AMQP Concepts
              RabbitMQ


                vhost



  Publisher   Exchange




               Queue
  Consumer
Concepts - Exchanges

• Named
• Messages are published (sent) to one
  exchange
• Can be durable (forces all queues attached
  to be durable)
Queues
• Queues can be named.
• Queues are bound to one (or more)
  exchanges.
• Queues can have 0 or more clients
• Queues may persist or be deleted when
  they have no clients
• FIFO (if you have 1 consumer)
• Message never delivered to > 1 client
Bindings
• Binding is what joins a queue and an
  exchange.
• There can be more than one binding for
  each queue, allowing a single consumer to
  listen to multiple message sources
• You can bind to topic exchanges selectively
  via the message ‘routing key’
Job queue
• Named exchange
• Bound to 1 named and persistent queue
• 0 or more listeners get round-robin
  messages
• Messages queue when nobody listens / if
  consumers are slow
Publish/Subscribe
• Named exchange
• Each client creates an anonymous
  ephemeral queue
• Client binds the queue to that exchange
• All clients get all messages
• Messages go to /dev/null if no clients
AMQP can be complex
• Different exchange types - direct, topic,
  fanout (and custom exchange types
  possible)
• Messages have a routing key allowing
  selective binding.
• You can do a lot using these and a mix of
  named and anonymous queues
• Much more complex topologies possible
Implementations:

• So - I want a queue
• What do I use?
 • Naive approaches
 • Job queue only approaches
 • More sophisticated/custom approaches
(Shared) database table
• Have a ‘jobs’ table, with some data, and a
  ‘status’ column.
• Waiting => Running => Done
• Job workers poll the table and change
  statuses.
• NO NO NO NO NO NO NO NO
• No, really, mst will come and break your
  legs if you do this (after he stops laughing)
(Shared) database table
• Have a ‘jobs’ table, with some data, and a
  ‘status’ column.
• Waiting => Running => Done
• Job workers poll the table and change
  statuses.
• NO NO NO NO NO NO NO NO
• No, really, mst will come and break your
  legs if you do this.
(Shared) database table
• Have a ‘jobs’ table, with some data, and a
  ‘status’ column.
• Waiting => Running => Done
• MySQL will get the query plan wrong if
  you try joining this table (hint: the
  cardinality on your status column is 3).
• You will lose super-hard. HAND.
(Queue) database table

• Have separate queued / running / done tables
• Less bad for performance - at least the ‘find
  something to do’ query is very cheap.
• Still pretty terrible.
• You still re-invented a big old wheel here,
  probably badly.
Gearman
• Around since 2006. Multi platform.
• Not really a message queue - designed as a
  job queuing system
• Client, Job Server, Worker
• Failover (multiple job servers)
• NOT persistent
• Simple, works well (if that’s all you need)
TheSchwartz
• Is Persistent
• From the same place as Gearman
• Not as well adopted
• Relies on a MySQL database - SPOF
• Still simple - maybe the easiest way to get
  started (if you need reliable)?
Client libs: Net::Stomp
• Apache ActiveMQ.
• Dead simple producers and consumers.
• Just a client - you need to manage / run
  your own jobs.
• Blocking.
• Works perfectly well for sending messages
  from a web app.
Client libs:
      Net::RabbitFoot
• AMQP / RabbitMQ
• AnyEvent based - non blocking.
• Documentation pretty poor (sorry).
• Works well if you have an async app.
• Can be used inside a web app for simple
  sending.
Catalyst::Engine::Stomp
•   By chrisa @ Venda & yours truly; now
    maintained by Paul Moony.
•   Simple framework for writing jobs / managing
    workers.
•   Allows you to fire and forget, or fire and wait
    for termination (and pass a message back)
•   Achieves many of the same things a Gearman
•   Used in anger by several companies.
         (http://miltonkeynes.pm.org/talks/2010/06/paul_mooney_stomp_moosex_workers.pdf)
Net::ActiveMQ

• Builds on Catalyst::Engine::STOMP
• Chisel talked about this at YAPC::EU (Friday
  PM ‘Going Postal’)
• NetAPorter people - poke him to release it
  (or at least put it on github)!
Web::Hippie
• Persistent (potentially bidirectional) web
  pipe to applications.
• Cheap connection, no polling needed (on
  reasonably modern browsers). Great as the
  listener part for ‘replies’
• Downsides - needs to be async - no DBI
  (kinda)!
• Plays very nicely with RabbitMQ (hint
  MooseX::Storage & Joose.Storage <3)
CatalystX::JobServer
• My current baby.
• Uses AMQP.
• Provides Web::Hippie pipes for jobs - shiny
  shiny ajax updates.
• Barely production ready (but useable).
• I’m talking about it later...
Conclusions
• Use JSON for your message payloads.
• You probably want to use Gearman if you
  can get away with it.
• STOMP works well and is simple, tried and
  tested jobs solution.
• AMQP is nicer and more flexible, but there
  are less proven solutions (in perl).

Contenu connexe

Tendances

Windows Azure Service Bus
Windows Azure Service BusWindows Azure Service Bus
Windows Azure Service Bus
Pavel Revenkov
 
Zarafa SummerCamp 2012 - Exchange Web Services on Zarafa
Zarafa SummerCamp 2012 - Exchange Web Services on ZarafaZarafa SummerCamp 2012 - Exchange Web Services on Zarafa
Zarafa SummerCamp 2012 - Exchange Web Services on Zarafa
Zarafa
 
ActiveMQ In Action - ApacheCon 2011
ActiveMQ In Action - ApacheCon 2011ActiveMQ In Action - ApacheCon 2011
ActiveMQ In Action - ApacheCon 2011
Bruce Snyder
 
Apache ActiveMQ - Enterprise messaging in action
Apache ActiveMQ - Enterprise messaging in actionApache ActiveMQ - Enterprise messaging in action
Apache ActiveMQ - Enterprise messaging in action
dejanb
 
Messaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new framework
Tomas Doran
 

Tendances (20)

Message queue architecture
Message queue architectureMessage queue architecture
Message queue architecture
 
3 years with Clojure
3 years with Clojure3 years with Clojure
3 years with Clojure
 
Windows Azure Service Bus
Windows Azure Service BusWindows Azure Service Bus
Windows Azure Service Bus
 
Ups and downs of enterprise Java app in a research setting
Ups and downs of enterprise Java app in a research settingUps and downs of enterprise Java app in a research setting
Ups and downs of enterprise Java app in a research setting
 
Zarafa SummerCamp 2012 - Exchange Web Services on Zarafa
Zarafa SummerCamp 2012 - Exchange Web Services on ZarafaZarafa SummerCamp 2012 - Exchange Web Services on Zarafa
Zarafa SummerCamp 2012 - Exchange Web Services on Zarafa
 
Parallel and Asynchronous Programming - ITProDevConnections 2012 (English)
Parallel and Asynchronous Programming -  ITProDevConnections 2012 (English)Parallel and Asynchronous Programming -  ITProDevConnections 2012 (English)
Parallel and Asynchronous Programming - ITProDevConnections 2012 (English)
 
ActiveMQ In Action - ApacheCon 2011
ActiveMQ In Action - ApacheCon 2011ActiveMQ In Action - ApacheCon 2011
ActiveMQ In Action - ApacheCon 2011
 
Flink Forward SF 2017: Tzu-Li (Gordon) Tai - Joining the Scurry of Squirrels...
Flink Forward SF 2017: Tzu-Li (Gordon) Tai -  Joining the Scurry of Squirrels...Flink Forward SF 2017: Tzu-Li (Gordon) Tai -  Joining the Scurry of Squirrels...
Flink Forward SF 2017: Tzu-Li (Gordon) Tai - Joining the Scurry of Squirrels...
 
Discover the Capabilities of Windows Azure Service Bus to Power Agile Busines...
Discover the Capabilities of Windows Azure Service Bus to Power Agile Busines...Discover the Capabilities of Windows Azure Service Bus to Power Agile Busines...
Discover the Capabilities of Windows Azure Service Bus to Power Agile Busines...
 
10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL
 
Apache ActiveMQ - Enterprise messaging in action
Apache ActiveMQ - Enterprise messaging in actionApache ActiveMQ - Enterprise messaging in action
Apache ActiveMQ - Enterprise messaging in action
 
Archipel Introduction - ejabberd SF Meetup
Archipel Introduction - ejabberd SF MeetupArchipel Introduction - ejabberd SF Meetup
Archipel Introduction - ejabberd SF Meetup
 
Serve like a boss (part one)
Serve like a boss (part one)Serve like a boss (part one)
Serve like a boss (part one)
 
Transactional Streaming: If you can compute it, you can probably stream it.
Transactional Streaming: If you can compute it, you can probably stream it.Transactional Streaming: If you can compute it, you can probably stream it.
Transactional Streaming: If you can compute it, you can probably stream it.
 
Messaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new framework
 
Cloud Messaging Service: Technical Overview
Cloud Messaging Service: Technical OverviewCloud Messaging Service: Technical Overview
Cloud Messaging Service: Technical Overview
 
Where do I put this data? #lessql
Where do I put this data? #lessqlWhere do I put this data? #lessql
Where do I put this data? #lessql
 
Apache con2016final
Apache con2016final Apache con2016final
Apache con2016final
 
Multiply like rabbits with rabbit mq
Multiply like rabbits with rabbit mqMultiply like rabbits with rabbit mq
Multiply like rabbits with rabbit mq
 
Mini-Training: Message Brokers
Mini-Training: Message BrokersMini-Training: Message Brokers
Mini-Training: Message Brokers
 

Similaire à High scale flavour

Real time system_performance_mon
Real time system_performance_monReal time system_performance_mon
Real time system_performance_mon
Tomas Doran
 
Enterprise Messaging with RabbitMQ.pdf
Enterprise Messaging with RabbitMQ.pdfEnterprise Messaging with RabbitMQ.pdf
Enterprise Messaging with RabbitMQ.pdf
Ortus Solutions, Corp
 
Message:Passing - lpw 2012
Message:Passing - lpw 2012Message:Passing - lpw 2012
Message:Passing - lpw 2012
Tomas Doran
 
Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pie
Tomas Doran
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
Newlink
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
Newlink
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
LLC NewLink
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
Newlink
 

Similaire à High scale flavour (20)

Real time system_performance_mon
Real time system_performance_monReal time system_performance_mon
Real time system_performance_mon
 
Building an Event Bus at Scale
Building an Event Bus at ScaleBuilding an Event Bus at Scale
Building an Event Bus at Scale
 
Eventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and Hadoop
Eventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and HadoopEventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and Hadoop
Eventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and Hadoop
 
Building Big Data Streaming Architectures
Building Big Data Streaming ArchitecturesBuilding Big Data Streaming Architectures
Building Big Data Streaming Architectures
 
Putting Kafka Into Overdrive
Putting Kafka Into OverdrivePutting Kafka Into Overdrive
Putting Kafka Into Overdrive
 
Enterprise Messaging with RabbitMQ.pdf
Enterprise Messaging with RabbitMQ.pdfEnterprise Messaging with RabbitMQ.pdf
Enterprise Messaging with RabbitMQ.pdf
 
Modern Distributed Messaging and RPC
Modern Distributed Messaging and RPCModern Distributed Messaging and RPC
Modern Distributed Messaging and RPC
 
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
 
Multi-platform Enterprise Messaging with RabbitMQ
Multi-platform Enterprise Messaging with RabbitMQMulti-platform Enterprise Messaging with RabbitMQ
Multi-platform Enterprise Messaging with RabbitMQ
 
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedInJay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
 
Message:Passing - lpw 2012
Message:Passing - lpw 2012Message:Passing - lpw 2012
Message:Passing - lpw 2012
 
Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pie
 
Kafka at scale facebook israel
Kafka at scale   facebook israelKafka at scale   facebook israel
Kafka at scale facebook israel
 
Voldemort Nosql
Voldemort NosqlVoldemort Nosql
Voldemort Nosql
 
Kafka tutorial
Kafka tutorialKafka tutorial
Kafka tutorial
 
Multiply like rabbits with rabbit mq
Multiply like rabbits with rabbit mqMultiply like rabbits with rabbit mq
Multiply like rabbits with rabbit mq
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 

Plus de Tomas Doran

Test driven infrastructure development (2 - puppetconf 2013 edition)
Test driven infrastructure development (2 - puppetconf 2013 edition)Test driven infrastructure development (2 - puppetconf 2013 edition)
Test driven infrastructure development (2 - puppetconf 2013 edition)
Tomas Doran
 
London devops logging
London devops loggingLondon devops logging
London devops logging
Tomas Doran
 
Webapp security testing
Webapp security testingWebapp security testing
Webapp security testing
Tomas Doran
 
Webapp security testing
Webapp security testingWebapp security testing
Webapp security testing
Tomas Doran
 
Large platform architecture in (mostly) perl - an illustrated tour
Large platform architecture in (mostly) perl - an illustrated tourLarge platform architecture in (mostly) perl - an illustrated tour
Large platform architecture in (mostly) perl - an illustrated tour
Tomas Doran
 

Plus de Tomas Doran (20)

Empowering developers to deploy their own data stores
Empowering developers to deploy their own data storesEmpowering developers to deploy their own data stores
Empowering developers to deploy their own data stores
 
Dockersh and a brief intro to the docker internals
Dockersh and a brief intro to the docker internalsDockersh and a brief intro to the docker internals
Dockersh and a brief intro to the docker internals
 
Sensu and Sensibility - Puppetconf 2014
Sensu and Sensibility - Puppetconf 2014Sensu and Sensibility - Puppetconf 2014
Sensu and Sensibility - Puppetconf 2014
 
Steamlining your puppet development workflow
Steamlining your puppet development workflowSteamlining your puppet development workflow
Steamlining your puppet development workflow
 
Building a smarter application stack - service discovery and wiring for Docker
Building a smarter application stack - service discovery and wiring for DockerBuilding a smarter application stack - service discovery and wiring for Docker
Building a smarter application stack - service discovery and wiring for Docker
 
Chasing AMI - Building Amazon machine images with Puppet, Packer and Jenkins
Chasing AMI - Building Amazon machine images with Puppet, Packer and JenkinsChasing AMI - Building Amazon machine images with Puppet, Packer and Jenkins
Chasing AMI - Building Amazon machine images with Puppet, Packer and Jenkins
 
Deploying puppet code at light speed
Deploying puppet code at light speedDeploying puppet code at light speed
Deploying puppet code at light speed
 
Thinking through puppet code layout
Thinking through puppet code layoutThinking through puppet code layout
Thinking through puppet code layout
 
Docker puppetcamp london 2013
Docker puppetcamp london 2013Docker puppetcamp london 2013
Docker puppetcamp london 2013
 
"The worst code I ever wrote"
"The worst code I ever wrote""The worst code I ever wrote"
"The worst code I ever wrote"
 
Test driven infrastructure development (2 - puppetconf 2013 edition)
Test driven infrastructure development (2 - puppetconf 2013 edition)Test driven infrastructure development (2 - puppetconf 2013 edition)
Test driven infrastructure development (2 - puppetconf 2013 edition)
 
Test driven infrastructure development
Test driven infrastructure developmentTest driven infrastructure development
Test driven infrastructure development
 
London devops - orc
London devops - orcLondon devops - orc
London devops - orc
 
London devops logging
London devops loggingLondon devops logging
London devops logging
 
Webapp security testing
Webapp security testingWebapp security testing
Webapp security testing
 
Webapp security testing
Webapp security testingWebapp security testing
Webapp security testing
 
Dates aghhhh!!?!?!?!
Dates aghhhh!!?!?!?!Dates aghhhh!!?!?!?!
Dates aghhhh!!?!?!?!
 
Zero mq logs
Zero mq logsZero mq logs
Zero mq logs
 
Large platform architecture in (mostly) perl - an illustrated tour
Large platform architecture in (mostly) perl - an illustrated tourLarge platform architecture in (mostly) perl - an illustrated tour
Large platform architecture in (mostly) perl - an illustrated tour
 
Large platform architecture in (mostly) perl
Large platform architecture in (mostly) perlLarge platform architecture in (mostly) perl
Large platform architecture in (mostly) perl
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

High scale flavour

  • 1. High scale flavor (recipes for message queueing) Tomas (t0m) Doran London Perl Workshop 2010
  • 2. What is message queueing. • In it’s simplest form, it’s just a list. • 1 (or more) ‘producers’ (writers) • 1 (or more) ‘consumers’ (readers) • Queue if rate of production > rate of consumption
  • 3. Why do I want it? • Decouples producers and consumers (probably across the network). • Lets you manage load, and spikes in load (only n consumers). • In a web environment - lets you serve more pages, quicker.
  • 4. What is the problem with web apps? • App servers take a lot of RAM • Context switching expensive • A lot of apps think like a CGI. • Making the user wait IS HORRIBLE. • Anything but very fast pages is fail.
  • 5. One page request per CPU core Even if extra context switching has zero overhead you serve people sooner if you queue requests. A B A B A B A B A B A finishes significantly before B in the lower diagram B finishes at the same time in both N.B. This explicitly assumes you never wait on external IO (e.g. a database)
  • 6. What are the solutions • Use a PAL (Page Assembly Layer) - e.g. Varnish • Defer doing work inside the web request to a queue • AJAX (heavy javascript) apps making many requests make this even more important. • If your requests are all small and fast then you can win by doing multiple small requests rather than one expensive one
  • 7. Message queueing • Many many flavors. • Going to cover options available right now in perl • First, a little theory
  • 8. Messaging Topologies • I.e. how producers and consumers interact together through the message broker • 3 common patterns - considerably more complex applications possible. • Even within these there is additional complexity to consider, e.g. message durability.
  • 9. 1: Publish-Subscribe • ‘Topic’ in ActiveMQ • Anonymous queues in AMQP • One (or more) publishers • Zero (or more) consumers • Every consumer gets every message • Messages discarded if no consumers • E.g. log message listener(s)
  • 10. 2: Queue(s) • One or more producers • One or more consumers • Each message delivered to exactly one consumer • Messages ‘queued’ (possibly to disk) • E.g. Job queue with worker pool allowing you to work efficiently through high load spikes
  • 11. 3: Request / Response • Create anonymous queue for replies • Publish to well known queue(s), include return address • Wait for reply. • Arrange for messages to be discarded if you stop listening for the reply.
  • 12. STOMP • Streamed Text Oriented Messageing Protocol • Simple. Interoperable. • You probably want to use ActiveMQ • Net::STOMP • Simple semantics: Queues and Topics • You can build the 3 simple patterns from these
  • 13. ActiveMQ - Topics • Publish / subscribe semantics. • Message goes to all the subscribers • Zero or more subscribers • Messages thrown away if no subscribers • Safe (cannot fill up server with undelivered messages)
  • 14. ActiveMQ - Queues • Load balancer semantics. • Each message - 1 consumer. • Messages queued. • Multiple consumers • Ack required (auto-ack possible) • Danger will robinson!
  • 15. AMQP • More complex than STOMP • Wiring of message routing is part of the protocol. • All your clients know (at least half) of the wiring. • Different topologies depending on routing configuration. • Nice when your server dies - no ‘current config’
  • 16. AMQP Concepts RabbitMQ vhost Publisher Exchange Queue Consumer
  • 17. Concepts - Exchanges • Named • Messages are published (sent) to one exchange • Can be durable (forces all queues attached to be durable)
  • 18. Queues • Queues can be named. • Queues are bound to one (or more) exchanges. • Queues can have 0 or more clients • Queues may persist or be deleted when they have no clients • FIFO (if you have 1 consumer) • Message never delivered to > 1 client
  • 19. Bindings • Binding is what joins a queue and an exchange. • There can be more than one binding for each queue, allowing a single consumer to listen to multiple message sources • You can bind to topic exchanges selectively via the message ‘routing key’
  • 20. Job queue • Named exchange • Bound to 1 named and persistent queue • 0 or more listeners get round-robin messages • Messages queue when nobody listens / if consumers are slow
  • 21. Publish/Subscribe • Named exchange • Each client creates an anonymous ephemeral queue • Client binds the queue to that exchange • All clients get all messages • Messages go to /dev/null if no clients
  • 22. AMQP can be complex • Different exchange types - direct, topic, fanout (and custom exchange types possible) • Messages have a routing key allowing selective binding. • You can do a lot using these and a mix of named and anonymous queues • Much more complex topologies possible
  • 23. Implementations: • So - I want a queue • What do I use? • Naive approaches • Job queue only approaches • More sophisticated/custom approaches
  • 24. (Shared) database table • Have a ‘jobs’ table, with some data, and a ‘status’ column. • Waiting => Running => Done • Job workers poll the table and change statuses. • NO NO NO NO NO NO NO NO • No, really, mst will come and break your legs if you do this (after he stops laughing)
  • 25. (Shared) database table • Have a ‘jobs’ table, with some data, and a ‘status’ column. • Waiting => Running => Done • Job workers poll the table and change statuses. • NO NO NO NO NO NO NO NO • No, really, mst will come and break your legs if you do this.
  • 26. (Shared) database table • Have a ‘jobs’ table, with some data, and a ‘status’ column. • Waiting => Running => Done • MySQL will get the query plan wrong if you try joining this table (hint: the cardinality on your status column is 3). • You will lose super-hard. HAND.
  • 27. (Queue) database table • Have separate queued / running / done tables • Less bad for performance - at least the ‘find something to do’ query is very cheap. • Still pretty terrible. • You still re-invented a big old wheel here, probably badly.
  • 28. Gearman • Around since 2006. Multi platform. • Not really a message queue - designed as a job queuing system • Client, Job Server, Worker • Failover (multiple job servers) • NOT persistent • Simple, works well (if that’s all you need)
  • 29. TheSchwartz • Is Persistent • From the same place as Gearman • Not as well adopted • Relies on a MySQL database - SPOF • Still simple - maybe the easiest way to get started (if you need reliable)?
  • 30. Client libs: Net::Stomp • Apache ActiveMQ. • Dead simple producers and consumers. • Just a client - you need to manage / run your own jobs. • Blocking. • Works perfectly well for sending messages from a web app.
  • 31. Client libs: Net::RabbitFoot • AMQP / RabbitMQ • AnyEvent based - non blocking. • Documentation pretty poor (sorry). • Works well if you have an async app. • Can be used inside a web app for simple sending.
  • 32. Catalyst::Engine::Stomp • By chrisa @ Venda & yours truly; now maintained by Paul Moony. • Simple framework for writing jobs / managing workers. • Allows you to fire and forget, or fire and wait for termination (and pass a message back) • Achieves many of the same things a Gearman • Used in anger by several companies. (http://miltonkeynes.pm.org/talks/2010/06/paul_mooney_stomp_moosex_workers.pdf)
  • 33. Net::ActiveMQ • Builds on Catalyst::Engine::STOMP • Chisel talked about this at YAPC::EU (Friday PM ‘Going Postal’) • NetAPorter people - poke him to release it (or at least put it on github)!
  • 34. Web::Hippie • Persistent (potentially bidirectional) web pipe to applications. • Cheap connection, no polling needed (on reasonably modern browsers). Great as the listener part for ‘replies’ • Downsides - needs to be async - no DBI (kinda)! • Plays very nicely with RabbitMQ (hint MooseX::Storage & Joose.Storage <3)
  • 35. CatalystX::JobServer • My current baby. • Uses AMQP. • Provides Web::Hippie pipes for jobs - shiny shiny ajax updates. • Barely production ready (but useable). • I’m talking about it later...
  • 36. Conclusions • Use JSON for your message payloads. • You probably want to use Gearman if you can get away with it. • STOMP works well and is simple, tried and tested jobs solution. • AMQP is nicer and more flexible, but there are less proven solutions (in perl).

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n