SlideShare a Scribd company logo
2021/10/02 PyCon Taiwan
Queick: A Simple Job Queue
System for Python
Ryota SUENAGA
1
Me
• Ryota SUENAGA a.k.a asmsuechan

• A new grad software developer living in Tokyo, Japan

• Working for M3, Inc.

• Like: markdown

• Former commiter of a markdown editor
(Boostnote)

• Creator of a simple markdown parser, minute

• 实际上,我会说一点儿中文
2
0. Background story
3
0.1 Background story
My prof: “Could you please make entry/exit management system for our lab?”

Me: “Yes, sir”
Someday when I was a master’s student (1 year ago)
~2 days later~
Me: “OK, it’s done. The system status is all-green”
4
0.2 Background story
This system consists of Raspberry Pi, PaSori RC-S380 NFC Card Scanner, a speaker, Slack
The entrance and exit time is posted on our Slack channel
5
0.3 Background story
The system was working fine for a few days…
But some troubles were discovered
• Network connection was not good every few hours

• I should use a job-queue system to retry

• But using Redis is too much for other students…
So, I created an easy one!
6
1. Overview
7
1.1 What I did
I developed a job-queue system in Python
Its concept is “Deadly Simple.”
8
1.2 Job-queue system?
• Main task: Deligating jobs to another process

• e.g: image processing, sending e-mails, uploading files
Worker process
Queue
Application
enqueue a job
take out the job
enqueue success
Executing…
time↓
9
1.3 Queick
• Light and simple job-queue system

• Only Python standard libraries

• Thread-based programming
https://github.com/asmsuechan/queick
10
1.4 Queick
2 jobs that only print a text with sleep are enqueued
11
• Asynchronous execution

• Periodic execution

• Be able to specify exact time

• Scheduling execution

• Retry
1.5 Queick’s features and characteristics
• No Redis (stored in-memory) and no persistence

• Built by only Python standard libraries

• Failed job retry when network connection returns
• Thread based job execution
Features
Characteristics
12
1.6 Queick usage
enqueue(), enqueue_at()
cron()
These interfaces are implemented based on RQ
13
• time

• argparse

• importlib

• traceback

• logging

• random

• concurrent.futures
• types

1.7 Standard libraries used in Queick
• typing

• socket

• pickle

• multiprocessing
• os

• sched
• sys

• unittest
14
2. General job-queue system
15
2.1 General purpose to use job-queue system
1. Asynchronous job execution for a heavy task

• Background processing

2. Scheduling
• job management

• e.g. running a function every 1 minute
16
2.2 How to realize them easily in Python
↑Job side (application)
←Job manager (ran as another process)
17
2.3 GIL (Global Interpretor Lock)
• GIL prevents multiple threads working simultaneously

• multi-threads programming in Python don’t work intuitively

• CPU cannot utilize multi cores

• Processing CPU-bounded tasks are not suitable

• Only CPython
A. Because Queick’s concept is “Deadly Simple”.
Q. “Why did you choose multi-thread?”
18
2.4 Why Job-queue is needed
• Abstraction thread and queue

• We can be freed from multi-thread programming and queue management

• Job management

• Jobs can be easily managed if UI is implemented
asynchrounos execution and scheduling is possible 

without any job-queue systems technically. So why?
Main points
19
2.5 Base implementation of a Job-queue system
Very simple example
• Multi-Thread

• Queue
simple-job-queue-example.py 20
2.6 Examples
rq/rq ⭐7.9K
celery/celery ⭐17.9K
coleifer/huey ⭐3.6k
21
2.7 RQ quick introduction
• RQ is Redis Queue

• ⭐8K

• Queick is affected by RQ because I like RQ’s interface and its simpleness
RQ (Redis Queue) is a simple Python library for queueing jobs and
processing them in the background with workers.
22
2.8 RQ API
• Very simple
• enqueue
• enqueue_at
• enqueue_in
23
2.9 RQ architecture
RQ Architecture
Application
• Job is executed on a child process

• Scheduler runs as another process

• Job retry is ran on the scheduler
Scheduler process
Worker process
Child process
fork()
fork()
Child process
RQ
Retry when failed
Check Queue every 1 sec
subscribe
enqueue
JobRegistry
redis
24
2.10 For more information
• RQ: Simple job queues for Python (https://python-rq.org/)

• rq/rq (https://github.com/rq/rq)

• Full Stack Python (https://www.fullstackpython.com/task-queues.html)

• Introducing RQ (https://nvie.com/posts/introducing-rq/)
25
3. Queick architecture deep dive
26
3.1 Job data structure
• Dictionary

• function name, retry flag, and other options
27
3.2 Finding a job
• importlib

• This method imports a module dinamically from its name.
28
3.3 Architecture and its internal structure
Application
29
3.3 Architecture and its internal structure
Job
30
3.3 Architecture and its internal structure
Job
31
3.4 Network connection check
Retry when returning to online
• Network connection check by another process

• Check connection every 1 sec

• Enqueue all when the state changes disconnected

to connected
Failed JobQueue
Worker process
Network Checker
Run
Thread
Failed retry_on_network_availabe == True
TCP Server
JobQueue
Queick
32
3.4 Network connection check
Retry when returning to online
Failed JobQueue
Worker process
Network Checker
Run
Thread
Failed retry_on_network_availabe == True
TCP Server
JobQueue
Queick
Application
• Network connection check by another process

• Check connection every 1 sec

• Enqueue all when the state changes disconnected

to connected
33
3.4 Network connection check
Retry when returning to online
Failed JobQueue
Worker process
Network Checker
Run
Thread
Failed retry_on_network_availabe == True
TCP Server
JobQueue
Queick
Execution
• Network connection check by another process

• Check connection every 1 sec

• Enqueue all when the state changes disconnected

to connected
34
3.4 Network connection check
Retry when returning to online
Failed JobQueue
Worker process
Network Checker
Run
Thread
Failed retry_on_network_availabe == True
TCP Server
JobQueue
Queick
Execution
• Network connection check by another process

• Check connection every 1 sec

• Enqueue all when the state changes disconnected

to connected
35
3.4 Network connection check
Retry when returning to online
Failed JobQueue
Worker process
Network Checker
Run
Thread
Failed retry_on_network_availabe == True
TCP Server
JobQueue
Queick
• Network connection check by another process

• Check connection every 1 sec

• Enqueue all when the state changes disconnected

to connected
36
3.5 Testing
Ofcourse Queick has unit tests by unittest

But testing for multi-thread programming is difficult…
Integration tests are used to assure if Queick works as expected
37
3.5 Testing
How I implement integration tests?
Integration tests inside a Docker image of Queick
Executing a procedure of “writing a line to a file” on Queick
Confirm if the file has a correct content
Job
Write “a”
Write “b”
a

b
38
4. Demonstration
39
If time is left enough
5. Summary and conclusion
40
5.1 OSS development
• In OSS development, “Spped” is justice

• “Done is better than perfect”, especially in indivisual development

• human being is lazy animal

• Intensive development until the first release

• Publishing a blog entry and posting to Reddit are effective to reach first users

• OSS activiteis include information trasmission
41
5.2 Summary / Conclusion
• Queick is a “Deadly Simple” job-queue system

• Thread based job-queue system

• built by only standard libraries

• More application examples are needed

• Building a software by only standard libraries is a lot of fun
• “Queick” comes from Queue + Quick

• The core of Queick was made in 2 days, yes, my developing speed was
quick, therefore, queick.
42
Thank you for listening!
Any questions?
43

More Related Content

What's hot

CICD using jenkins and Nomad
CICD using jenkins and NomadCICD using jenkins and Nomad
CICD using jenkins and Nomad
Bram Vogelaar
 
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Codemotion
 
OpenWhisk Go Runtime
OpenWhisk Go RuntimeOpenWhisk Go Runtime
OpenWhisk Go Runtime
Michele Sciabarrà
 
Steamlining your puppet development workflow
Steamlining your puppet development workflowSteamlining your puppet development workflow
Steamlining your puppet development workflow
Tomas Doran
 
Rex - Lightning Talk yapc.eu 2013
Rex - Lightning Talk yapc.eu 2013Rex - Lightning Talk yapc.eu 2013
Rex - Lightning Talk yapc.eu 2013
Jan Gehring
 
Jenkins-Koji plugin presentation on Python & Ruby devel group @ Brno
Jenkins-Koji plugin presentation on Python & Ruby devel group @ BrnoJenkins-Koji plugin presentation on Python & Ruby devel group @ Brno
Jenkins-Koji plugin presentation on Python & Ruby devel group @ Brno
Vaclav Tunka
 
Ceylon From Here to Infinity: The Big Picture and What's Coming
Ceylon From Here to Infinity: The Big Picture and What's Coming Ceylon From Here to Infinity: The Big Picture and What's Coming
Ceylon From Here to Infinity: The Big Picture and What's Coming
Virtual JBoss User Group
 
Puppet Camp Berlin 2015: Andrea Giardini | Configuration Management @ CERN: G...
Puppet Camp Berlin 2015: Andrea Giardini | Configuration Management @ CERN: G...Puppet Camp Berlin 2015: Andrea Giardini | Configuration Management @ CERN: G...
Puppet Camp Berlin 2015: Andrea Giardini | Configuration Management @ CERN: G...
NETWAYS
 
Perfomance tuning on Go 2.0
Perfomance tuning on Go 2.0Perfomance tuning on Go 2.0
Perfomance tuning on Go 2.0
Yogi Kulkarni
 
High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014
Derek Collison
 
Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...
Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...
Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...
Codemotion
 
Rsyslog version naming (v8.6.0+)
Rsyslog version naming (v8.6.0+)Rsyslog version naming (v8.6.0+)
Rsyslog version naming (v8.6.0+)
Rainer Gerhards
 
Travis CI
Travis CITravis CI
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
tdc-globalcode
 
rsyslog meets docker
rsyslog meets dockerrsyslog meets docker
rsyslog meets docker
Rainer Gerhards
 
Juc boston2014.pptx
Juc boston2014.pptxJuc boston2014.pptx
Juc boston2014.pptx
Brandon Mueller
 
About Clack
About ClackAbout Clack
About Clack
fukamachi
 
Rethinking the debugger
Rethinking the debuggerRethinking the debugger
Rethinking the debugger
Iulian Dragos
 
Ratpack JVM_MX Meetup February 2016
Ratpack JVM_MX Meetup February 2016Ratpack JVM_MX Meetup February 2016
Ratpack JVM_MX Meetup February 2016
Domingo Suarez Torres
 
Building Docker Containers @ Scale
Building Docker Containers @ ScaleBuilding Docker Containers @ Scale
Building Docker Containers @ Scale
lxfontes
 

What's hot (20)

CICD using jenkins and Nomad
CICD using jenkins and NomadCICD using jenkins and Nomad
CICD using jenkins and Nomad
 
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
 
OpenWhisk Go Runtime
OpenWhisk Go RuntimeOpenWhisk Go Runtime
OpenWhisk Go Runtime
 
Steamlining your puppet development workflow
Steamlining your puppet development workflowSteamlining your puppet development workflow
Steamlining your puppet development workflow
 
Rex - Lightning Talk yapc.eu 2013
Rex - Lightning Talk yapc.eu 2013Rex - Lightning Talk yapc.eu 2013
Rex - Lightning Talk yapc.eu 2013
 
Jenkins-Koji plugin presentation on Python & Ruby devel group @ Brno
Jenkins-Koji plugin presentation on Python & Ruby devel group @ BrnoJenkins-Koji plugin presentation on Python & Ruby devel group @ Brno
Jenkins-Koji plugin presentation on Python & Ruby devel group @ Brno
 
Ceylon From Here to Infinity: The Big Picture and What's Coming
Ceylon From Here to Infinity: The Big Picture and What's Coming Ceylon From Here to Infinity: The Big Picture and What's Coming
Ceylon From Here to Infinity: The Big Picture and What's Coming
 
Puppet Camp Berlin 2015: Andrea Giardini | Configuration Management @ CERN: G...
Puppet Camp Berlin 2015: Andrea Giardini | Configuration Management @ CERN: G...Puppet Camp Berlin 2015: Andrea Giardini | Configuration Management @ CERN: G...
Puppet Camp Berlin 2015: Andrea Giardini | Configuration Management @ CERN: G...
 
Perfomance tuning on Go 2.0
Perfomance tuning on Go 2.0Perfomance tuning on Go 2.0
Perfomance tuning on Go 2.0
 
High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014
 
Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...
Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...
Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...
 
Rsyslog version naming (v8.6.0+)
Rsyslog version naming (v8.6.0+)Rsyslog version naming (v8.6.0+)
Rsyslog version naming (v8.6.0+)
 
Travis CI
Travis CITravis CI
Travis CI
 
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
 
rsyslog meets docker
rsyslog meets dockerrsyslog meets docker
rsyslog meets docker
 
Juc boston2014.pptx
Juc boston2014.pptxJuc boston2014.pptx
Juc boston2014.pptx
 
About Clack
About ClackAbout Clack
About Clack
 
Rethinking the debugger
Rethinking the debuggerRethinking the debugger
Rethinking the debugger
 
Ratpack JVM_MX Meetup February 2016
Ratpack JVM_MX Meetup February 2016Ratpack JVM_MX Meetup February 2016
Ratpack JVM_MX Meetup February 2016
 
Building Docker Containers @ Scale
Building Docker Containers @ ScaleBuilding Docker Containers @ Scale
Building Docker Containers @ Scale
 

Similar to Queick: A Simple Job Queue System for Python

Puppet Camp New York 2014: Streamlining Puppet Development Workflow
Puppet Camp New York 2014: Streamlining Puppet Development Workflow Puppet Camp New York 2014: Streamlining Puppet Development Workflow
Puppet Camp New York 2014: Streamlining Puppet Development Workflow
Puppet
 
Performance Benchmarking: Tips, Tricks, and Lessons Learned
Performance Benchmarking: Tips, Tricks, and Lessons LearnedPerformance Benchmarking: Tips, Tricks, and Lessons Learned
Performance Benchmarking: Tips, Tricks, and Lessons Learned
Tim Callaghan
 
Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pie
Tomas Doran
 
How we use Twisted in Launchpad
How we use Twisted in LaunchpadHow we use Twisted in Launchpad
How we use Twisted in Launchpad
Michael Hudson-Doyle
 
mobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxmobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptx
NgLQun
 
Rex gke-clustree
Rex gke-clustreeRex gke-clustree
Rex gke-clustree
Romain Vrignaud
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage Systems
SATOSHI TAGOMORI
 
John adams talk cloudy
John adams   talk cloudyJohn adams   talk cloudy
John adams talk cloudy
John Adams
 
Tips For Maintaining OSS Projects
Tips For Maintaining OSS ProjectsTips For Maintaining OSS Projects
Tips For Maintaining OSS Projects
Taro L. Saito
 
Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?
GetInData
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
Thomas Hunter II
 
Tupperware: Containerized Deployment at FB
Tupperware: Containerized Deployment at FBTupperware: Containerized Deployment at FB
Tupperware: Containerized Deployment at FB
Docker, Inc.
 
Why Play Framework is fast
Why Play Framework is fastWhy Play Framework is fast
Why Play Framework is fast
Legacy Typesafe (now Lightbend)
 
Creating basic workflows as Jupyter Notebooks to use Cytoscape programmatically.
Creating basic workflows as Jupyter Notebooks to use Cytoscape programmatically.Creating basic workflows as Jupyter Notebooks to use Cytoscape programmatically.
Creating basic workflows as Jupyter Notebooks to use Cytoscape programmatically.
Hakky St
 
Celery: The Distributed Task Queue
Celery: The Distributed Task QueueCelery: The Distributed Task Queue
Celery: The Distributed Task Queue
Richard Leland
 
Docker and Puppet for Continuous Integration
Docker and Puppet for Continuous IntegrationDocker and Puppet for Continuous Integration
Docker and Puppet for Continuous Integration
Giacomo Vacca
 
Nautilus
NautilusNautilus
Nautilus
INRIA-OAK
 
Introduction to jenkins
Introduction to jenkinsIntroduction to jenkins
Introduction to jenkins
Abe Diaz
 
Ansible benelux meetup - Amsterdam 27-5-2015
Ansible benelux meetup - Amsterdam 27-5-2015Ansible benelux meetup - Amsterdam 27-5-2015
Ansible benelux meetup - Amsterdam 27-5-2015
Pavel Chunyayev
 
DevSecCon London 2017: Permitting agility whilst enforcing security by Alina ...
DevSecCon London 2017: Permitting agility whilst enforcing security by Alina ...DevSecCon London 2017: Permitting agility whilst enforcing security by Alina ...
DevSecCon London 2017: Permitting agility whilst enforcing security by Alina ...
DevSecCon
 

Similar to Queick: A Simple Job Queue System for Python (20)

Puppet Camp New York 2014: Streamlining Puppet Development Workflow
Puppet Camp New York 2014: Streamlining Puppet Development Workflow Puppet Camp New York 2014: Streamlining Puppet Development Workflow
Puppet Camp New York 2014: Streamlining Puppet Development Workflow
 
Performance Benchmarking: Tips, Tricks, and Lessons Learned
Performance Benchmarking: Tips, Tricks, and Lessons LearnedPerformance Benchmarking: Tips, Tricks, and Lessons Learned
Performance Benchmarking: Tips, Tricks, and Lessons Learned
 
Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pie
 
How we use Twisted in Launchpad
How we use Twisted in LaunchpadHow we use Twisted in Launchpad
How we use Twisted in Launchpad
 
mobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxmobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptx
 
Rex gke-clustree
Rex gke-clustreeRex gke-clustree
Rex gke-clustree
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage Systems
 
John adams talk cloudy
John adams   talk cloudyJohn adams   talk cloudy
John adams talk cloudy
 
Tips For Maintaining OSS Projects
Tips For Maintaining OSS ProjectsTips For Maintaining OSS Projects
Tips For Maintaining OSS Projects
 
Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
 
Tupperware: Containerized Deployment at FB
Tupperware: Containerized Deployment at FBTupperware: Containerized Deployment at FB
Tupperware: Containerized Deployment at FB
 
Why Play Framework is fast
Why Play Framework is fastWhy Play Framework is fast
Why Play Framework is fast
 
Creating basic workflows as Jupyter Notebooks to use Cytoscape programmatically.
Creating basic workflows as Jupyter Notebooks to use Cytoscape programmatically.Creating basic workflows as Jupyter Notebooks to use Cytoscape programmatically.
Creating basic workflows as Jupyter Notebooks to use Cytoscape programmatically.
 
Celery: The Distributed Task Queue
Celery: The Distributed Task QueueCelery: The Distributed Task Queue
Celery: The Distributed Task Queue
 
Docker and Puppet for Continuous Integration
Docker and Puppet for Continuous IntegrationDocker and Puppet for Continuous Integration
Docker and Puppet for Continuous Integration
 
Nautilus
NautilusNautilus
Nautilus
 
Introduction to jenkins
Introduction to jenkinsIntroduction to jenkins
Introduction to jenkins
 
Ansible benelux meetup - Amsterdam 27-5-2015
Ansible benelux meetup - Amsterdam 27-5-2015Ansible benelux meetup - Amsterdam 27-5-2015
Ansible benelux meetup - Amsterdam 27-5-2015
 
DevSecCon London 2017: Permitting agility whilst enforcing security by Alina ...
DevSecCon London 2017: Permitting agility whilst enforcing security by Alina ...DevSecCon London 2017: Permitting agility whilst enforcing security by Alina ...
DevSecCon London 2017: Permitting agility whilst enforcing security by Alina ...
 

Recently uploaded

Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
Fwdays
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
christinelarrosa
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
DanBrown980551
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
UiPathCommunity
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
Enterprise Knowledge
 

Recently uploaded (20)

Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
 

Queick: A Simple Job Queue System for Python

  • 1. 2021/10/02 PyCon Taiwan Queick: A Simple Job Queue System for Python Ryota SUENAGA 1
  • 2. Me • Ryota SUENAGA a.k.a asmsuechan • A new grad software developer living in Tokyo, Japan • Working for M3, Inc. • Like: markdown • Former commiter of a markdown editor (Boostnote) • Creator of a simple markdown parser, minute • 实际上,我会说一点儿中文 2
  • 4. 0.1 Background story My prof: “Could you please make entry/exit management system for our lab?” Me: “Yes, sir” Someday when I was a master’s student (1 year ago) ~2 days later~ Me: “OK, it’s done. The system status is all-green” 4
  • 5. 0.2 Background story This system consists of Raspberry Pi, PaSori RC-S380 NFC Card Scanner, a speaker, Slack The entrance and exit time is posted on our Slack channel 5
  • 6. 0.3 Background story The system was working fine for a few days… But some troubles were discovered • Network connection was not good every few hours • I should use a job-queue system to retry • But using Redis is too much for other students… So, I created an easy one! 6
  • 8. 1.1 What I did I developed a job-queue system in Python Its concept is “Deadly Simple.” 8
  • 9. 1.2 Job-queue system? • Main task: Deligating jobs to another process • e.g: image processing, sending e-mails, uploading files Worker process Queue Application enqueue a job take out the job enqueue success Executing… time↓ 9
  • 10. 1.3 Queick • Light and simple job-queue system • Only Python standard libraries • Thread-based programming https://github.com/asmsuechan/queick 10
  • 11. 1.4 Queick 2 jobs that only print a text with sleep are enqueued 11
  • 12. • Asynchronous execution • Periodic execution • Be able to specify exact time • Scheduling execution • Retry 1.5 Queick’s features and characteristics • No Redis (stored in-memory) and no persistence • Built by only Python standard libraries • Failed job retry when network connection returns • Thread based job execution Features Characteristics 12
  • 13. 1.6 Queick usage enqueue(), enqueue_at() cron() These interfaces are implemented based on RQ 13
  • 14. • time • argparse • importlib • traceback • logging • random • concurrent.futures • types 1.7 Standard libraries used in Queick • typing • socket • pickle • multiprocessing • os • sched • sys • unittest 14
  • 15. 2. General job-queue system 15
  • 16. 2.1 General purpose to use job-queue system 1. Asynchronous job execution for a heavy task • Background processing
 2. Scheduling • job management • e.g. running a function every 1 minute 16
  • 17. 2.2 How to realize them easily in Python ↑Job side (application) ←Job manager (ran as another process) 17
  • 18. 2.3 GIL (Global Interpretor Lock) • GIL prevents multiple threads working simultaneously • multi-threads programming in Python don’t work intuitively • CPU cannot utilize multi cores • Processing CPU-bounded tasks are not suitable • Only CPython A. Because Queick’s concept is “Deadly Simple”. Q. “Why did you choose multi-thread?” 18
  • 19. 2.4 Why Job-queue is needed • Abstraction thread and queue • We can be freed from multi-thread programming and queue management • Job management • Jobs can be easily managed if UI is implemented asynchrounos execution and scheduling is possible without any job-queue systems technically. So why? Main points 19
  • 20. 2.5 Base implementation of a Job-queue system Very simple example • Multi-Thread • Queue simple-job-queue-example.py 20
  • 21. 2.6 Examples rq/rq ⭐7.9K celery/celery ⭐17.9K coleifer/huey ⭐3.6k 21
  • 22. 2.7 RQ quick introduction • RQ is Redis Queue • ⭐8K • Queick is affected by RQ because I like RQ’s interface and its simpleness RQ (Redis Queue) is a simple Python library for queueing jobs and processing them in the background with workers. 22
  • 23. 2.8 RQ API • Very simple • enqueue • enqueue_at • enqueue_in 23
  • 24. 2.9 RQ architecture RQ Architecture Application • Job is executed on a child process • Scheduler runs as another process • Job retry is ran on the scheduler Scheduler process Worker process Child process fork() fork() Child process RQ Retry when failed Check Queue every 1 sec subscribe enqueue JobRegistry redis 24
  • 25. 2.10 For more information • RQ: Simple job queues for Python (https://python-rq.org/) • rq/rq (https://github.com/rq/rq) • Full Stack Python (https://www.fullstackpython.com/task-queues.html) • Introducing RQ (https://nvie.com/posts/introducing-rq/) 25
  • 26. 3. Queick architecture deep dive 26
  • 27. 3.1 Job data structure • Dictionary • function name, retry flag, and other options 27
  • 28. 3.2 Finding a job • importlib • This method imports a module dinamically from its name. 28
  • 29. 3.3 Architecture and its internal structure Application 29
  • 30. 3.3 Architecture and its internal structure Job 30
  • 31. 3.3 Architecture and its internal structure Job 31
  • 32. 3.4 Network connection check Retry when returning to online • Network connection check by another process • Check connection every 1 sec • Enqueue all when the state changes disconnected
 to connected Failed JobQueue Worker process Network Checker Run Thread Failed retry_on_network_availabe == True TCP Server JobQueue Queick 32
  • 33. 3.4 Network connection check Retry when returning to online Failed JobQueue Worker process Network Checker Run Thread Failed retry_on_network_availabe == True TCP Server JobQueue Queick Application • Network connection check by another process • Check connection every 1 sec • Enqueue all when the state changes disconnected
 to connected 33
  • 34. 3.4 Network connection check Retry when returning to online Failed JobQueue Worker process Network Checker Run Thread Failed retry_on_network_availabe == True TCP Server JobQueue Queick Execution • Network connection check by another process • Check connection every 1 sec • Enqueue all when the state changes disconnected
 to connected 34
  • 35. 3.4 Network connection check Retry when returning to online Failed JobQueue Worker process Network Checker Run Thread Failed retry_on_network_availabe == True TCP Server JobQueue Queick Execution • Network connection check by another process • Check connection every 1 sec • Enqueue all when the state changes disconnected
 to connected 35
  • 36. 3.4 Network connection check Retry when returning to online Failed JobQueue Worker process Network Checker Run Thread Failed retry_on_network_availabe == True TCP Server JobQueue Queick • Network connection check by another process • Check connection every 1 sec • Enqueue all when the state changes disconnected
 to connected 36
  • 37. 3.5 Testing Ofcourse Queick has unit tests by unittest But testing for multi-thread programming is difficult… Integration tests are used to assure if Queick works as expected 37
  • 38. 3.5 Testing How I implement integration tests? Integration tests inside a Docker image of Queick Executing a procedure of “writing a line to a file” on Queick Confirm if the file has a correct content Job Write “a” Write “b” a b 38
  • 39. 4. Demonstration 39 If time is left enough
  • 40. 5. Summary and conclusion 40
  • 41. 5.1 OSS development • In OSS development, “Spped” is justice • “Done is better than perfect”, especially in indivisual development • human being is lazy animal • Intensive development until the first release • Publishing a blog entry and posting to Reddit are effective to reach first users • OSS activiteis include information trasmission 41
  • 42. 5.2 Summary / Conclusion • Queick is a “Deadly Simple” job-queue system • Thread based job-queue system • built by only standard libraries • More application examples are needed • Building a software by only standard libraries is a lot of fun • “Queick” comes from Queue + Quick • The core of Queick was made in 2 days, yes, my developing speed was quick, therefore, queick. 42
  • 43. Thank you for listening! Any questions? 43