Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Queue Everything and Please Everyone

Queue Everything and Please Everyone

The intent of this talk is to introduce the concepts of queueing in web development, tools at one’s disposal, some common patterns and how it all can be used to reduce time to generate user feedback.

Vaidik Kapoor

September 15, 2012
Tweet

More Decks by Vaidik Kapoor

Other Decks in Programming

Transcript

  1. Who am I? ➔ Undergraduate student. ➔ Involved with: ✔

    Mozilla as a Contributor and Rep ✔ Drupal as a Contributor ➔ Twitter: @vaidikkapoor ➔ Github: vaidikkp ➔ Web: vaidikkapoor.info
  2. Why do everything at once? Task 1 Task 2 Task

    3 Task N Client Request Response
  3. What can Queues help with? ➔ Background Processing ✔ Data

    Processing ✔ Media Processing ✔ Updating Caches ➔ Anything that you want to offload off your server. ➔ Improve the overall User Experience
  4. Redis + HotQueue PRODUCER: from hotqueue import HotQueue queue =

    HotQueue("myqueue", host="localhost", port=6379, db=0) queue.put(message) CONSUMER / WORKER: from hotqueue import HotQueue queue = HotQueue("myqueue", host="localhost", port=6379, db=0) while True: message = queue.get() # do something awesome
  5. Redis + PyRes ➔ Python clone of Github's Resque ➔

    Offers a lot more features than HotQueue ✔ Job failure handling ✔ Queue status information ➔ Comes with Monitoring System written in Ruby
  6. Redis + PyRes PRODUCER: from pyres import ResQ r =

    Resq() class WebPage: queue = “screenies” @staticmethod def perform(urll): # save the screenshot r.enqueue(WebPage, 'http://python.org') CONSUMER: ./pyres_worker screenies
  7. What can MQs help with? ➔ Everything that generic Queues

    can help with. ➔ Increase Reliability ➔ Cron Jobs (Celery)
  8. Available MQ Solutions ➔ RabbitMQ ➔ Amazon Simple Queue ➔

    Apache MQ ➔ Gearman ➔ Starling ➔ OpenAMQ ➔ Sun Java Message Queue System
  9. Message Queue Protocols ➔ AMQP: Advanced Message Queue Protocol ➔

    JMS: Java Messaging Service ➔ STOMP: Streaming Text Oriented Messaging Protocol
  10. Criteria for Broker Selection ➔ Difficulty in Recovery ➔ Relatively

    low level of required maintenance ➔ Ease of Deployment ➔ Durability ➔ Persistence ➔ Community Support ➔ Cluster Support ➔ What language is it written in?
  11. Celery ➔ An amazing Task Manager ➔ Batteries Included ➔

    Uses RabbitMQ as broker (or almost anything) ➔ Libraries for most of the common web frameworks like Django, Flask, Pyramid ➔ Supports multiprocessing. ➔ Distribute tasks easily. ➔ Makes life easy
  12. Review ➔ Choose a system according to needs ➔ Build

    a robust system ➔ Integrate seamlessly with your UI ➔ Isolate & Recycle: make it a habit ➔ Improve the overall UX! ➔ Please everyone, even yourself!
  13. References ➔ PyRes - http://pyres.readthedocs.org/ ➔ RabbitMQ - http://www.rabbitmq.com/ ➔

    Celery - http://celeryproject.org/ ➔ Amazing Article - http://wiki.secondlife.com/wiki/Message_Queue_Evaluation_Notes