SlideShare a Scribd company logo
Delayed operations with queues for website performance
Delayed operations
with queues
Yuriy Gerasimov
Frédéric G. Marand
Session track: PHP
Who are we?
Yuriy Gerasimov
● FFW
● Drupal architect & developer
● Contrib 7 modules: services, draggableviews
● Founder at Backtrac.io
ygerasimov
Frédéric G. Marand
● OSInet: performance/architecture consulting
for internal teams at larger accounts
● Core contributor 4.7 to 8.0.x, MongoDB + XMLRPC
maintainer + others
● Already 4 D8 customer projects before 8.0.0
● Customer D8 in production since 07/2015
● Frequently adds queueing to larger Drupal projects
fgm
Why use queues ?
To have websites which are :
● Faster for visitors
● Snappier for editors
● More scaleable
To process time-consuming jobs :
● Video encoding
● High-resolution gallery uploads and processing
Concrete use cases
● Prepare content for non-Drupal front-ends
● Anticipate content generation
● Deferred submits, e.g. comments handling
● Slow operations: node saves, previews, image processing
● External data sources: pull, push
● Multi-step operations: batch
Cooking for front-ends
Front
end
Anticipated content generation
Blocks
Ctools content types
Controllers
etc.
Contrib :
http://github.com/FGM/lazy
Content created Served from cache
Fresh Stale Expiredt0
t1
t2
Served from cache Regenerate cache
time
Usual Drupal
Content created Served from cache
Fresh Stale Fresht0
t1
t2
Served from cache
+ request update Store
Served from cache
time
Anticipated content generation
Comment handling
“Pull” data sources (aggregator)
“Push” data sources
Image processing
Job servers
● How to get results
● Rerun failed jobs
● Separate queue for failed jobs
● Monitoring queues, workers
● Supervisor
Some implementations
Queue D6 D7 D8
Memory core core
Database OK core core
AdvancedQueue OK Not yet
Amazon SQS (aws_sqs) OK Not yet
Beanstalkd OK 8.1/8.2
evQueue Started
Queue D6 D7 D8
IronMQ (iron.io) OK Not yet
Gearman OK OK Not yet
MongoDB OK Started
PHPResque
RabbitMQ OK Not yet
Redis (redis_queue) OK OK Not yet
Queues API: concepts
Queue: a minimally-featured FIFO
Worker: the code actually doing the work
Item: a piece of workload submitted to the queue
Runner: the process triggering/monitoring workers
Batch subsystem: a high-level API on top of Queue API
D8: Manager, Plugins
D6/D7 Queue API
D7: core
D6: drupal_queue module
Declaring queues:
hook_cron_queue_info[_alter]()
● “Skip on cron”: enable decoupling from cron runs
● Time: max lifetime allocated to process items
during a cron run, useless with skip on cron =
TRUE
● Worker callback: an implementation of
callback_queue_worker (mixed
queue_item): void
API useable without cron
Default Runner:
● In the cron subsystem
● Pokemon exception handling
D8 Queue API
API useable without cron Declaring queue workers:
Service: plugin.manager.queue_worker
Instantiates QueueWorker plugins
Definition:
● Cron, not enabled by default
○ Time: max lifetime allocated to
process items during a cron run
● Core examples : AggregatorRefresh,
LocaleTranslation
● hook_queue_info_alter()
Default Runner:
In the cron subsystem:
DrupalCoreCron::processQueues()
SuspendQueueException: $q-
>releaseItem()
Queue API methods: Queue
QueueInterface
● Q::createItem(mixed $data: void
● Q::claimItem($lease_time = 3600: mixed $item
○ FALSE | stdClass + [item_id => int, data => mixed, created => timestamp]
○ $lease_time → Assumptions for runner, currently not used
● Q::deleteItem($item): void -> work done
● Q::releaseItem($item): bool
● Q::numberOfItems(): int → best guess, unreliable
● Q::createQueue() / Q::deleteQueue()
ReliableQueueInterface: ordering, single execution
Queue API methods: others
Queue service → QueueFactory::get($name, $reliable)
QueueManager: a vanilla plugin manager
● In charge of hook_queue_info_alter()
● createInstance($plugin_id, $configuration)
QueueWorkerInterface:
● processItem (mixed data) : void @throws SuspendQueueException
Queue Runners
Core / Contrib
● Core Cron / Elysia Cron / Queue_Runner
● Drush: queue-list / queue-run
● Similar limitations:
○ Default on in D6 / D7, default off in D8
○ Limited timeout support: non preemptive
○ Single threaded, single process across queues
Custom runners
● Provided by queue modules or per-project one-offs
● Preemption, parallel execution...
Queue API limitations
Limited FIFO paradigm
● D8: non-Reliable
QueueInterface: datagram
No monitoring
No queue disciplines
● Priority management
● Tagging
● Delay, burying ...
Implementations may provide more
● Item structure is free-form: add
richer interfaces
No Peek(), no LIFO,
no deduplication: hacks
Performance edge
Runners:
● Avoid active polling à la core DB
● Use a blocking layer + select()
● Parallel handling of multiple queues → multiple runners, scheduling
Workers: read after write
● Write in the queue → cache invalidated
● Read again→ cache primed
Sprint: Friday
https://www.flickr.
com/photos/amazeelabs/9965814443/in/fav
es-38914559@N03/
Sprint with the Community on Friday.
We have tasks for every skillset.
Mentors are available for new contributors.
An optional Friday morning workshop for first-
time sprinters will help you get set up.
Follow @drupalmentoring.
Delayed operations with queues for website performance
Delayed operations with queues for website performance

More Related Content

PDF
Faster Drupal sites using Queue API
PPTX
Deep dive - Concourse CI/CD and Pipelines
PPTX
Autolab Workshop
PDF
Introduction to rails
PDF
Zenly - Reverse geocoding
PDF
Integrating Node.js with PHP
PPTX
PDF
OpenCms Days 2014 - Updating to OpenCms 9.5
Faster Drupal sites using Queue API
Deep dive - Concourse CI/CD and Pipelines
Autolab Workshop
Introduction to rails
Zenly - Reverse geocoding
Integrating Node.js with PHP
OpenCms Days 2014 - Updating to OpenCms 9.5

What's hot (20)

PDF
Beyond Puppet
PDF
Asynchronous job queues with python-rq
PDF
OpenCms Days 2014 Keynote - Step up to OpenCms 9.5
ODP
Migrations
PDF
Create ReactJS Component & publish as npm package
ODP
Javascript robotics
PDF
How to-node-core
PDF
Nuxeo World Session: Building Packages for the Nuxeo Marketplace
PDF
React starter-kitでとっとと始めるisomorphic開発
PDF
«Управление логикой переходов между экранами приложения с помощью координатор...
KEY
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
PDF
OpenCms Days 2015 How do you develop for OpenCms?
ODP
Monitoring your VM's at Scale
PDF
OSDC 2014: Christian Patsch - System Orchestration with Capistrano and Puppet
PDF
Is the order code deploy?
PDF
[HKOSCON][20200613][ Ansible: From VM to Kubernetes]
PDF
OpenCms Days 2013 - Start rolling with OpenCms 9
PPTX
PHP and node.js Together
PDF
Docker Up and Running Introduction
PDF
Xlab #2: wzorce projektowe
Beyond Puppet
Asynchronous job queues with python-rq
OpenCms Days 2014 Keynote - Step up to OpenCms 9.5
Migrations
Create ReactJS Component & publish as npm package
Javascript robotics
How to-node-core
Nuxeo World Session: Building Packages for the Nuxeo Marketplace
React starter-kitでとっとと始めるisomorphic開発
«Управление логикой переходов между экранами приложения с помощью координатор...
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
OpenCms Days 2015 How do you develop for OpenCms?
Monitoring your VM's at Scale
OSDC 2014: Christian Patsch - System Orchestration with Capistrano and Puppet
Is the order code deploy?
[HKOSCON][20200613][ Ansible: From VM to Kubernetes]
OpenCms Days 2013 - Start rolling with OpenCms 9
PHP and node.js Together
Docker Up and Running Introduction
Xlab #2: wzorce projektowe
Ad

Similar to Delayed operations with queues for website performance (20)

PDF
Delayed operations with Queues
PDF
Юрій Герасимов — Delayed operations with queues
ODP
Drupal 7 Queues
PDF
Faster PHP apps using Queues and Workers
ODP
Introduction to Python Celery
PDF
Queue your work
PPTX
Message Queues & Offline Processing with PHP
PPTX
Job Queues Overview
PPTX
Do you queue (updated)
PDF
Lazy evaluation drupal camp moscow 2014
ODP
Drupal course - batch API
PPTX
Slideshare - Magento Imagine - Do You Queue
PDF
Distributed Queue System using Gearman
PDF
Work Queue Systems
PPTX
Do you queue
PPT
Gearman and asynchronous processing in PHP applications
PPT
Gearman and asynchronous processing in PHP applications
KEY
Work Queues
KEY
Cooking a rabbit pie
KEY
Real time system_performance_mon
Delayed operations with Queues
Юрій Герасимов — Delayed operations with queues
Drupal 7 Queues
Faster PHP apps using Queues and Workers
Introduction to Python Celery
Queue your work
Message Queues & Offline Processing with PHP
Job Queues Overview
Do you queue (updated)
Lazy evaluation drupal camp moscow 2014
Drupal course - batch API
Slideshare - Magento Imagine - Do You Queue
Distributed Queue System using Gearman
Work Queue Systems
Do you queue
Gearman and asynchronous processing in PHP applications
Gearman and asynchronous processing in PHP applications
Work Queues
Cooking a rabbit pie
Real time system_performance_mon
Ad

More from OSInet (14)

PPTX
Interface texte plein écran en Go avec TView
PDF
Scaling up and accelerating Drupal 8 with NoSQL
PDF
Mon site web est hacké ! Que faire ?
PDF
Life after the hack
PDF
Drupal 8 : regards croisés
PDF
Cache speedup with Heisencache for Drupal 7 and Drupal 8
PDF
Recueil des mauvaises pratiques constatées lors de l'audit de sites Drupal 7
PDF
Le groupe PHP-FIG et les standards PSR
PDF
Les blocs Drupal de drop.org à Drupal 8
ODP
Utiliser drupal
ODP
Equipe drupal
ODP
Pourquoi choisir un CMS Open Source ?
PDF
Drupal et le NoSQL - drupagora 2011
ODP
Drupal Views development
Interface texte plein écran en Go avec TView
Scaling up and accelerating Drupal 8 with NoSQL
Mon site web est hacké ! Que faire ?
Life after the hack
Drupal 8 : regards croisés
Cache speedup with Heisencache for Drupal 7 and Drupal 8
Recueil des mauvaises pratiques constatées lors de l'audit de sites Drupal 7
Le groupe PHP-FIG et les standards PSR
Les blocs Drupal de drop.org à Drupal 8
Utiliser drupal
Equipe drupal
Pourquoi choisir un CMS Open Source ?
Drupal et le NoSQL - drupagora 2011
Drupal Views development

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Approach and Philosophy of On baking technology
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Electronic commerce courselecture one. Pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
KodekX | Application Modernization Development
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
A Presentation on Artificial Intelligence
cuic standard and advanced reporting.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Approach and Philosophy of On baking technology
Understanding_Digital_Forensics_Presentation.pptx
Empathic Computing: Creating Shared Understanding
Advanced methodologies resolving dimensionality complications for autism neur...
“AI and Expert System Decision Support & Business Intelligence Systems”
The Rise and Fall of 3GPP – Time for a Sabbatical?
Electronic commerce courselecture one. Pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
20250228 LYD VKU AI Blended-Learning.pptx
KodekX | Application Modernization Development
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Reach Out and Touch Someone: Haptics and Empathic Computing
A Presentation on Artificial Intelligence

Delayed operations with queues for website performance

  • 2. Delayed operations with queues Yuriy Gerasimov Frédéric G. Marand Session track: PHP
  • 4. Yuriy Gerasimov ● FFW ● Drupal architect & developer ● Contrib 7 modules: services, draggableviews ● Founder at Backtrac.io ygerasimov
  • 5. Frédéric G. Marand ● OSInet: performance/architecture consulting for internal teams at larger accounts ● Core contributor 4.7 to 8.0.x, MongoDB + XMLRPC maintainer + others ● Already 4 D8 customer projects before 8.0.0 ● Customer D8 in production since 07/2015 ● Frequently adds queueing to larger Drupal projects fgm
  • 6. Why use queues ? To have websites which are : ● Faster for visitors ● Snappier for editors ● More scaleable To process time-consuming jobs : ● Video encoding ● High-resolution gallery uploads and processing
  • 7. Concrete use cases ● Prepare content for non-Drupal front-ends ● Anticipate content generation ● Deferred submits, e.g. comments handling ● Slow operations: node saves, previews, image processing ● External data sources: pull, push ● Multi-step operations: batch
  • 9. Anticipated content generation Blocks Ctools content types Controllers etc. Contrib : http://github.com/FGM/lazy Content created Served from cache Fresh Stale Expiredt0 t1 t2 Served from cache Regenerate cache time Usual Drupal Content created Served from cache Fresh Stale Fresht0 t1 t2 Served from cache + request update Store Served from cache time Anticipated content generation
  • 11. “Pull” data sources (aggregator)
  • 14. Job servers ● How to get results ● Rerun failed jobs ● Separate queue for failed jobs ● Monitoring queues, workers ● Supervisor
  • 15. Some implementations Queue D6 D7 D8 Memory core core Database OK core core AdvancedQueue OK Not yet Amazon SQS (aws_sqs) OK Not yet Beanstalkd OK 8.1/8.2 evQueue Started Queue D6 D7 D8 IronMQ (iron.io) OK Not yet Gearman OK OK Not yet MongoDB OK Started PHPResque RabbitMQ OK Not yet Redis (redis_queue) OK OK Not yet
  • 16. Queues API: concepts Queue: a minimally-featured FIFO Worker: the code actually doing the work Item: a piece of workload submitted to the queue Runner: the process triggering/monitoring workers Batch subsystem: a high-level API on top of Queue API D8: Manager, Plugins
  • 17. D6/D7 Queue API D7: core D6: drupal_queue module Declaring queues: hook_cron_queue_info[_alter]() ● “Skip on cron”: enable decoupling from cron runs ● Time: max lifetime allocated to process items during a cron run, useless with skip on cron = TRUE ● Worker callback: an implementation of callback_queue_worker (mixed queue_item): void API useable without cron Default Runner: ● In the cron subsystem ● Pokemon exception handling
  • 18. D8 Queue API API useable without cron Declaring queue workers: Service: plugin.manager.queue_worker Instantiates QueueWorker plugins Definition: ● Cron, not enabled by default ○ Time: max lifetime allocated to process items during a cron run ● Core examples : AggregatorRefresh, LocaleTranslation ● hook_queue_info_alter() Default Runner: In the cron subsystem: DrupalCoreCron::processQueues() SuspendQueueException: $q- >releaseItem()
  • 19. Queue API methods: Queue QueueInterface ● Q::createItem(mixed $data: void ● Q::claimItem($lease_time = 3600: mixed $item ○ FALSE | stdClass + [item_id => int, data => mixed, created => timestamp] ○ $lease_time → Assumptions for runner, currently not used ● Q::deleteItem($item): void -> work done ● Q::releaseItem($item): bool ● Q::numberOfItems(): int → best guess, unreliable ● Q::createQueue() / Q::deleteQueue() ReliableQueueInterface: ordering, single execution
  • 20. Queue API methods: others Queue service → QueueFactory::get($name, $reliable) QueueManager: a vanilla plugin manager ● In charge of hook_queue_info_alter() ● createInstance($plugin_id, $configuration) QueueWorkerInterface: ● processItem (mixed data) : void @throws SuspendQueueException
  • 21. Queue Runners Core / Contrib ● Core Cron / Elysia Cron / Queue_Runner ● Drush: queue-list / queue-run ● Similar limitations: ○ Default on in D6 / D7, default off in D8 ○ Limited timeout support: non preemptive ○ Single threaded, single process across queues Custom runners ● Provided by queue modules or per-project one-offs ● Preemption, parallel execution...
  • 22. Queue API limitations Limited FIFO paradigm ● D8: non-Reliable QueueInterface: datagram No monitoring No queue disciplines ● Priority management ● Tagging ● Delay, burying ... Implementations may provide more ● Item structure is free-form: add richer interfaces No Peek(), no LIFO, no deduplication: hacks
  • 23. Performance edge Runners: ● Avoid active polling à la core DB ● Use a blocking layer + select() ● Parallel handling of multiple queues → multiple runners, scheduling Workers: read after write ● Write in the queue → cache invalidated ● Read again→ cache primed
  • 24. Sprint: Friday https://www.flickr. com/photos/amazeelabs/9965814443/in/fav es-38914559@N03/ Sprint with the Community on Friday. We have tasks for every skillset. Mentors are available for new contributors. An optional Friday morning workshop for first- time sprinters will help you get set up. Follow @drupalmentoring.