pycon india 2012: celery talk

21
Celery for background task processing and deferred execution Piyush Kumar & Konark Modi

Upload: piyush-kumar

Post on 13-May-2015

3.324 views

Category:

Technology


2 download

DESCRIPTION

Celery for background task processing and deferred execution

TRANSCRIPT

Page 1: PyCon India 2012: Celery Talk

Celery for background task processing and deferred executionPiyush Kumar & Konark Modi

Page 2: PyCon India 2012: Celery Talk

Show of Hands : How many of us• Have used or know about celery / djcelery .• Have worked with queues .

Page 3: PyCon India 2012: Celery Talk

Setup details :System config. we'd be using:

Centos 6.2 : Hosted on Virtual boxPython version : Python 2.6.6MySQLDjango-1.4

Packages installed :1. Virutal env : pip install virtualenv2. RabbitMQ 3. Celery : pip install -U celery4. Django-Celery : pip install django-celery5. MySQLdb module for python : easy_install MySQL , yum

install mysql-devel python-devel6. pytz : pip install pytz

Page 4: PyCon India 2012: Celery Talk

Tutorial sections: • Understanding the basics – Level 0• Getting started with celery – Level 1• Next Steps with Celery – Level 2• Recap of what we’ve discussed till now• Q & A

Page 5: PyCon India 2012: Celery Talk

Understanding the basics – Level 0• Need of job queues• What is celery ?• Understanding AMQP (Advanced Message Queueing

Protocol )• Choosing a broker : Why RabbitMQ ?• Moving to console : Understanding RabbitMQ better.

Page 6: PyCon India 2012: Celery Talk

Getting started with Celery – Level 1• Celery architecture• Setting up celery : Installation of all the components• Hands-On : A simple application• How are we using Celery• Integrating Celery with a Web-Framework : Django using

djcelery• Django-celery architecture• Hands-On : Web application using celery

Page 7: PyCon India 2012: Celery Talk

Next steps with Celery – Level 2• Adding multiple worker• Retrying tasks• Routing to multiple queues• Monitoring• Security

Page 8: PyCon India 2012: Celery Talk

Lets get started now ☺Understanding the basics – Level 0

Page 9: PyCon India 2012: Celery Talk

Need of Job Queues:• For executing tasks asynchronusly.• Distributed tasks.• Scheduling.• Retries.• Handling errors.• Dynamic work load.• Enhancing user experience.• Some of the use cases include:

• Clickstream ( No. of hotels being watched, likes etc.)• Generate graphs based on a large data set for display on a site’s home page / Dashboard

every 15 minute• Admin applications like

• Thumbnails generation • Re-generate static CSS files by examining when certain items in the admin have been modified

• Connecting to third-party APIs• Mass e-mailers

Page 10: PyCon India 2012: Celery Talk

What is Celery ?• Asynschronus task queue/job queue.• Uses distributed message passing.• Supports both real-time processing + schedule jobs.• Tasks can be run concurrently on a single or more worker

servers taking advantage of multiprocessing.

Page 11: PyCon India 2012: Celery Talk

AMQP (Advanced Message Queueing Protocol )• Open standard application layer protocol for message-

oriented middleware• Features of AMQP

• Message orientation,• Queuing,• Routing (including point-to-point and publish-and-subscribe),• Reliability • Security• Interoperable: AMQP mandates the behaviour of the messaging

provider and client to the extent that implementations from different vendors are truly interoperable, in the same way as SMTP, HTTP, FTP, etc. have created interoperable systems.

Page 12: PyCon India 2012: Celery Talk

Choosing a broker : Why RabbitMQ ?

Page 13: PyCon India 2012: Celery Talk

Moving to console : Understanding RabbitMQ better

Page 14: PyCon India 2012: Celery Talk

Getting started with celery – Level 1

Page 15: PyCon India 2012: Celery Talk

Installing Celery :• RabbitMQ (http://www.rabbitmq.com/download.html )• pip install -U celery

Page 16: PyCon India 2012: Celery Talk

A simple application• Create tasks.py• Run celeryd and understand its various options• Configure the result backend• Fetch the result• Call the task using file, python interpreter

• Delay()• Apply_async() : Expiration, countdown

• Periodic tasks

Page 17: PyCon India 2012: Celery Talk

Our use cases:• Poll approx 300+ DB queries every 15 minutes.• Custom metric collection• Inventory management system :

• Asynchronus web-interface• Periodic tasks

Page 18: PyCon India 2012: Celery Talk

Integrating celery with a web-framework : Django with djcelery• Installation• Understanding the DB schema djcelery uses to store

tasks/result sets• Writing a simple web-app

Page 19: PyCon India 2012: Celery Talk

Next steps• Adding multiple workers• Retrying tasks• Monitoring various components of celery:

• Exploring various components of our celery setup.• Setting up celery-cam Monitoring RabbitMQ

• Running celeryd as a daemon in production• Security :

• Signals , Tracking of tasks as they transition through different states, and inspecting return values.

• Message signing.

Page 20: PyCon India 2012: Celery Talk

Recap of what we’ve discussed till now

Page 21: PyCon India 2012: Celery Talk

Thanks : Q & A