SlideShare une entreprise Scribd logo
1  sur  43
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

CICD using jenkins and Nomad
CICD using jenkins and NomadCICD using jenkins and Nomad
CICD using jenkins and NomadBram 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
 
Steamlining your puppet development workflow
Steamlining your puppet development workflowSteamlining your puppet development workflow
Steamlining your puppet development workflowTomas Doran
 
Rex - Lightning Talk yapc.eu 2013
Rex - Lightning Talk yapc.eu 2013Rex - Lightning Talk yapc.eu 2013
Rex - Lightning Talk yapc.eu 2013Jan 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 @ BrnoVaclav 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.0Yogi 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 2014Derek 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
 
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
 
Rethinking the debugger
Rethinking the debuggerRethinking the debugger
Rethinking the debuggerIulian Dragos
 
Building Docker Containers @ Scale
Building Docker Containers @ ScaleBuilding Docker Containers @ Scale
Building Docker Containers @ Scalelxfontes
 

Tendances (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
 

Similaire à 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 LearnedTim Callaghan
 
Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pieTomas Doran
 
mobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxmobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxNgLQun
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage SystemsSATOSHI TAGOMORI
 
John adams talk cloudy
John adams   talk cloudyJohn adams   talk cloudy
John adams talk cloudyJohn Adams
 
Tips For Maintaining OSS Projects
Tips For Maintaining OSS ProjectsTips For Maintaining OSS Projects
Tips For Maintaining OSS ProjectsTaro 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
 
Tupperware: Containerized Deployment at FB
Tupperware: Containerized Deployment at FBTupperware: Containerized Deployment at FB
Tupperware: Containerized Deployment at FBDocker, Inc.
 
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 QueueRichard Leland
 
Docker and Puppet for Continuous Integration
Docker and Puppet for Continuous IntegrationDocker and Puppet for Continuous Integration
Docker and Puppet for Continuous IntegrationGiacomo Vacca
 
Introduction to jenkins
Introduction to jenkinsIntroduction to jenkins
Introduction to jenkinsAbe 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-2015Pavel 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
 

Similaire à 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 ...
 

Dernier

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Dernier (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

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