SlideShare a Scribd company logo
1 of 103
Intro to Celery
or
Everything you are now able to do, but
you did not know about
Approximate time: 55mins
Rafael Roman Otero
Detour—message queue
A queue of messages (really!)
Q
Invariant?
Detour—message queue
A queue of messages (really!)
Q
Invariant?
timestamp( peek(Q) ) is oldest in Q
Detour—message queue
A queue of messages (really!)
Q
Invariant?
timestamp( peek(Q) ) is oldest in Q
Applications
Buffered Communications
Detour—message queue
A queue of messages (really!)
Q
Invariant?
timestamp( peek(Q) ) is oldest in Q
Applications
Buffered Communications
Example
A human example of buffered and unbuffered communications ?
Detour—message queue
A queue of messages (really!)
Q
Invariant?
timestamp( peek(Q) ) is oldest in Q
Applications?
Communicatoins
Example
A human example of buffered and unbuffered communications ?
Is there any benefit of
buffered over unbuffered
communication?
Detour—message queue
A queue of messages (really!)
Q
Invariant?
timestamp( peek(Q) ) is oldest in Q
Applications?
Anything that requires a buffer that keeps arrival order
(e.g., communications)
Communications
A human example of buffered and unbuffered communications ?
Is there any benefit of
buffered over unbuffered
communication?
Talking and listening does not have to take
place at the same time.
Detour—message queue
Messages queues are used as infrastructure for inter-process
communication (IPC)
process
process
process
NODE a
NODE b
Detour—message queue
Messages queues are used as infrastructure for inter-process
communication (IPC)
process
process
process
NODE a
NODE b
Detour—message queue
Messages queues are used as infrastructure for inter-process
communication (IPC)
process
process
process
NODE a
NODE b
Too abstract
Detour—message queue
Messages queues are used as infrastructure for inter-process
communication (IPC)
process
process
process
NODE a
NODE b
Detour—message queue
Messages queues are used as infrastructure for inter-process
communication (IPC)
process
process
process
NODE a
NODE b
Too abstract
Detour—IPC with message queues
Intermediary
a
send receive
b c
Process
b
Process
c
Process
a
Detour—IPC with message queues
Intermediary
a
send receive
b c
Process
b
Process
c
Process
a
Communicating processes
Detour—IPC with message queues
Intermediary
a
send receive
b c
Process
b
Process
c
Process
a
Communicating processes
Can be many things
Detour—IPC with message queues
OS
a
send receive
b
Process
a
Process
b
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
Process
c
OS
send receive
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
c
NODE a NODE b
Detour—IPC with message queues
Layer-2 communication in Linux:
• sendto ( mac address, msg, … )
• recvfrom ( mac address, msg, … )
OS
a
send receive
b
Process
a
Process
b
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
Process
c
OS
send receive
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
c
NODE a NODE b
Detour—IPC with message queues
Layer-2 communication in Linux:
• sendto ( mac address, msg, … )
• recvfrom ( mac address, msg, … )
OS
a
send receive
b
Process
a
Process
b
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
Process
c
OS
send receive
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
c
NODE a NODE b
Detour—IPC with message queues
Layer-2 communication in Linux:
• sendto ( mac address, msg, … )
• recvfrom ( mac address, msg, … )
OS
a
send receive
b
Process
a
Process
b
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
Process
c
OS
send receive
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
c
NODE a NODE b
Detour—IPC with message queues
Layer-2 communication in Linux:
• sendto ( mac address, msg, … )
• recvfrom ( mac address, msg, … )
OS
a
send receive
b
Process
a
Process
b
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
Process
c
OS
send receive
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
c
NODE a NODE b
Synchronous IO
What does that mean?
Detour—IPC with message queues
OS
send receive
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
OS
send receive
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
Function
a
Class
b
send receive
Language
a b
Module
c
send receive
Language
c
NODE a NODE b
Detour—IPC with message queues
processprocess
OS
send receive
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
OS
send receive
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
Function
a
Class
b
send receive
Language
a b
Module
c
send receive
Language
c
NODE a NODE b
Detour—IPC with message queues
NODE a NODE b
OS
send receive
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
OS
send receive
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
Same
language
Same
language
Function
a
Class
b
send receive
Language
a b
Module
c
send receive
Language
c
Detour—IPC with message queues
NODE a NODE b
OS
send receive
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
OS
send receive
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
Same
language
Same
language
Function
a
Class
b
send receive
Lang + lib
a b
Module
c
send receive
Lang + lib
c
Detour—IPC with message queues
OS
send receive
Java process(es) Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
OS
send receive
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
NODE a NODE b
Java process
Same
language
Same
language
Function
a
Class
b
send receive
Java + Akka
a b
Module
c
send receive
Java + Akka
c
Detour—IPC with message queues
public static class Actor extends UntypedActor {
public void onReceive( Object message ) {
if ( message.equals( "I'm looking for Joanna" ) )
getSender().tell( "She's taken", getSelf() );
}
}
OS
send receive
Java process(es) Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
OS
send receive
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
Java process
send receive
Java + Akka
a b
send receive
Java + Akka
c
NODE a NODE b
So verbose
Detour—IPC with message queues
No example…
NODE a NODE b
OS
send receive
Java process(es) Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
OS
send receive
Physical Layer
MAC Layer
Transport Layer
Network Layer
App Layer
Java process
send receive
Erlang
a b
send receive
Erlang
c
Detour—IPC with message queues
NODE a NODE b
OSsend receive OS send receive
send receive
Language
Message broker
send receive
Language
send receive
Message Broker
a b
send receive
Message Broker
c
Message broker
Function
a
Class
b
Module
c
Detour—IPC with message queues
NODE a NODE b
OSsend receive OS send receive
send receive
Language
Message broker
send receive
Language
send receive
Message Broker
a b
send receive
Message Broker
c
Message broker
Function
a
Class
b
Module
c
Handle:
Queuing
Routing
Reliability
etc
Detour—IPC with message queues
NODE a NODE b
OSsend receive OS send receive
send receive
Language
Message broker
send receive
Language
send receive
Message Broker
a b
send receive
Message Broker
c
Message broker
Function
a
Class
b
Module
c
Protocols:
AMQP
MQTT
Detour—IPC with message queues
NODE a NODE b
OSsend receive OS send receive
send receive
Language
Message broker
send receive
Language
send receive
Message Broker
a b
send receive
Message Broker
c
Message broker
Function
a
Class
b
Module
c
Protocols:
AMQP
MQTT
• Advance Message
Queueing protocol
• App-layer protocol
Detour—IPC with message queues
NODE a NODE b
OSsend receive OS send receive
send receive
Language
Message broker
send receive
Language
send receive
Message Broker
a b
send receive
Message Broker
c
Message broker
Function
a
Class
b
Module
c
Protocols:
AMQP
MQTT
• Advance Message
Queueing protocol
• App-layer protocol
• Publish and subscribe
What is P and S ?
Detour—IPC with message queues
NODE a NODE b
OSsend receive OS send receive
send receive
Language
Message broker
send receive
Language
send receive
Message Broker
a b
send receive
Message Broker
c
Message broker
Function
a
Class
b
Module
c
Steve Vinoski. 2006. Advanced Message Queuing Protocol.
IEEE Internet Computing 10, 6 (November 2006), 87-89.
Protocols:
AMQP
MQTT
• Advance Message
Queueing protocol
• App-layer protocol
• Publish and subscribe
Detour—IPC with message queues
NODE a NODE b
OSsend receive OS send receive
send receive
Erlang
RabbitMQ
send receive
Erlang
send receive
RabbitMQ
a b
send receive
RabbitMQ
c
Message broker
amqp amqp
Detour—IPC with message queues
NODE a NODE b
OSsend receive OS send receive
send receive
Erlang
RabbitMQ
send receive
Erlang
send receive
RabbitMQ
a b
send receive
RabbitMQ
c
Message broker
amqp amqp
script
script
Python Java
class
class
Detour—IPC with message queues
NODE a NODE b
OSsend receive OS send receive
send receive
Erlang
RabbitMQ
send receive
Erlang
send receive
RabbitMQ
a b
send receive
RabbitMQ
c
Message broker
amqp amqp
script
script
Python Java
class
class
channel = connection.channel()
channel.queue_declare( queue=‘my queue‘ )
channel.basic_publish ( routing_key=‘my queue',
body=‘I’m looking for Joanna‘ … )
Detour—IPC with message queues
NODE a NODE b
OSsend receive OS send receive
send receive
Erlang
RabbitMQ
send receive
Erlang
send receive
RabbitMQ
a b
send receive
RabbitMQ
c
Message broker
amqp amqp
script
script
Python Java
class
class
channel = connection.channel()
channel.queue_declare( queue=‘my queue‘ )
channel.basic_publish ( routing_key=‘my queue',
body=‘I’m looking for Joanna‘ … )
Code missing:
Too verbose to serve as
example
Celery
It’s a distributed task queue for python
python
app
python
app
Celery
app
NODE a
NODE b
task
task task
Celery
It’s a distributed task queue for python
python
app
python
app
Celery
app
NODE a
NODE b
task
task task
RabbitMQ + amqp
Celery
It’s a distributed task queue for python
python
app
python
app
Celery
app
NODE a
NODE b
task
task task
result
result
result
RabbitMQ + amqp
Celery
It’s a distributed task queue for python
python
app
python
app
Celery
app
NODE a
NODE b
task
task task
result
result
result
RabbitMQ + amqp
“A single Celery process can process MILLIONS OF TASKS A
MINUTE, with sub-millisecond round-trip latency”
Celery
It’s a distributed task queue for python
python
app
python
app
Celery
app
NODE a
NODE b
task
task task
result
result
result
RabbitMQ + amqp
Result DB
Celery
It’s a distributed task queue for python
python
app
python
app
Celery
app
NODE a
NODE b
result
result
result
RabbitMQ + amqp
Result DB
task
task
Celery
It’s a distributed task queue for python
python
app
python
app
Celery
app
NODE a
NODE b
result
result
result
RabbitMQ + amqp
Result DB
task
task
single
worker
(process)
Celery
It’s a distributed task queue for python
python
app
python
app
Celery
app
NODE a
NODE b
result
result
result
RabbitMQ + amqp
Result DB
task
task
single
worker
(effectively 4 workers)
Celery
It’s a distributed task queue for python
python
app
python
app
Celery
app
NODE a
NODE b
result
result
result
RabbitMQ + amqp
Result DB
task
task
single
worker
Automatic Retry on
connection loss or failure.
(effectively 4 workers)
Celery
It’s a distributed task queue for python
python
app
python
app
Celery
app
NODE a
NODE b
result
result
result
RabbitMQ + amqp
Result DB
task
task
@app.task
def task():
print( “Hey I’m a task” )
@app.task
def launch_rocket( destination ):
return launch( destination, ‘now’ )
single
worker
NODE b
Celery—Example
from celery import Celery
app = Celery( 'task_pool',
broker='pyamqp://guest@localhost//‘ )
@app.task
def launch_rocket( destination ):
return launch( ‘now’, destination )
python
app
Celery
app
tasks
tasks
app name
Celery—Example
from celery import Celery
app = Celery( 'task_pool',
broker='pyamqp://guest@localhost//‘ )
@app.task
def launch_rocket( destination ):
return launch( ‘now’, destination )
from task_pool import launch_rocket
launch_rocket( ‘4501 Kingsway’ )
print( “rocket launch triggered” )
python
app
Celery
app
tasks
tasks
app name
Celery—Example
from celery import Celery
app = Celery( 'task_pool',
broker='pyamqp://guest@localhost//‘ )
@app.task
def launch_rocket( destination ):
return launch( ‘now’, destination )
from task_pool import launch_rocket
#asynch
launch_rocket( ‘4501 Kingsway’ )
print( “rocket launch triggered” )
python
app
Celery
app
tasks
tasks
Celery—Example
from celery import Celery
app = Celery( 'task_pool',
broker='pyamqp://guest@localhost//‘ )
@app.task
def launch_rocket( destination ):
return launch( ‘now’, destination )
from task_pool import launch_rocket
#asynch
launch_rocket( ‘4501 Kingsway’ )
print( “rocket launch triggered” )
#synch
result = launch_rocket.delay( ‘4501 Kingsway’ )
print( “launch was {}”.format(result) )
python
app
Celery
app
tasks
tasks
Celery—Example
from celery import Celery
app = Celery( 'task_pool',
broker='pyamqp://guest@localhost//‘ )
@app.task
def launch_rocket( destination ):
return launch( ‘now’, destination )
from task_pool import launch_rocket
#asynch
launch_rocket( ‘4501 Kingsway’ )
print( “rocket launch triggered” )
#synch
result = launch_rocket.delay( ‘4501 Kingsway’ )
print( “launch was {}”.format(result) )
python
app
Celery
app
tasks
tasks
That’s Celery in a nutshell
(not finished yet)
Celery—Intuition
Workers
task queues
Celery—Intuition
Celery—Intuition
What if tomcat needs to
process
many many tasks…
What would happen?
Celery—Intuition
What if tomcat needs to
process
many many tasks…
What would happen?
• Lots of bread in the queue
Celery—Intuition
What if tomcat needs to
process
many many tasks…
What would happen?
• Lots of bread in the queue
• Long process time for
individual loafs of bread
Celery—Intuition
What if tomcat needs to
process
many many tasks…
Can this configuration
be scaled?
Celery—Intuition
NODE a NODE b
Celery—Intuition
NODE a NODE b
DECOUPLING
CONSUMER
PRODUCER
Celery—Intuition
NODE a NODE b
DECOUPLING
CONSUMER
PRODUCER
Celery—Intuition
NODE a NODE b
DECOUPLING
CONSUMER
PRODUCER
Celery—Intuition
NODE a NODE b
MULTIPLE
CONSUMERS
MULTIPLE PRODUCERS
Celery—Intuition
NODE a NODE b
Celery—Intuition
NODE a NODE b
!!!!
!!
!!!
!
Celery—Intuition
NODE a NODE b
!!!!
!!
!!!
!
Control over resources
assigned to
“groups of tasks”
Celery—Intuition
NODE a NODE b
!!!!
!!
!!!
!
E.g.:
Synch on-demand tasks:
High priority, 4 threads
Asynch on-demand:
Medium priority, 2 threads
Background
Low priority, 1 thread, limited rate
Control over resources
assigned to
“groups of tasks”
Celery—Example
How can Workers
take advantage of
Multicore machines?
$ celery app1 -worker --concurrency=4
$ celery app2 -worker --concurrency=6
!!!!
!!
!!!
!
!!!!
!!!!
!!!!
!!
!!
!
!
!
Our webserver is written in Java, not
in python
Flower—what is it?
It’s a monitoring tool and web admin for Celery
Flower—what is it?
R
app
Java
app
Celery
app
NODE a
NODE b
task
task task
result
result
result
Flower
It’s a monitoring tool and web admin for Celery
Flower—what is it?
R
app
Java
app
Celery
app
NODE a
NODE b
task
task task
result
result
result
Flower
It’s a monitoring tool and web admin for Celery
@app.task
def launch_rocket( destination ):
return launch( ‘now’ )
POST
http://someurl:5555/api/task/apply/task_pool.launch_rocket
{ "args":["4501 Kingsway"] }
Celery & Flower—Benefits
• Fine control over tasks and their processing
Celery & Flower—Benefits
• Fine control over tasks and their processing
• Flexible and Decoupled architecture
• Tasks can be easily redeployed elsewhere with different amount of assigned resources
• Or say, one day, you say “I hate this architecture. Let’s put it in a Flask webserver”. You
could do so with very little changes.
Celery & Flower—Benefits
• Fine control over tasks and their processing
• Flexible and Decoupled architecture
• Tasks can be easily redeployed elsewhere with different amount of assigned resources
• Or say, one day, you say “I hate this architecture. Let’s put it in a Flask webserver”. You
could do so with very little changes.
• Scalable task architecture (a consequence of bullet one and two)
Celery & Flower—Benefits
• Fine control over tasks and their processing
• Flexible and Decoupled architecture
• Tasks can be easily redeployed elsewhere with different amount of assigned resources
• Or say, one day, you say “I hate this architecture. Let’s put it in a Flask webserver”. You
could do so with very little changes.
• Scalable task architecture (a consequence of bullet one and two)
• One-way language interoperability (tasks must be in python)
Celery & Flower—Benefits
• Fine control over tasks and their processing
• Flexible and Decoupled architecture
• Tasks can be easily redeployed elsewhere with different amount of assigned resources
• Or say, one day, you say “I hate this architecture. Let’s put it in a Flask webserver”. You
could do so with very little changes.
• Scalable task architecture (a consequence of bullet one and two)
• One-way language interoperability (tasks must be in python)
• Monitoring
• See real-time statistics
• Stop, restart, shutdown, inspect tasks
• Off-the-shelf tools for task progress self-reporting to the UI (e.g. UI progress bar)
Celery & Flower—Use case
Improving UI responsiveness
Celery & Flower—Use case
Improving UI responsiveness
Celery & Flower—Use case
Improving UI responsiveness
Asynch processing
Celery & Flower—Use case
Asynch UI-triggered tasks
Celery & Flower—Use case
Asynch UI-triggered tasks
synch
Typical UI-tomcat interaction
Celery & Flower—Use case
Asynch UI-triggered tasks
synch
Tomcat triggers and task
and
DOES NOT WAIT FOR IT.
asynch_pool
asynch
Celery & Flower—Use case
Asynch UI-triggered tasks
synch
Tomcat triggers and task
and
DOES NOT WAIT FOR IT.
• Create metadata (e.g. DB entry, or csv file)
• Clean something
• Send an e-mail
• etc
asynch
asynch_pool
Celery & Flower—Use case
Asynch UI-triggered tasks
asynch
asynch_pool
POST
http://someurl:5555/api/task/async-apply/async_pool.send_email
That’s all it takes to do it asynch
• Create metadata (e.g. DB entry, or csv file)
• Clean something
• Send an e-mail
• etc
synch
Celery & Flower—Use case
Scheduling background tasks from a custom UI
def task():
# ...
Celery & Flower—Use case
Scheduling background tasks from a custom UI
def task():
# ... background_pool
task
Celery & Flower—Use case
Scheduling background tasks from a custom UI
def task():
# ... background_pool
task
def schedule_task(sender, hours, minute, day_of_week):
sender.add_periodic_task(
crontab( hour, minute, day_of_week ),
task.s(),
)
Schedule for periodic execution
Celery & Flower—Use case
Scheduling background tasks from a custom UI
def task():
# ... background_pool
task
def schedule_task(sender, hours, minute, day_of_week):
sender.add_periodic_task(
crontab( hour, minute, day_of_week ),
task.s(),
)
POST
http://someurl:5555/api/task/async-apply/background_pool.schedule_task
{ "args":[“7“, “30”, “Monday”] }
Celery + Flower—Who’s maintaining them
• Let’s say you’re worried about using some exotic tool and trusting
your production system to it….
Celery + Flower—Who’s using them
• Let’s say you’re worried about using some exotic tool and trusting
your production system to it….
Celery + Flower—Who’s using them
• Let’s say you’re worried about using some exotic tool and trusting
your production system to it….
“Each time a photo is posted, the system finds out all the
users followers […], and assigns individual tasks to place
the photo into each followers feed”
Celery + Flower—The case against Fork
But I could “just” run a python process from Java:
Runtime.getRuntime().exec("python3 launch_rocket.py");
Celery + Flower—The case against Fork
But I could “just” run a python process from Java:
Runtime.getRuntime().exec("python3 launch_rocket.py");
Celery + Flower “Just” forking a new process
Celery + Flower—The case against threads
But I could “just” do asynch processing with threads (from Tomcat):
new Thread( public void run(){ launch_rocket(“501 Kingsway”) }).start();
Celery + Flower—The case against threads
But I could “just” do asynch processing with threads (from Tomcat):
new Thread( public void run(){ launch_rocket(“501 Kingsway”) }).start();
Celery + Flower “Just” creating threads from tomcat
Celery + Flower—Disclaimer
This is work in progress
Not everything that I mentioned is deployed in res01
Celery + Flower—Disclaimer
This is work in progress
Not everything that I mentioned is deployed in res01
e.g.
• There’s a single worker at the moment
• No threads, no priorities, no distributed
Celery + Flower—Disclaimer
This is work in progress
Not everything that I mentioned is deployed in res01
e.g.
• There’s a single worker at the moment
• No threads, no priorities, no distributed
( The infrastructure is in place )
Celery + Flower—Drawbacks
• One time learning curve (for whoever wants to use it)
Celery + Flower—Drawbacks
• One time learning curve (for whoever wants to use it)
Celery + Flower—Drawbacks
• One time learning curve (for whoever wants to use it)
• Deployment complexity introduced
• No longer just moving a WAR file
Celery + Flower—Drawbacks
• One time learning curve (for whoever wants to use it)
• Deployment complexity introduced
• No longer just moving a WAR file
• Mismatch between servers environment and our laptops
Celery + Flower—Drawbacks
• One time learning curve (for whoever wants to use it)
• Deployment complexity introduced
• No longer just moving a WAR file
• Mismatch between servers environment and our laptops
a. Having to configure your laptop to match the server’s environment
b. “Works on my laptops” problems

More Related Content

What's hot

What's hot (20)

Virtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAP
Virtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAPVirtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAP
Virtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAP
 
Redis 101
Redis 101Redis 101
Redis 101
 
Nginx Internals
Nginx InternalsNginx Internals
Nginx Internals
 
PostgreSQL Extensions: A deeper look
PostgreSQL Extensions:  A deeper lookPostgreSQL Extensions:  A deeper look
PostgreSQL Extensions: A deeper look
 
Scaling up task processing with Celery
Scaling up task processing with CeleryScaling up task processing with Celery
Scaling up task processing with Celery
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Redis - Usability and Use Cases
Redis - Usability and Use CasesRedis - Usability and Use Cases
Redis - Usability and Use Cases
 
MyRocks introduction and production deployment
MyRocks introduction and production deploymentMyRocks introduction and production deployment
MyRocks introduction and production deployment
 
Spider HA 20100922(DTT#7)
Spider HA 20100922(DTT#7)Spider HA 20100922(DTT#7)
Spider HA 20100922(DTT#7)
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
php-src の歩き方
php-src の歩き方php-src の歩き方
php-src の歩き方
 
Scylla Summit 2022: How to Migrate a Counter Table for 68 Billion Records
Scylla Summit 2022: How to Migrate a Counter Table for 68 Billion RecordsScylla Summit 2022: How to Migrate a Counter Table for 68 Billion Records
Scylla Summit 2022: How to Migrate a Counter Table for 68 Billion Records
 
REST: From GET to HATEOAS
REST: From GET to HATEOASREST: From GET to HATEOAS
REST: From GET to HATEOAS
 
Distributed load testing with k6
Distributed load testing with k6Distributed load testing with k6
Distributed load testing with k6
 
Facebook & Twitter API
Facebook & Twitter APIFacebook & Twitter API
Facebook & Twitter API
 
Redis cluster
Redis clusterRedis cluster
Redis cluster
 
Redis overview for Software Architecture Forum
Redis overview for Software Architecture ForumRedis overview for Software Architecture Forum
Redis overview for Software Architecture Forum
 
REST API
REST APIREST API
REST API
 
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricksQuery Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
 
H2O - the optimized HTTP server
H2O - the optimized HTTP serverH2O - the optimized HTTP server
H2O - the optimized HTTP server
 

Similar to Flower and celery

JConf.dev 2022 - Apache Pulsar Development 101 with Java
JConf.dev 2022 - Apache Pulsar Development 101 with JavaJConf.dev 2022 - Apache Pulsar Development 101 with Java
JConf.dev 2022 - Apache Pulsar Development 101 with Java
Timothy Spann
 
NoSQL afternoon in Japan Kumofs & MessagePack
NoSQL afternoon in Japan Kumofs & MessagePackNoSQL afternoon in Japan Kumofs & MessagePack
NoSQL afternoon in Japan Kumofs & MessagePack
Sadayuki Furuhashi
 
NoSQL afternoon in Japan kumofs & MessagePack
NoSQL afternoon in Japan kumofs & MessagePackNoSQL afternoon in Japan kumofs & MessagePack
NoSQL afternoon in Japan kumofs & MessagePack
Sadayuki Furuhashi
 
H2O World - What's New in H2O with Cliff Click
H2O World - What's New in H2O with Cliff ClickH2O World - What's New in H2O with Cliff Click
H2O World - What's New in H2O with Cliff Click
Sri Ambati
 
Lindheimer Philippe
Lindheimer PhilippeLindheimer Philippe
Lindheimer Philippe
Carl Ford
 
Asterisk World2008
Asterisk World2008Asterisk World2008
Asterisk World2008
Carl Ford
 
Lindsay distributed geventzmq
Lindsay distributed geventzmqLindsay distributed geventzmq
Lindsay distributed geventzmq
Robin Xiao
 

Similar to Flower and celery (20)

CocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIsCocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIs
 
Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)
Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)
Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)
 
Rabbit MQ introduction
Rabbit MQ introductionRabbit MQ introduction
Rabbit MQ introduction
 
OCaml-MPST / Global Protocol Combinators
OCaml-MPST / Global Protocol CombinatorsOCaml-MPST / Global Protocol Combinators
OCaml-MPST / Global Protocol Combinators
 
All Day DevOps - FLiP Stack for Cloud Data Lakes
All Day DevOps - FLiP Stack for Cloud Data LakesAll Day DevOps - FLiP Stack for Cloud Data Lakes
All Day DevOps - FLiP Stack for Cloud Data Lakes
 
JConf.dev 2022 - Apache Pulsar Development 101 with Java
JConf.dev 2022 - Apache Pulsar Development 101 with JavaJConf.dev 2022 - Apache Pulsar Development 101 with Java
JConf.dev 2022 - Apache Pulsar Development 101 with Java
 
From a Kafkaesque Story to The Promised Land at LivePerson
From a Kafkaesque Story to The Promised Land at LivePersonFrom a Kafkaesque Story to The Promised Land at LivePerson
From a Kafkaesque Story to The Promised Land at LivePerson
 
Architectures with Windows Azure
Architectures with Windows AzureArchitectures with Windows Azure
Architectures with Windows Azure
 
NoSQL afternoon in Japan Kumofs & MessagePack
NoSQL afternoon in Japan Kumofs & MessagePackNoSQL afternoon in Japan Kumofs & MessagePack
NoSQL afternoon in Japan Kumofs & MessagePack
 
NoSQL afternoon in Japan kumofs & MessagePack
NoSQL afternoon in Japan kumofs & MessagePackNoSQL afternoon in Japan kumofs & MessagePack
NoSQL afternoon in Japan kumofs & MessagePack
 
StormMQ Introduction to AMQP, Dublin
StormMQ Introduction to AMQP, DublinStormMQ Introduction to AMQP, Dublin
StormMQ Introduction to AMQP, Dublin
 
Plank
PlankPlank
Plank
 
H2O World - What's New in H2O with Cliff Click
H2O World - What's New in H2O with Cliff ClickH2O World - What's New in H2O with Cliff Click
H2O World - What's New in H2O with Cliff Click
 
Lindheimer Philippe
Lindheimer PhilippeLindheimer Philippe
Lindheimer Philippe
 
Free Pbx Ot
Free Pbx OtFree Pbx Ot
Free Pbx Ot
 
Asterisk World2008
Asterisk World2008Asterisk World2008
Asterisk World2008
 
Lindsay distributed geventzmq
Lindsay distributed geventzmqLindsay distributed geventzmq
Lindsay distributed geventzmq
 
Formal analysis-crypto-proto
Formal analysis-crypto-protoFormal analysis-crypto-proto
Formal analysis-crypto-proto
 
C# Async on iOS and Android - Miguel de Icaza, CTO of Xamarin
C# Async on iOS and Android - Miguel de Icaza, CTO of XamarinC# Async on iOS and Android - Miguel de Icaza, CTO of Xamarin
C# Async on iOS and Android - Miguel de Icaza, CTO of Xamarin
 
C# Client to Cloud
C# Client to CloudC# Client to Cloud
C# Client to Cloud
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 

Flower and celery

  • 1. Intro to Celery or Everything you are now able to do, but you did not know about Approximate time: 55mins Rafael Roman Otero
  • 2. Detour—message queue A queue of messages (really!) Q Invariant?
  • 3. Detour—message queue A queue of messages (really!) Q Invariant? timestamp( peek(Q) ) is oldest in Q
  • 4. Detour—message queue A queue of messages (really!) Q Invariant? timestamp( peek(Q) ) is oldest in Q Applications Buffered Communications
  • 5. Detour—message queue A queue of messages (really!) Q Invariant? timestamp( peek(Q) ) is oldest in Q Applications Buffered Communications Example A human example of buffered and unbuffered communications ?
  • 6. Detour—message queue A queue of messages (really!) Q Invariant? timestamp( peek(Q) ) is oldest in Q Applications? Communicatoins Example A human example of buffered and unbuffered communications ? Is there any benefit of buffered over unbuffered communication?
  • 7. Detour—message queue A queue of messages (really!) Q Invariant? timestamp( peek(Q) ) is oldest in Q Applications? Anything that requires a buffer that keeps arrival order (e.g., communications) Communications A human example of buffered and unbuffered communications ? Is there any benefit of buffered over unbuffered communication? Talking and listening does not have to take place at the same time.
  • 8. Detour—message queue Messages queues are used as infrastructure for inter-process communication (IPC) process process process NODE a NODE b
  • 9. Detour—message queue Messages queues are used as infrastructure for inter-process communication (IPC) process process process NODE a NODE b
  • 10. Detour—message queue Messages queues are used as infrastructure for inter-process communication (IPC) process process process NODE a NODE b Too abstract
  • 11. Detour—message queue Messages queues are used as infrastructure for inter-process communication (IPC) process process process NODE a NODE b
  • 12. Detour—message queue Messages queues are used as infrastructure for inter-process communication (IPC) process process process NODE a NODE b Too abstract
  • 13. Detour—IPC with message queues Intermediary a send receive b c Process b Process c Process a
  • 14. Detour—IPC with message queues Intermediary a send receive b c Process b Process c Process a Communicating processes
  • 15. Detour—IPC with message queues Intermediary a send receive b c Process b Process c Process a Communicating processes Can be many things
  • 16. Detour—IPC with message queues OS a send receive b Process a Process b Physical Layer MAC Layer Transport Layer Network Layer App Layer Process c OS send receive Physical Layer MAC Layer Transport Layer Network Layer App Layer c NODE a NODE b
  • 17. Detour—IPC with message queues Layer-2 communication in Linux: • sendto ( mac address, msg, … ) • recvfrom ( mac address, msg, … ) OS a send receive b Process a Process b Physical Layer MAC Layer Transport Layer Network Layer App Layer Process c OS send receive Physical Layer MAC Layer Transport Layer Network Layer App Layer c NODE a NODE b
  • 18. Detour—IPC with message queues Layer-2 communication in Linux: • sendto ( mac address, msg, … ) • recvfrom ( mac address, msg, … ) OS a send receive b Process a Process b Physical Layer MAC Layer Transport Layer Network Layer App Layer Process c OS send receive Physical Layer MAC Layer Transport Layer Network Layer App Layer c NODE a NODE b
  • 19. Detour—IPC with message queues Layer-2 communication in Linux: • sendto ( mac address, msg, … ) • recvfrom ( mac address, msg, … ) OS a send receive b Process a Process b Physical Layer MAC Layer Transport Layer Network Layer App Layer Process c OS send receive Physical Layer MAC Layer Transport Layer Network Layer App Layer c NODE a NODE b
  • 20. Detour—IPC with message queues Layer-2 communication in Linux: • sendto ( mac address, msg, … ) • recvfrom ( mac address, msg, … ) OS a send receive b Process a Process b Physical Layer MAC Layer Transport Layer Network Layer App Layer Process c OS send receive Physical Layer MAC Layer Transport Layer Network Layer App Layer c NODE a NODE b Synchronous IO What does that mean?
  • 21. Detour—IPC with message queues OS send receive Physical Layer MAC Layer Transport Layer Network Layer App Layer OS send receive Physical Layer MAC Layer Transport Layer Network Layer App Layer Function a Class b send receive Language a b Module c send receive Language c NODE a NODE b
  • 22. Detour—IPC with message queues processprocess OS send receive Physical Layer MAC Layer Transport Layer Network Layer App Layer OS send receive Physical Layer MAC Layer Transport Layer Network Layer App Layer Function a Class b send receive Language a b Module c send receive Language c NODE a NODE b
  • 23. Detour—IPC with message queues NODE a NODE b OS send receive Physical Layer MAC Layer Transport Layer Network Layer App Layer OS send receive Physical Layer MAC Layer Transport Layer Network Layer App Layer Same language Same language Function a Class b send receive Language a b Module c send receive Language c
  • 24. Detour—IPC with message queues NODE a NODE b OS send receive Physical Layer MAC Layer Transport Layer Network Layer App Layer OS send receive Physical Layer MAC Layer Transport Layer Network Layer App Layer Same language Same language Function a Class b send receive Lang + lib a b Module c send receive Lang + lib c
  • 25. Detour—IPC with message queues OS send receive Java process(es) Physical Layer MAC Layer Transport Layer Network Layer App Layer OS send receive Physical Layer MAC Layer Transport Layer Network Layer App Layer NODE a NODE b Java process Same language Same language Function a Class b send receive Java + Akka a b Module c send receive Java + Akka c
  • 26. Detour—IPC with message queues public static class Actor extends UntypedActor { public void onReceive( Object message ) { if ( message.equals( "I'm looking for Joanna" ) ) getSender().tell( "She's taken", getSelf() ); } } OS send receive Java process(es) Physical Layer MAC Layer Transport Layer Network Layer App Layer OS send receive Physical Layer MAC Layer Transport Layer Network Layer App Layer Java process send receive Java + Akka a b send receive Java + Akka c NODE a NODE b So verbose
  • 27. Detour—IPC with message queues No example… NODE a NODE b OS send receive Java process(es) Physical Layer MAC Layer Transport Layer Network Layer App Layer OS send receive Physical Layer MAC Layer Transport Layer Network Layer App Layer Java process send receive Erlang a b send receive Erlang c
  • 28. Detour—IPC with message queues NODE a NODE b OSsend receive OS send receive send receive Language Message broker send receive Language send receive Message Broker a b send receive Message Broker c Message broker Function a Class b Module c
  • 29. Detour—IPC with message queues NODE a NODE b OSsend receive OS send receive send receive Language Message broker send receive Language send receive Message Broker a b send receive Message Broker c Message broker Function a Class b Module c Handle: Queuing Routing Reliability etc
  • 30. Detour—IPC with message queues NODE a NODE b OSsend receive OS send receive send receive Language Message broker send receive Language send receive Message Broker a b send receive Message Broker c Message broker Function a Class b Module c Protocols: AMQP MQTT
  • 31. Detour—IPC with message queues NODE a NODE b OSsend receive OS send receive send receive Language Message broker send receive Language send receive Message Broker a b send receive Message Broker c Message broker Function a Class b Module c Protocols: AMQP MQTT • Advance Message Queueing protocol • App-layer protocol
  • 32. Detour—IPC with message queues NODE a NODE b OSsend receive OS send receive send receive Language Message broker send receive Language send receive Message Broker a b send receive Message Broker c Message broker Function a Class b Module c Protocols: AMQP MQTT • Advance Message Queueing protocol • App-layer protocol • Publish and subscribe What is P and S ?
  • 33. Detour—IPC with message queues NODE a NODE b OSsend receive OS send receive send receive Language Message broker send receive Language send receive Message Broker a b send receive Message Broker c Message broker Function a Class b Module c Steve Vinoski. 2006. Advanced Message Queuing Protocol. IEEE Internet Computing 10, 6 (November 2006), 87-89. Protocols: AMQP MQTT • Advance Message Queueing protocol • App-layer protocol • Publish and subscribe
  • 34. Detour—IPC with message queues NODE a NODE b OSsend receive OS send receive send receive Erlang RabbitMQ send receive Erlang send receive RabbitMQ a b send receive RabbitMQ c Message broker amqp amqp
  • 35. Detour—IPC with message queues NODE a NODE b OSsend receive OS send receive send receive Erlang RabbitMQ send receive Erlang send receive RabbitMQ a b send receive RabbitMQ c Message broker amqp amqp script script Python Java class class
  • 36. Detour—IPC with message queues NODE a NODE b OSsend receive OS send receive send receive Erlang RabbitMQ send receive Erlang send receive RabbitMQ a b send receive RabbitMQ c Message broker amqp amqp script script Python Java class class channel = connection.channel() channel.queue_declare( queue=‘my queue‘ ) channel.basic_publish ( routing_key=‘my queue', body=‘I’m looking for Joanna‘ … )
  • 37. Detour—IPC with message queues NODE a NODE b OSsend receive OS send receive send receive Erlang RabbitMQ send receive Erlang send receive RabbitMQ a b send receive RabbitMQ c Message broker amqp amqp script script Python Java class class channel = connection.channel() channel.queue_declare( queue=‘my queue‘ ) channel.basic_publish ( routing_key=‘my queue', body=‘I’m looking for Joanna‘ … ) Code missing: Too verbose to serve as example
  • 38. Celery It’s a distributed task queue for python python app python app Celery app NODE a NODE b task task task
  • 39. Celery It’s a distributed task queue for python python app python app Celery app NODE a NODE b task task task RabbitMQ + amqp
  • 40. Celery It’s a distributed task queue for python python app python app Celery app NODE a NODE b task task task result result result RabbitMQ + amqp
  • 41. Celery It’s a distributed task queue for python python app python app Celery app NODE a NODE b task task task result result result RabbitMQ + amqp “A single Celery process can process MILLIONS OF TASKS A MINUTE, with sub-millisecond round-trip latency”
  • 42. Celery It’s a distributed task queue for python python app python app Celery app NODE a NODE b task task task result result result RabbitMQ + amqp Result DB
  • 43. Celery It’s a distributed task queue for python python app python app Celery app NODE a NODE b result result result RabbitMQ + amqp Result DB task task
  • 44. Celery It’s a distributed task queue for python python app python app Celery app NODE a NODE b result result result RabbitMQ + amqp Result DB task task single worker (process)
  • 45. Celery It’s a distributed task queue for python python app python app Celery app NODE a NODE b result result result RabbitMQ + amqp Result DB task task single worker (effectively 4 workers)
  • 46. Celery It’s a distributed task queue for python python app python app Celery app NODE a NODE b result result result RabbitMQ + amqp Result DB task task single worker Automatic Retry on connection loss or failure. (effectively 4 workers)
  • 47. Celery It’s a distributed task queue for python python app python app Celery app NODE a NODE b result result result RabbitMQ + amqp Result DB task task @app.task def task(): print( “Hey I’m a task” ) @app.task def launch_rocket( destination ): return launch( destination, ‘now’ ) single worker NODE b
  • 48. Celery—Example from celery import Celery app = Celery( 'task_pool', broker='pyamqp://guest@localhost//‘ ) @app.task def launch_rocket( destination ): return launch( ‘now’, destination ) python app Celery app tasks tasks app name
  • 49. Celery—Example from celery import Celery app = Celery( 'task_pool', broker='pyamqp://guest@localhost//‘ ) @app.task def launch_rocket( destination ): return launch( ‘now’, destination ) from task_pool import launch_rocket launch_rocket( ‘4501 Kingsway’ ) print( “rocket launch triggered” ) python app Celery app tasks tasks app name
  • 50. Celery—Example from celery import Celery app = Celery( 'task_pool', broker='pyamqp://guest@localhost//‘ ) @app.task def launch_rocket( destination ): return launch( ‘now’, destination ) from task_pool import launch_rocket #asynch launch_rocket( ‘4501 Kingsway’ ) print( “rocket launch triggered” ) python app Celery app tasks tasks
  • 51. Celery—Example from celery import Celery app = Celery( 'task_pool', broker='pyamqp://guest@localhost//‘ ) @app.task def launch_rocket( destination ): return launch( ‘now’, destination ) from task_pool import launch_rocket #asynch launch_rocket( ‘4501 Kingsway’ ) print( “rocket launch triggered” ) #synch result = launch_rocket.delay( ‘4501 Kingsway’ ) print( “launch was {}”.format(result) ) python app Celery app tasks tasks
  • 52. Celery—Example from celery import Celery app = Celery( 'task_pool', broker='pyamqp://guest@localhost//‘ ) @app.task def launch_rocket( destination ): return launch( ‘now’, destination ) from task_pool import launch_rocket #asynch launch_rocket( ‘4501 Kingsway’ ) print( “rocket launch triggered” ) #synch result = launch_rocket.delay( ‘4501 Kingsway’ ) print( “launch was {}”.format(result) ) python app Celery app tasks tasks That’s Celery in a nutshell (not finished yet)
  • 55. Celery—Intuition What if tomcat needs to process many many tasks… What would happen?
  • 56. Celery—Intuition What if tomcat needs to process many many tasks… What would happen? • Lots of bread in the queue
  • 57. Celery—Intuition What if tomcat needs to process many many tasks… What would happen? • Lots of bread in the queue • Long process time for individual loafs of bread
  • 58. Celery—Intuition What if tomcat needs to process many many tasks… Can this configuration be scaled?
  • 60. Celery—Intuition NODE a NODE b DECOUPLING CONSUMER PRODUCER
  • 61. Celery—Intuition NODE a NODE b DECOUPLING CONSUMER PRODUCER
  • 62. Celery—Intuition NODE a NODE b DECOUPLING CONSUMER PRODUCER
  • 63. Celery—Intuition NODE a NODE b MULTIPLE CONSUMERS MULTIPLE PRODUCERS
  • 66. Celery—Intuition NODE a NODE b !!!! !! !!! ! Control over resources assigned to “groups of tasks”
  • 67. Celery—Intuition NODE a NODE b !!!! !! !!! ! E.g.: Synch on-demand tasks: High priority, 4 threads Asynch on-demand: Medium priority, 2 threads Background Low priority, 1 thread, limited rate Control over resources assigned to “groups of tasks”
  • 68. Celery—Example How can Workers take advantage of Multicore machines? $ celery app1 -worker --concurrency=4 $ celery app2 -worker --concurrency=6 !!!! !! !!! ! !!!! !!!! !!!! !! !! ! ! ! Our webserver is written in Java, not in python
  • 69. Flower—what is it? It’s a monitoring tool and web admin for Celery
  • 70. Flower—what is it? R app Java app Celery app NODE a NODE b task task task result result result Flower It’s a monitoring tool and web admin for Celery
  • 71. Flower—what is it? R app Java app Celery app NODE a NODE b task task task result result result Flower It’s a monitoring tool and web admin for Celery @app.task def launch_rocket( destination ): return launch( ‘now’ ) POST http://someurl:5555/api/task/apply/task_pool.launch_rocket { "args":["4501 Kingsway"] }
  • 72. Celery & Flower—Benefits • Fine control over tasks and their processing
  • 73. Celery & Flower—Benefits • Fine control over tasks and their processing • Flexible and Decoupled architecture • Tasks can be easily redeployed elsewhere with different amount of assigned resources • Or say, one day, you say “I hate this architecture. Let’s put it in a Flask webserver”. You could do so with very little changes.
  • 74. Celery & Flower—Benefits • Fine control over tasks and their processing • Flexible and Decoupled architecture • Tasks can be easily redeployed elsewhere with different amount of assigned resources • Or say, one day, you say “I hate this architecture. Let’s put it in a Flask webserver”. You could do so with very little changes. • Scalable task architecture (a consequence of bullet one and two)
  • 75. Celery & Flower—Benefits • Fine control over tasks and their processing • Flexible and Decoupled architecture • Tasks can be easily redeployed elsewhere with different amount of assigned resources • Or say, one day, you say “I hate this architecture. Let’s put it in a Flask webserver”. You could do so with very little changes. • Scalable task architecture (a consequence of bullet one and two) • One-way language interoperability (tasks must be in python)
  • 76. Celery & Flower—Benefits • Fine control over tasks and their processing • Flexible and Decoupled architecture • Tasks can be easily redeployed elsewhere with different amount of assigned resources • Or say, one day, you say “I hate this architecture. Let’s put it in a Flask webserver”. You could do so with very little changes. • Scalable task architecture (a consequence of bullet one and two) • One-way language interoperability (tasks must be in python) • Monitoring • See real-time statistics • Stop, restart, shutdown, inspect tasks • Off-the-shelf tools for task progress self-reporting to the UI (e.g. UI progress bar)
  • 77. Celery & Flower—Use case Improving UI responsiveness
  • 78. Celery & Flower—Use case Improving UI responsiveness
  • 79. Celery & Flower—Use case Improving UI responsiveness Asynch processing
  • 80. Celery & Flower—Use case Asynch UI-triggered tasks
  • 81. Celery & Flower—Use case Asynch UI-triggered tasks synch Typical UI-tomcat interaction
  • 82. Celery & Flower—Use case Asynch UI-triggered tasks synch Tomcat triggers and task and DOES NOT WAIT FOR IT. asynch_pool asynch
  • 83. Celery & Flower—Use case Asynch UI-triggered tasks synch Tomcat triggers and task and DOES NOT WAIT FOR IT. • Create metadata (e.g. DB entry, or csv file) • Clean something • Send an e-mail • etc asynch asynch_pool
  • 84. Celery & Flower—Use case Asynch UI-triggered tasks asynch asynch_pool POST http://someurl:5555/api/task/async-apply/async_pool.send_email That’s all it takes to do it asynch • Create metadata (e.g. DB entry, or csv file) • Clean something • Send an e-mail • etc synch
  • 85. Celery & Flower—Use case Scheduling background tasks from a custom UI def task(): # ...
  • 86. Celery & Flower—Use case Scheduling background tasks from a custom UI def task(): # ... background_pool task
  • 87. Celery & Flower—Use case Scheduling background tasks from a custom UI def task(): # ... background_pool task def schedule_task(sender, hours, minute, day_of_week): sender.add_periodic_task( crontab( hour, minute, day_of_week ), task.s(), ) Schedule for periodic execution
  • 88. Celery & Flower—Use case Scheduling background tasks from a custom UI def task(): # ... background_pool task def schedule_task(sender, hours, minute, day_of_week): sender.add_periodic_task( crontab( hour, minute, day_of_week ), task.s(), ) POST http://someurl:5555/api/task/async-apply/background_pool.schedule_task { "args":[“7“, “30”, “Monday”] }
  • 89. Celery + Flower—Who’s maintaining them • Let’s say you’re worried about using some exotic tool and trusting your production system to it….
  • 90. Celery + Flower—Who’s using them • Let’s say you’re worried about using some exotic tool and trusting your production system to it….
  • 91. Celery + Flower—Who’s using them • Let’s say you’re worried about using some exotic tool and trusting your production system to it…. “Each time a photo is posted, the system finds out all the users followers […], and assigns individual tasks to place the photo into each followers feed”
  • 92. Celery + Flower—The case against Fork But I could “just” run a python process from Java: Runtime.getRuntime().exec("python3 launch_rocket.py");
  • 93. Celery + Flower—The case against Fork But I could “just” run a python process from Java: Runtime.getRuntime().exec("python3 launch_rocket.py"); Celery + Flower “Just” forking a new process
  • 94. Celery + Flower—The case against threads But I could “just” do asynch processing with threads (from Tomcat): new Thread( public void run(){ launch_rocket(“501 Kingsway”) }).start();
  • 95. Celery + Flower—The case against threads But I could “just” do asynch processing with threads (from Tomcat): new Thread( public void run(){ launch_rocket(“501 Kingsway”) }).start(); Celery + Flower “Just” creating threads from tomcat
  • 96. Celery + Flower—Disclaimer This is work in progress Not everything that I mentioned is deployed in res01
  • 97. Celery + Flower—Disclaimer This is work in progress Not everything that I mentioned is deployed in res01 e.g. • There’s a single worker at the moment • No threads, no priorities, no distributed
  • 98. Celery + Flower—Disclaimer This is work in progress Not everything that I mentioned is deployed in res01 e.g. • There’s a single worker at the moment • No threads, no priorities, no distributed ( The infrastructure is in place )
  • 99. Celery + Flower—Drawbacks • One time learning curve (for whoever wants to use it)
  • 100. Celery + Flower—Drawbacks • One time learning curve (for whoever wants to use it)
  • 101. Celery + Flower—Drawbacks • One time learning curve (for whoever wants to use it) • Deployment complexity introduced • No longer just moving a WAR file
  • 102. Celery + Flower—Drawbacks • One time learning curve (for whoever wants to use it) • Deployment complexity introduced • No longer just moving a WAR file • Mismatch between servers environment and our laptops
  • 103. Celery + Flower—Drawbacks • One time learning curve (for whoever wants to use it) • Deployment complexity introduced • No longer just moving a WAR file • Mismatch between servers environment and our laptops a. Having to configure your laptop to match the server’s environment b. “Works on my laptops” problems

Editor's Notes

  1. The first concept that you need to understand is that of message queue. A message queue… Messages come in, and messages come out. Question: Anybody knows what’s the one condition that has to hold for a queue to be a queue (as opposed to something else)?
  2. Message queues are used as BUFFERS in different types of communications.
  3. Question, what would be an everyday example of…. (mail, mailbox VS phone, direct speaking)
  4. Now, do you see any benefit of buffered over unbuffered communication?
  5. Talking and listening…. and this takes to our next point.
  6. In software, message queues are the infrastructure that enables processes to communicate with each other.
  7. As you can see from the illustration, communication can be within the same node, or across different nodes.
  8. Now, this is illustration is too abstract. Let me try and give you something closer to its actual implementation
  9. From this more elaborated illustration you can tell bi-directional communication can be stablished between 2 processes using 2 queues. One queue for each direction.
  10. But, again, this second picture is still quite abstract. So I’ll give you something more real.
  11. This is a little more real. This illustration makes it explicit that processes talk to each other by means of an intermediary. This intermediary keeps a queue for each process (one for a, one for…).
  12. Something I want to highlight from this picture is that the concept of queuing and dequeuing has been replaced for that of sending and receiving. In other words, we’re now dealing with communicating processes
  13. Intermediaries come in many forms and shapes, and they can build on each other. To see how let us look at the very first intermediary: the OS.
  14. OSes support sending and receiving of messages via system calls. These system calls are translated into messages that come in and out from different places in the network stack. Again, processes can be within the same machine or distributed.
  15. This one here is an example of a… On one node you would have a process calling….
  16. Because it’s layer 2, sendto will send the message via the MAC layer, and recvfrom will receive also from the MAC layer.
  17. Still the physical sending of ones and zeroes will take place at the physical layer. This can be a wired or a wireless link.
  18. Something relevant you need to know about IO is that IO can be synchr or asynch. In the example, sento and recvfrom are…. (NOTE: diff from asynch communication)
  19. Intermediaries can also be programming languages. If they are compiled or interpreted doesn’t matter. In either case they provide programs with message passing mechanisms. Whether those mechanisms are translated into layer 3 or layer 5 messages, is entirely up to the language,
  20. In this context we are talking about functions, classes or modules within a program, as it is programs who use the programming language facilities to send and receive messages, NOT PROCESSES.
  21. Because we’re talking about programs and not processes, for communication to be possible, all programs must be written in the same language
  22. In many cases languages do not have built-in support for message passing. Instead they rely on libraries.
  23. This is, for instance, the case of Java. Java does not have primitives for sending and receiving messages. But there are libraries such as akka that enhance Java with message passing primitives.
  24. This is an example of an Akka application in Java. In this example…
  25. Another example I wanted to show you is Erlang. Erlang is a language for distributed programming, and unlike Java, it has built-in support for message passing. But I can’t show you an example because…
  26. Another type of intermediary (higher-level intermediaries) are message brokers.
  27. Brokers handle… and a few other things that I’m not really quite aware of.
  28. In brokers the actual exchange of messages takes place in very specific protocols. Examples of these protocols are…
  29. AMQP, for instance, stands for…
  30. AMQP also allows for messages to be delivered in a … (fashion) (Special case producer and consumer)
  31. I’m not entirely sure who is responsible for what exactly, whether it’s the broker or the protocol…. But if you’re interested. that’s the original publication
  32. Now let’s look at an specific message broker: rabbitmq. Rabbitmq is written in Erlang, and it uses the AMQP protocol for communication.
  33. RabbitMQ enables applications to send messages to each other, even if these applications are written in different languages. All you need is a rabbitMQ client.
  34. This code is an excerpt from a python application… you start by creating a channel
  35. Likewise, on the java side, you would have... Well a lot of code. Because that’s how Java is. So you will have to imagine java replying that Joanna is taken (The important part is the language interoperability that you get with rabbitmq)
  36. Celery is a… It works by having one or more python apps sending tasks to….
  37. The queueing infrastructure is RabbitMQ. There is also the possibility to use different brokers, but RabbitMQ is the best of the available options.
  38. Again, these python apps send tasks to a celery app, AND ONCE a task is completed, it is possible for the Celery app to send back a result
  39. How FAST is this round-trip communication? Documentation states that…. (that would be, of course, without considering the time it takes a task to produce its result)
  40. Results from tasks can also be PERSISTED. That is, you can store them in the result DB for later inspection. Now, this is not entirely accurate, because tasks do not get sent.
  41. Tasks are part of the Celery app itself. Python apps instead send something else… (I don’t know what it is, id? String?).
  42. The “thing” that actually executes tasks in Celery is called a worker A worker is simply a process
  43. There is one single worker per APP, but you can specify the worker to have n threads at its disposal. IN THIS PICTURE YOU CAN THINK OF THIS WORKER AS hAVING 4 THREADS to run tasks…
  44. Something interesting about workers is that….In the event of connection loss or failure, they will AUTOMATICALLY RETRY.
  45. Now an example. Consider the following two tasks. The first task is named task and prints… and it does not return a value. The second task…
  46. This is a more complete example. In a Celery app you have to: Import… Configure the app by GIVING IT a name and the brokers address. Tasks definitions
  47. Then any python application can “trigger a task” by Importing the task from its queue Then you trigger the task by calling the task as a function. In this case you’d say… That’s it
  48. Something to notice here is that the task launch rocket was executed asynchronously… (default semantics of calling a task on celery)
  49. If you wanted to do it synchronously (i.e. block until the result is ready) you would say….
  50. DOES THAT MAKE SENSE????
  51. Sometimes it’s useful to see things from a different perspective. If I were to leave an image of Celery for you it’d be this: (One or more conveyor belts, where you have one or more workers )
  52. So any time tomcat needs to get a python task done, tomcat simply needs to place the task in the queue and a worker will get it done….
  53. Questions…
  54. Since there’s only so much bread a worker can handle, there’d be…
  55. if anyone is waiting for a particular loaf of bread to get processed, that person would have to wait perhaps a long time
  56. A second question is … how do we solve this?
  57. Yes it can. We can simply… Create more workers and more queues Distribute them across different nodes
  58. In this scenario, scaling is possible thanks to the decoupling that exists between THE PRODUCER OF THESE TASKS AND THEIR CONSUMERS.
  59. SEPARATION OF CONCERNS is one of those concepts you learn at school that is often undervalued, but it’s very very important
  60. In this PARTICULAR CASE it is the difference between SCALING and NOT SCALING.
  61. Because of this separation, in celery you can have multiple producers, multiple consumers, and consumers consuming from more than one queue.
  62. You can also limit the amount of tasks a queue is allowed to process per minute.
  63. You can also set different priorities for different queues
  64. ALL This, together with the fact that you can assign n number of threads to each worker, gives you control over the resources that you assign to each group of tasks (which is important, again, for scalability)
  65. You could have, for example, three different queues. One for …
  66. Okay.. so far… we have miss one important detail…. One way to do the interfacing…. is with a java RabbitMQ client… from java we write/read directly into Celery’s queue…. But it’s complicated A simpler approach is flower….
  67. What is flower? Flower… is a
  68. Visually… it sits right between Celery applications and all task producers. Among other things it enables you to trigger and monitor tasks via HTTP… so you can have R apps and Java apps…
  69. Consider the previous example.. The rocker launcher. In Java, you would have to do a POST request to this URL, and pass a JSON array with the task arguments.
  70. Summarizing... Together, Celery and flower, enables us to have FINE CONTROL…
  71. They also give us a …..
  72. We also get a…
  73. We get…
  74. Last but not least, we get off the shelf…
  75. Now a concrete use case for Celery and Flower in iHub. Say you have a UI, and this UI needs to display a large list of something, and say it takes time to create every item that will be shown on the list.
  76. In a simple implementation the user would be shown a loading gif. Then 20 or 30 secs later, after the entire list is processed, the list would appear on screen. ALL AT ONCE. Depending on how long it takes to process the entire list, this behaviour may be undesirable.
  77. Task queues solve this problems because they enable you to split the list in chunks Submit the chunks to workers for asynchronous processing, And have workers submit the results to the UI as they become available SO NOT ALL AT ONCE.
  78. Another use case for Celery and flower are asynchronous UI-triggered tasks.
  79. The use case is as follows. You have a typical UI-server interaction, where the UI request something from tomcat and tomcat replies.
  80. But sometimes you want to do something or produce something as a result of this interaction, but YOU DON’T WANT TO KEEP THE UI WAITING. So tomcat can simply trigger and task (asynchronously), forget about it, and let the UI continue executing.
  81. Examples of such tasks include…
  82. The nice thing about flower is that turning a synch task into an asynch one is as simples changing,…
  83. Yet another use case. Let us say you want to schedule a background task from a custom UI. At the moment we’re using Airflow, but let us say you really want a custom UI.
  84. In this case you’d do the same thing. You would create a task in some background pool.
  85. Then you would create another task, for scheduling purposes, that looks like this one…
  86. Finally, you would make the UI post to flower to trigger schedule_task with the desired schedule. In this case, every Monday 7:30 am…. That’s it.
  87. Now if you’re worried that Celery and Flower are some sort of exotic tools no body uses, then you can rest in peace Celery is an active open source project, and so there’s a community contributing regularly to it.
  88. On the same topic. Celery is being used by companies such as Instagram and Blackduck Vancouver!
  89. If you’re interested take a look at Instagram’s case. Apparently every time somebody posts a photo on Instagram, there are Celery workers putting those photos into followers’ feeds.
  90. The case against fork….If after this explanation you’re still thinking… WELL I COULD JUST…. . That means you haven’t listened. So I have one closing argument for you….
  91. I actually have no argument… just look at the picture.
  92. The case against threads from Tomcat…. If you’re still thinking, but I could just... I also have one closing argument for you….
  93. Again no argument…. (What’s wrong with ad-hoc threading? We don’t have control over resources used by those threads) (There’s no central monitoring either)
  94. Disclaimer…
  95. For instance….
  96. Indeed there’s work to do, but the important part to remember is…
  97. Like in everything, there’s some drawbacks to using Celery and Flower. Namely, there’s a
  98. In an attempt to solve this, I’ve added some tutorials on confluence…but still you need to read them, and they are in progress. (ASK NATHAN/LEANDRO HOW DIFFICULT THEY ARE TO FOLLOW… RAY ASK TOO)
  99. Second, deployment is now more complex. For one thing, it is no longer a matter of copy pasting a WAR file.
  100. Also, there’s a mismatch between our backend deployment servers and the laptops where we develop.
  101. This results in a) …