19

Boost Magento perfomance with Queues

Embed Size (px)

DESCRIPTION

Slides of my speech at Meet Magento Italy: http://it.meet-magento.com/speaker/manuele-menozzi/

Citation preview

Page 1: Boost Magento perfomance with Queues
Page 2: Boost Magento perfomance with Queues

WebgriffeTailored Digital Works

| webgriffe.com @webgriffe5+ Years of Experience with Magento5 Certified Developers (Zend & Magento)350+ Customers20+ Magento Extensions450+ Extensions Sold

Page 3: Boost Magento perfomance with Queues

Simple Scenario

Page 4: Boost Magento perfomance with Queues

Complex Scenario

Page 5: Boost Magento perfomance with Queues

Can we go over this limit?

Yes!Queueing several syncrounous tasks allows us to go further.

Page 6: Boost Magento perfomance with Queues

Separation of components withQueue Manager & Workers

Queue Manager: collects & assigns tasks to workersWorkers: execute tasks (with repeat-until logic)

Page 7: Boost Magento perfomance with Queues

Response time improvmentsSave 30% of the time by queuing index update on product save

Magento CE v. 1.8.1.0 with sample data. Index update on save enabled. Data collected with Xhprof profiler.

Page 8: Boost Magento perfomance with Queues

Online Hackathon Worldwide Experiencewww.mage-hackathon.de/passed/online-hackathon-worldwide-31st-jan-1st-feb.html

4 continents10+ countries100+ people

80+ open source Magento projectsgithub.com/magento-hackathon

Page 9: Boost Magento perfomance with Queues

Online Hackathon Worldwide ExperienceLilmuckers_Queue( )Beanstalk( )Your custom logic

github.com/lilmuckers/magento-lilmuckers_queue

kr.github.io/beanstalkd

Page 10: Boost Magento perfomance with Queues

Which queue manager to use?The ones we can easly integrate with Magento are:

Beanstalk ( )Amazon SQS ( )Gearman ( )

kr.github.io/beanstalkdaws.amazon.com/sqs

gearman.org

Page 11: Boost Magento perfomance with Queues

Lilmuckers_Queue ExtensionDefining a Queue Backend (for example Beanstalk)

<?xml version="1.0"?><!-- app/etc/local.xml --><config> <global> ... <queue> <backend>beanstalkd</backend> <beanstalkd> <servers> <server> <host>127.0.0.1</host> </server> </servers> </beanstalkd> </queue> ... </global></config>

Page 12: Boost Magento perfomance with Queues

Lilmuckers_Queue ExtensionDefining a Queue

<?xml version="1.0"?><!-- app/code/local/MyVendor/MyModule/etc/config.xml --><config>... <queues> <queueName> <label>The Queue Name</label> <class>module/queueHandler</class> <workers> <taskName> <class>module/worker</class> <method>methodName</method> </taskName> </workers> </queueName> </queues>...</config>

Page 13: Boost Magento perfomance with Queues

Lilmuckers_Queue ExtensionAdding tasks to Queue

$_queue = Mage::helper('lilqueue')->getQueue('queueName');$_task = Mage::helper('lilqueue')->createTask( 'taskName', array('data'=>'to provide', 'to'=>'the worker'), $storeToRunAs);

// Optionally$_task->setPriority(100) ->setDelay(60) ->setTtr(60);

$_queue->addTask($_task);

Page 14: Boost Magento perfomance with Queues

Lilmuckers_Queue ExtensionWorker

class My_Module_Model_Worker extends Lilmuckers_Queue_Model_Worker_Abstract{ public function methodName(Lilmuckers_Queue_Model_Queue_Task $task) { //get the store assigned with the task $store = $task->getStore(); //get the queue handler for this queue $queue = $task->getQueue(); //get the data assigned with the task $data = $task->getData(); //This task ended properly $task->success(); //this task needs to be repeated $task->retry(); //this task errored and we should drop it from the queue $task->hold(); //this worker is taking a long time, we should extend it $task->touch(); }}

$ php /path/to/magento/shell/queue.php --watch <queues>

Page 15: Boost Magento perfomance with Queues

Queueing Magento Index Update

Open source code on GitHub

buildbuild passingpassing

github.com/webgriffe/index-queue-extension

Page 16: Boost Magento perfomance with Queues

Webgriffe_IndexQueueExtension

Architecture

Page 17: Boost Magento perfomance with Queues

The same can be done withother components or tasks

Queues are for…Entity index updateCache cleaningStock updateRendering email templates…Any task which the user doesn't need to wait for

Page 18: Boost Magento perfomance with Queues

Any Question?

WebgriffeTailored Digital Works

| webgriffe.com @webgriffe5+ Years of Experience with Magento5 Certified Developers (Zend & Magento)350+ Customers20+ Magento Extensions450+ Extensions Sold

Page 19: Boost Magento perfomance with Queues

Thank you!