SlideShare a Scribd company logo
1 of 45
Download to read offline
PLEASE HOLD: YOUR
                     CALL IS IN A QUEUE
                     An introduction to queueing in Drupal
                               by Tom Phethean




Sunday, 3 March 13
QUEUING IN 30 MINUTES...

    •I     hate waiting in line...

    • Drupal         Queue API

    • Beyond         Core

    • Queue          jumpers and other gotchas

    • Questions



Sunday, 3 March 13
I HATE WAITING IN LINE...




Sunday, 3 March 13
Sunday, 3 March 13
Sunday, 3 March 13
Sunday, 3 March 13
Sunday, 3 March 13
QUEUES WILL FORM
    WHEN PROCESSES WITH VARIABILITY
      ARE LOADED TO HIGH LEVELS
             OF UTILISATION
       WITHOUT CONSTRAINT




Sunday, 3 March 13
SOMETHING WILL QUEUE
                SOMEWHERE



Sunday, 3 March 13
SOMETHING WILL QUEUE
                SOMEWHERE
                     Whether you like it or not




Sunday, 3 March 13
DO YOU WANT TO BE IN
                          CONTROL?



Sunday, 3 March 13
<silly_question>


                     DO YOU WANT TO BE IN
                          CONTROL?
                           </silly_question>




Sunday, 3 March 13
DRUPAL TO THE
              RESCUE!




Sunday, 3 March 13
CORE QUEUE API

    • Two            kinds of queue: reliable and non-reliable

    • Provides           interface to common queue functions

         • MemoryQueue            implements QueueInterface

         • SystemQueue           implements ReliableQueueInterface

    • In      Drupal 7 (and 8), Batch API extends SystemQueue


Sunday, 3 March 13
WHERE CAN I FIND QUEUE
                   API?

    • Drupal         7:

         • ./modules/system/system.queue.inc

    • Drupal         8:

         • ./core/lib/Drupal/Core/Queue




Sunday, 3 March 13
QUEUE API METHODS

    • createQueue()           • numberOfItems()

    • createItem()            • deleteItem()

    • claimItem()             • deleteQueue()

    • releaseItem()




Sunday, 3 March 13
Code time.



Sunday, 3 March 13
/**
                * Create a queue.
                */
              function queues_create_queue() {
                 $queue = DrupalQueue::get('my_queue');
                 $queue->createQueue();
              }




Sunday, 3 March 13
/**
               * Add an item to a queue.
               */
              function queues_create_queueitem() {
                $queue = DrupalQueue::get('my_queue');

                     $queue_data = array (
                        'stuff' => 'test',
                     );

                     return $queue->createItem($queue_data);
              }

              /**
               * Check number of items on a queue.
               */
              function queues_count_queueitems() {
                $queue = DrupalQueue::get('my_queue');

                     return $queue->numberOfItems();
              }

Sunday, 3 March 13
/**
               * Process a queue item
               */
              function queues_process_queueitem() {
                $queue = DrupalQueue::get('my_queue');

                     $item = $queue->claimItem(30);

                if ($item && $item->data['stuff'] == 'test') {
                  // Success - we don't need this item anymore.
                  $queue->deleteItem($item);
                }
                else {
                  // Something unexpected happened, we still need
              this item.
                  $queue->releaseItem($item);
                }
              }



Sunday, 3 March 13
/**
                * Implements hook_cron_queue_info().
                */
              function queues_cron_queue_info() {
                 $queues['my_queue'] = array(
                    'worker callback' => 'queues_process_queueitem',
                    'time' => 60,
                    // Time is NOT the lease item.
                    // Time is the amount of time cron will spend
              processing this queue.
                 );
                 return $queues;
              }




Sunday, 3 March 13
/**
                * Implements hook_queue_info() from queue_ui module.
                */
              function queues_queue_info() {
                 return array(
                    'my_queue' => array(
                       'title' => t('My test queue'),
                       'batch' => array(
                          'operations' =>
              array(array('queues_batch_process', array())),
                          'finished' => 'queues_batch_finished',
                          'title' => t('Processing my test queue'),
                       ),
                       'cron' => array(
                          'callback' =>'queues_process_queueitem',
                       ),
                    ),
                 );
              }


Sunday, 3 March 13
That’s it!



Sunday, 3 March 13
BEYOND CORE
    •   Drupal Queue (backport to D6) - http://drupal.org/project/drupal_queue

    •   Queue UI - http://drupal.org/project/queue_ui

    •   Examples - http://drupal.org/project/examples

    •   Queue backends:

         •   Beanstalkd - http://drupal.org/project/beanstalkd

         •   STOMP - http://drupal.org/project/stomp

         •   Redis - http://drupal.org/project/redis_queue

Sunday, 3 March 13
CUSTOM BACKENDS

    • Default        queue class:

         • $conf['queue_default_class']   = 'SystemQueue';

         • $conf[‘queue_default_reliable_class’]   = ‘SystemQueue’;

    • Override        queue classes:

         • $conf['queue_class_{queue   name}'] = 'StompQueue';


Sunday, 3 March 13
CUSTOM BACKENDS

    • Default        queue class:

         • $conf['queue_default_class']   = 'SystemQueue';

         • $conf[‘queue_default_reliable_class’]   = ‘SystemQueue’;

    • Override        queue classes:

         • $conf['queue_class_{queue   name}'] = 'RedisQueue';


Sunday, 3 March 13
QUEUES AND DRUSH


    • drush          queue-list

    • drush          queue-run [queue name]

    • ...use         with caution: queue-run will always delete your queue
        item



Sunday, 3 March 13
WHEN TO QUEUE


    • Remote           service call triggered by user interface

    • Complex           business rules around data processing

    • Need           guaranteed success




Sunday, 3 March 13
SOME EXAMPLES


    • Publishing         user information to a remote CRM

    • Backend          order fulfilment

    • Email          sending (see notifications module)




Sunday, 3 March 13
GOTCHAS




Sunday, 3 March 13
MULTIPLE CONSUMERS
Sunday, 3 March 13
MULTIPLE CONSUMERS

    • Identify          what it is you’re processing

    • Use            Lock API to secure a lock on it:

         • lock_acquire(‘my_id’)

         • lock_release(‘my_id’)

    • Check            the “thing” is in a state you expect it to be

    • Release           or Delete from queue as appropriate

Sunday, 3 March 13
DEBUGGING YOUR QUEUE
Sunday, 3 March 13
DEBUGGING YOUR QUEUE

    • watchdog()          is your friend

    • Log            EVERYTHING

    • Abstract          it so you can toggle verbose logging

    • Use    Graylog, LogStash etc to save your database from death
        by logs


Sunday, 3 March 13
THINGS CAN GO WRONG...
Sunday, 3 March 13
THINGS CAN GO WRONG...


    • Monitor          your queue depths with Munin or Nagios

    • Alert          if they get too deep

    • Know           what the alert means (and listen to it)!




Sunday, 3 March 13
THINGS BREAK.
                      BUT WHEN THEY DO, KNOW THAT
                     EVERY ITEM IN YOUR QUEUE
                       IS A REQUEST WHICH WOULD
                        OTHERWISE HAVE BEEN LOST.




Sunday, 3 March 13
IMPLEMENTING QUEUEING IN YOUR APPLICATION
               SMOOTHS THE PEAKS,




Sunday, 3 March 13
IMPLEMENTING QUEUEING IN YOUR APPLICATION
                SMOOTHS THE PEAKS,
           MAKE THROUGHPUT PREDICTABLE,




Sunday, 3 March 13
IMPLEMENTING QUEUEING IN YOUR APPLICATION
                SMOOTHS THE PEAKS,
           MAKE THROUGHPUT PREDICTABLE,
            REMOVES PROCESSING TIME FROM
               THE USER EXPERIENCE




Sunday, 3 March 13
IMPLEMENTING QUEUEING IN YOUR APPLICATION
                SMOOTHS THE PEAKS,
           MAKE THROUGHPUT PREDICTABLE,
            REMOVES PROCESSING TIME FROM
               THE USER EXPERIENCE
            AND ENSURES THAT PROBLEMS ARE
               HANDLED GRACEFULLY




Sunday, 3 March 13
IN OTHER WORDS...




Sunday, 3 March 13
Sunday, 3 March 13
QUESTIONS?




   Tweet: @tsphethean
  Drupal.org: tsphethean
     IRC: tsphethean
Sunday, 3 March 13
IMAGE ATTRIBUTIONS
    •   Image of supermarket queue - http://petoneponderings.blogspot.co.uk/2012_12_01_archive.html

    •   Post Office queue - http://www.flickr.com/photos/welshkaren/5367517662/

    •   Apple Store queueing http://www.telegraph.co.uk/technology/apple/7854982/Apple-iPhone-4-more-
        than-a-quarter-of-users-think-video-calling-is-a-gimmick.html

    •   Supermarket crush - http://www.dailymail.co.uk/news/article-2078597/Boxing-Day-sales-Record-
        numbers-shops-open-80-push-grab-shoppers.html

    •   Drupal Superhero - http://www.origineight.net/blog-post/web-sites-you-manage

    •   Lots of Shoppers - http://www.dailymail.co.uk/news/article-2253523/United-Nations-Bargain-Hunters-
        Britons-the-queue-China-Middle-East-lead-rush-designer-brands.html

    •   Confused baby - http://thementalpausechronicles.blogspot.co.uk/2008/08/head-scratching.html

    •   Mark Sonnabaum - http://www.whatwouldmarksonnabaumdo.com


Sunday, 3 March 13

More Related Content

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
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...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Featured

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Please hold: your call is in a queue. An introduction to queuing in Drupal.

  • 1. PLEASE HOLD: YOUR CALL IS IN A QUEUE An introduction to queueing in Drupal by Tom Phethean Sunday, 3 March 13
  • 2. QUEUING IN 30 MINUTES... •I hate waiting in line... • Drupal Queue API • Beyond Core • Queue jumpers and other gotchas • Questions Sunday, 3 March 13
  • 3. I HATE WAITING IN LINE... Sunday, 3 March 13
  • 8. QUEUES WILL FORM WHEN PROCESSES WITH VARIABILITY ARE LOADED TO HIGH LEVELS OF UTILISATION WITHOUT CONSTRAINT Sunday, 3 March 13
  • 9. SOMETHING WILL QUEUE SOMEWHERE Sunday, 3 March 13
  • 10. SOMETHING WILL QUEUE SOMEWHERE Whether you like it or not Sunday, 3 March 13
  • 11. DO YOU WANT TO BE IN CONTROL? Sunday, 3 March 13
  • 12. <silly_question> DO YOU WANT TO BE IN CONTROL? </silly_question> Sunday, 3 March 13
  • 13. DRUPAL TO THE RESCUE! Sunday, 3 March 13
  • 14. CORE QUEUE API • Two kinds of queue: reliable and non-reliable • Provides interface to common queue functions • MemoryQueue implements QueueInterface • SystemQueue implements ReliableQueueInterface • In Drupal 7 (and 8), Batch API extends SystemQueue Sunday, 3 March 13
  • 15. WHERE CAN I FIND QUEUE API? • Drupal 7: • ./modules/system/system.queue.inc • Drupal 8: • ./core/lib/Drupal/Core/Queue Sunday, 3 March 13
  • 16. QUEUE API METHODS • createQueue() • numberOfItems() • createItem() • deleteItem() • claimItem() • deleteQueue() • releaseItem() Sunday, 3 March 13
  • 18. /** * Create a queue. */ function queues_create_queue() { $queue = DrupalQueue::get('my_queue'); $queue->createQueue(); } Sunday, 3 March 13
  • 19. /** * Add an item to a queue. */ function queues_create_queueitem() { $queue = DrupalQueue::get('my_queue'); $queue_data = array ( 'stuff' => 'test', ); return $queue->createItem($queue_data); } /** * Check number of items on a queue. */ function queues_count_queueitems() { $queue = DrupalQueue::get('my_queue'); return $queue->numberOfItems(); } Sunday, 3 March 13
  • 20. /** * Process a queue item */ function queues_process_queueitem() { $queue = DrupalQueue::get('my_queue'); $item = $queue->claimItem(30); if ($item && $item->data['stuff'] == 'test') { // Success - we don't need this item anymore. $queue->deleteItem($item); } else { // Something unexpected happened, we still need this item. $queue->releaseItem($item); } } Sunday, 3 March 13
  • 21. /** * Implements hook_cron_queue_info(). */ function queues_cron_queue_info() { $queues['my_queue'] = array( 'worker callback' => 'queues_process_queueitem', 'time' => 60, // Time is NOT the lease item. // Time is the amount of time cron will spend processing this queue. ); return $queues; } Sunday, 3 March 13
  • 22. /** * Implements hook_queue_info() from queue_ui module. */ function queues_queue_info() { return array( 'my_queue' => array( 'title' => t('My test queue'), 'batch' => array( 'operations' => array(array('queues_batch_process', array())), 'finished' => 'queues_batch_finished', 'title' => t('Processing my test queue'), ), 'cron' => array( 'callback' =>'queues_process_queueitem', ), ), ); } Sunday, 3 March 13
  • 24. BEYOND CORE • Drupal Queue (backport to D6) - http://drupal.org/project/drupal_queue • Queue UI - http://drupal.org/project/queue_ui • Examples - http://drupal.org/project/examples • Queue backends: • Beanstalkd - http://drupal.org/project/beanstalkd • STOMP - http://drupal.org/project/stomp • Redis - http://drupal.org/project/redis_queue Sunday, 3 March 13
  • 25. CUSTOM BACKENDS • Default queue class: • $conf['queue_default_class'] = 'SystemQueue'; • $conf[‘queue_default_reliable_class’] = ‘SystemQueue’; • Override queue classes: • $conf['queue_class_{queue name}'] = 'StompQueue'; Sunday, 3 March 13
  • 26. CUSTOM BACKENDS • Default queue class: • $conf['queue_default_class'] = 'SystemQueue'; • $conf[‘queue_default_reliable_class’] = ‘SystemQueue’; • Override queue classes: • $conf['queue_class_{queue name}'] = 'RedisQueue'; Sunday, 3 March 13
  • 27. QUEUES AND DRUSH • drush queue-list • drush queue-run [queue name] • ...use with caution: queue-run will always delete your queue item Sunday, 3 March 13
  • 28. WHEN TO QUEUE • Remote service call triggered by user interface • Complex business rules around data processing • Need guaranteed success Sunday, 3 March 13
  • 29. SOME EXAMPLES • Publishing user information to a remote CRM • Backend order fulfilment • Email sending (see notifications module) Sunday, 3 March 13
  • 32. MULTIPLE CONSUMERS • Identify what it is you’re processing • Use Lock API to secure a lock on it: • lock_acquire(‘my_id’) • lock_release(‘my_id’) • Check the “thing” is in a state you expect it to be • Release or Delete from queue as appropriate Sunday, 3 March 13
  • 34. DEBUGGING YOUR QUEUE • watchdog() is your friend • Log EVERYTHING • Abstract it so you can toggle verbose logging • Use Graylog, LogStash etc to save your database from death by logs Sunday, 3 March 13
  • 35. THINGS CAN GO WRONG... Sunday, 3 March 13
  • 36. THINGS CAN GO WRONG... • Monitor your queue depths with Munin or Nagios • Alert if they get too deep • Know what the alert means (and listen to it)! Sunday, 3 March 13
  • 37. THINGS BREAK. BUT WHEN THEY DO, KNOW THAT EVERY ITEM IN YOUR QUEUE IS A REQUEST WHICH WOULD OTHERWISE HAVE BEEN LOST. Sunday, 3 March 13
  • 38. IMPLEMENTING QUEUEING IN YOUR APPLICATION SMOOTHS THE PEAKS, Sunday, 3 March 13
  • 39. IMPLEMENTING QUEUEING IN YOUR APPLICATION SMOOTHS THE PEAKS, MAKE THROUGHPUT PREDICTABLE, Sunday, 3 March 13
  • 40. IMPLEMENTING QUEUEING IN YOUR APPLICATION SMOOTHS THE PEAKS, MAKE THROUGHPUT PREDICTABLE, REMOVES PROCESSING TIME FROM THE USER EXPERIENCE Sunday, 3 March 13
  • 41. IMPLEMENTING QUEUEING IN YOUR APPLICATION SMOOTHS THE PEAKS, MAKE THROUGHPUT PREDICTABLE, REMOVES PROCESSING TIME FROM THE USER EXPERIENCE AND ENSURES THAT PROBLEMS ARE HANDLED GRACEFULLY Sunday, 3 March 13
  • 44. QUESTIONS? Tweet: @tsphethean Drupal.org: tsphethean IRC: tsphethean Sunday, 3 March 13
  • 45. IMAGE ATTRIBUTIONS • Image of supermarket queue - http://petoneponderings.blogspot.co.uk/2012_12_01_archive.html • Post Office queue - http://www.flickr.com/photos/welshkaren/5367517662/ • Apple Store queueing http://www.telegraph.co.uk/technology/apple/7854982/Apple-iPhone-4-more- than-a-quarter-of-users-think-video-calling-is-a-gimmick.html • Supermarket crush - http://www.dailymail.co.uk/news/article-2078597/Boxing-Day-sales-Record- numbers-shops-open-80-push-grab-shoppers.html • Drupal Superhero - http://www.origineight.net/blog-post/web-sites-you-manage • Lots of Shoppers - http://www.dailymail.co.uk/news/article-2253523/United-Nations-Bargain-Hunters- Britons-the-queue-China-Middle-East-lead-rush-designer-brands.html • Confused baby - http://thementalpausechronicles.blogspot.co.uk/2008/08/head-scratching.html • Mark Sonnabaum - http://www.whatwouldmarksonnabaumdo.com Sunday, 3 March 13