SlideShare a Scribd company logo
Concurrency
 & Gevent
Scaling Real World Applications
Concurrency
handling a number of things at the same time




Examples: (Incoming) WebServers, Database Servers
         (Outgoing) SSH Mux
SSH Mux

●
    Execute a command on a remote
    SSH server
●
    Handle concurrent SSH Clients
●
    Command execution time varies
    from seconds to days
●
    Command execution happens on
    remote servers, SSH mux is I/O
    bound
SSH Client


1. Init session

2. Authenticate

3. Get a channel

4. Issue command

5. Read output
Need Concurrency?
●
    Process blocks on read()
●
    No new connections can be inititated
●
    Need ability to handle multiple clients at the same
    time
Multiprocessing
●
    One process is the master
●
    Master can spawn workers
●
    Each worker handles one request at a time
●
    Pre-forked pool of workers
Concurrent SSH Clients
SSH Mux Memory Usage

                                              ssh mux memory usage

               600


               500


               400
 Memory (MB)




               300                                                                     Processes


               200


               100


                0
                     0   5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100
                                            # Concurrent Reqs
SSH Mux Performace

                                     ssh mux performance sheet

          160

          140

          120

          100
Time(s)




          80                                                                           Processes

          60

          40

          20

           0
                20   40   80   150   200     400     800   1200   1500   1800   2100
                                     # Concurrent Reqs
Multiprocessing yay

●
    Easy to get started
●
    OS guaranteed process isolation & fairness
●
    Covers up for misbehaving workers
●
    Add more concurrency by adding more workers
●
    Convenient when numbers are smaller numbers
Multiprocessing nay
●
    Concurrency limited by number of processes
●
    Memory heavy
●
    Implicit scheduling
●
    Synchronization is not trivial
More Concurrency?

●
    Command execution is happening on remote servers, we
    are mostly blocked on I/O




●
    Handle multiple I/O in a single process?
Gevent
gevent is a coroutine-based Python networking library that
 uses greenlet to provide a high-level synchronous API on
             top of the libevent event loop.
Greenlets
●
    Lightweight 'threads' - not OS threads
●
    Explicit scheduling - Cooperative
●
    Minimal stack
●
    Application decides execution flow
●
    Easy to synchronize/ Avoid locks
●
    All run inside one process
Libevent
●
    Use fastest mechanism to poll (portable)
●
    Fast Event loop
●
    In Gevent, event loop runs in a greenlet (event hub)
●
    Instead of blocking, greenlets switch to event hub
●
    It's all done behind the scene
Monkey Patching

Monkey patching
Modifies behaviour of blocking calls such as select, sleep to
non-blocking
Patches the python standard socket library
Gevent
●
    Greenlet 1 is running
●
    Greenlet 2 and 3 are ready
Gevent
●
    Greenlet 1 has to wait for read
●
    Greenlet 1 switches to Event hub
Gevent
●
    Event hub switches to Greenlet 3
Gevent
●
    Greenlet 2 runs
Gevent
●
    Greenlet 2 wants to sleep
●
    Greenlet 2 switches to Event hub
Gevent
●
    Greenlet 1 data has come, moved to ready state
●
    Eventhub switches to Greenlet 3
Gevent
●
    Greenlet 3 runs
Gevent
●
    When Greenlet 1 resumes, its from next instruction
●
    It's as if it were a blocking call
Green SSH Client


1. Init session

2. Authenticate

3. Get a channel

4. Issue command

5. Read output
A closer look
Going Concurrent




 Use pre-forked processes to use all cores
Memory usage
                                               ssh mux memory usage

             45

             40

             35

             30
Memory(MB)




             25
                                                                                    Gevent+Processes
             20

             15

             10

             5

             0
                  0   5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100

                                          # Concurrent Reqs
SSH Mux Performace
                                           ssh mux performace chart

           70


           60


           50


           40
 Time(s)




                                                                                     Gevent+Processes
           30


           20


           10


           0
                20   40   80   150   200     400   800   1200   1500   1800   2100
                                     # Concurrent Reqs
SSH Mux memory usage

                                              ssh mux memory usage

                600


                500


                400
   Memory(MB)




                                                                                        Processes
                300
                                                                                        Gevent

                200


                100


                 0
                      0   5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100
                                             # Concurrent Reqs
SSH Mux Performance
                                        ssh mux performance sheet

          160

          140

          120

          100
                                                                                       Processes
Time(s)




          80                                                                           Gevent+Processes

          60

          40

          20

           0
                20   40   80   150   200     400     800   1200   1500   1800   2100

                                     # Concurrent Reqs
Gevent yay!
●
    Untwist – write linear non blocking code
●
    Explicit scheduling, dictate the execution flow
●
    Timeouts
●
    Events, AsyncResults for Synchronization
●
    gevent.wsgi
●
    Pre-spawned pool of greenlets
Gevent beware of

●
    No multicore support
●
    Not great for CPU bound applications
●
    Third party libs must be green (non blocking)
●
    Misbehaving workers can be lethal
●
    No fairness when it comes to scheduling
Take Away
●
    Gevent lets you write asynchronous code in a
    synchronous manner
●
    No multicore support, still need multiprocessing
●
    Not so great for CPU bound applications
●
    Split your application into CPU bound and IO bound
    parts
●
    Be willing to contribute patches
●
    Code available at
    git@github.com:aaloksood/pyexamples.git
Thank you




            That's all folks!
Countdown Timer
●
    Count down from 200000000
●
    Split work among workers
Threads

                                 Multithreading wonder

            25


            20


            15
                                                                      1 Core
  Time(s)




                                                                      4 cores
            10


            5


            0
                 1   2   3   4     5           6   7     8   9   10
                                   # Workers
One core


                                    Execution time One Core

             14.5
              14
             13.5
              13                                                           Processes
                                                                           1 Core
  Time (s)




             12.5
                                                                           Gevent_1
              12                                                           Gevent_4
             11.5
              11
             10.5
                    1   2   3   4       5         6   7       8   9   10
                                      # Workers
Four cores


                                  Execution time 4 cores

             25


             20

                                                                        Process
             15
                                                                        Threads
   Time(s)




                                                                        Gevent_1
             10
                                                                        Gevent_4

             5


             0
                  1   2   3   4     5          6   7       8   9   10
                                   # Workers
Ad

More Related Content

What's hot (20)

Introduction to robot framework
Introduction to robot frameworkIntroduction to robot framework
Introduction to robot framework
Chonlasith Jucksriporn
 
programming with python ppt
programming with python pptprogramming with python ppt
programming with python ppt
Priyanka Pradhan
 
アプリ屋もDockerをドカドカ使おう ~ Docker入門
アプリ屋もDockerをドカドカ使おう ~ Docker入門アプリ屋もDockerをドカドカ使おう ~ Docker入門
アプリ屋もDockerをドカドカ使おう ~ Docker入門
Hori Tasuku
 
Git and git flow
Git and git flowGit and git flow
Git and git flow
Fran García
 
PowerShellでWebブラウザ(Selenium Webdriver)を動かした話
PowerShellでWebブラウザ(Selenium Webdriver)を動かした話PowerShellでWebブラウザ(Selenium Webdriver)を動かした話
PowerShellでWebブラウザ(Selenium Webdriver)を動かした話
洋史 東平
 
Agile\scrum: все что необходимо знать
Agile\scrum: все что необходимо знатьAgile\scrum: все что необходимо знать
Agile\scrum: все что необходимо знать
Yuri Navruzov
 
파이썬 TDD 101
파이썬 TDD 101파이썬 TDD 101
파이썬 TDD 101
정주 김
 
Docker 기반 개발환경 구축 - XE Open seminar #2
Docker 기반 개발환경 구축 - XE Open seminar #2Docker 기반 개발환경 구축 - XE Open seminar #2
Docker 기반 개발환경 구축 - XE Open seminar #2
XpressEngine
 
Git-flow workflow and pull-requests
Git-flow workflow and pull-requestsGit-flow workflow and pull-requests
Git-flow workflow and pull-requests
Bartosz Kosarzycki
 
Introducing GitLab (June 2018)
Introducing GitLab (June 2018)Introducing GitLab (June 2018)
Introducing GitLab (June 2018)
Noa Harel
 
Python ppt
Python pptPython ppt
Python ppt
Rohit Verma
 
python.ppt python python python python python
python.ppt python python python python pythonpython.ppt python python python python python
python.ppt python python python python python
ssuser5feb2c1
 
Git best practices workshop
Git best practices workshopGit best practices workshop
Git best practices workshop
Otto Kekäläinen
 
Python vs c++ ppt
Python vs c++ pptPython vs c++ ppt
Python vs c++ ppt
AllProgrammingHelp
 
新人Git/Github研修公開用スライド(その2)
新人Git/Github研修公開用スライド(その2)新人Git/Github研修公開用スライド(その2)
新人Git/Github研修公開用スライド(その2)
pupupopo88
 
【初心者向け】Go言語勉強会資料
 【初心者向け】Go言語勉強会資料 【初心者向け】Go言語勉強会資料
【初心者向け】Go言語勉強会資料
Yuji Otani
 
Git hub ppt presentation
Git hub ppt presentationGit hub ppt presentation
Git hub ppt presentation
AyanaRukasar
 
Git vs svn
Git vs svnGit vs svn
Git vs svn
Suman Mukherjee
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
atishgoswami
 
Linuxカーネル超入門
Linuxカーネル超入門Linuxカーネル超入門
Linuxカーネル超入門
Takashi Masuda
 
programming with python ppt
programming with python pptprogramming with python ppt
programming with python ppt
Priyanka Pradhan
 
アプリ屋もDockerをドカドカ使おう ~ Docker入門
アプリ屋もDockerをドカドカ使おう ~ Docker入門アプリ屋もDockerをドカドカ使おう ~ Docker入門
アプリ屋もDockerをドカドカ使おう ~ Docker入門
Hori Tasuku
 
PowerShellでWebブラウザ(Selenium Webdriver)を動かした話
PowerShellでWebブラウザ(Selenium Webdriver)を動かした話PowerShellでWebブラウザ(Selenium Webdriver)を動かした話
PowerShellでWebブラウザ(Selenium Webdriver)を動かした話
洋史 東平
 
Agile\scrum: все что необходимо знать
Agile\scrum: все что необходимо знатьAgile\scrum: все что необходимо знать
Agile\scrum: все что необходимо знать
Yuri Navruzov
 
파이썬 TDD 101
파이썬 TDD 101파이썬 TDD 101
파이썬 TDD 101
정주 김
 
Docker 기반 개발환경 구축 - XE Open seminar #2
Docker 기반 개발환경 구축 - XE Open seminar #2Docker 기반 개발환경 구축 - XE Open seminar #2
Docker 기반 개발환경 구축 - XE Open seminar #2
XpressEngine
 
Git-flow workflow and pull-requests
Git-flow workflow and pull-requestsGit-flow workflow and pull-requests
Git-flow workflow and pull-requests
Bartosz Kosarzycki
 
Introducing GitLab (June 2018)
Introducing GitLab (June 2018)Introducing GitLab (June 2018)
Introducing GitLab (June 2018)
Noa Harel
 
python.ppt python python python python python
python.ppt python python python python pythonpython.ppt python python python python python
python.ppt python python python python python
ssuser5feb2c1
 
新人Git/Github研修公開用スライド(その2)
新人Git/Github研修公開用スライド(その2)新人Git/Github研修公開用スライド(その2)
新人Git/Github研修公開用スライド(その2)
pupupopo88
 
【初心者向け】Go言語勉強会資料
 【初心者向け】Go言語勉強会資料 【初心者向け】Go言語勉強会資料
【初心者向け】Go言語勉強会資料
Yuji Otani
 
Git hub ppt presentation
Git hub ppt presentationGit hub ppt presentation
Git hub ppt presentation
AyanaRukasar
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
atishgoswami
 
Linuxカーネル超入門
Linuxカーネル超入門Linuxカーネル超入門
Linuxカーネル超入門
Takashi Masuda
 

Similar to Scaling real world applications using gevent (20)

Scaling real world applications using gevent
Scaling real world applications using geventScaling real world applications using gevent
Scaling real world applications using gevent
aalokthemagnificient
 
It's all about the timing
It's all about the timingIt's all about the timing
It's all about the timing
SensePost
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
Marcus Frödin
 
Usenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyUsenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a Proxy
Leif Hedstrom
 
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance TuningPyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
Graham Dumpleton
 
Joomla! Day Deutschland 2012 - Active Security
Joomla! Day Deutschland 2012 - Active SecurityJoomla! Day Deutschland 2012 - Active Security
Joomla! Day Deutschland 2012 - Active Security
Nicholas Dionysopoulos
 
Getput suite
Getput suiteGetput suite
Getput suite
Iben Rodriguez
 
Microservices with Micronaut
Microservices with MicronautMicroservices with Micronaut
Microservices with Micronaut
QAware GmbH
 
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
Puppet
 
ずばり動く!kumofs と ずばり動かないケース
ずばり動く!kumofs と ずばり動かないケースずばり動く!kumofs と ずばり動かないケース
ずばり動く!kumofs と ずばり動かないケース
Sadayuki Furuhashi
 
Analyze Virtual Machine Overhead Compared to Bare Metal with Tracing
Analyze Virtual Machine Overhead Compared to Bare Metal with TracingAnalyze Virtual Machine Overhead Compared to Bare Metal with Tracing
Analyze Virtual Machine Overhead Compared to Bare Metal with Tracing
ScyllaDB
 
Analyzing OS X Systems Performance with the USE Method
Analyzing OS X Systems Performance with the USE MethodAnalyzing OS X Systems Performance with the USE Method
Analyzing OS X Systems Performance with the USE Method
Brendan Gregg
 
Rails Performance
Rails PerformanceRails Performance
Rails Performance
Wen-Tien Chang
 
Performance tests with gatling
Performance tests with gatlingPerformance tests with gatling
Performance tests with gatling
SoftwareMill
 
分散Key-valueストアkumofsの思想と設計
分散Key-valueストアkumofsの思想と設計分散Key-valueストアkumofsの思想と設計
分散Key-valueストアkumofsの思想と設計
Sadayuki Furuhashi
 
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
Ji-Woong Choi
 
How NOT to write in Node.js
How NOT to write in Node.jsHow NOT to write in Node.js
How NOT to write in Node.js
Piotr Pelczar
 
SFO15-202: Towards Multi-Threaded Tiny Code Generator (TCG) in QEMU
SFO15-202: Towards Multi-Threaded Tiny Code Generator (TCG) in QEMUSFO15-202: Towards Multi-Threaded Tiny Code Generator (TCG) in QEMU
SFO15-202: Towards Multi-Threaded Tiny Code Generator (TCG) in QEMU
Linaro
 
Scaling sql server 2014 parallel insert
Scaling sql server 2014 parallel insertScaling sql server 2014 parallel insert
Scaling sql server 2014 parallel insert
Chris Adkin
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
Tom Croucher
 
Scaling real world applications using gevent
Scaling real world applications using geventScaling real world applications using gevent
Scaling real world applications using gevent
aalokthemagnificient
 
It's all about the timing
It's all about the timingIt's all about the timing
It's all about the timing
SensePost
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
Marcus Frödin
 
Usenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyUsenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a Proxy
Leif Hedstrom
 
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance TuningPyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
Graham Dumpleton
 
Joomla! Day Deutschland 2012 - Active Security
Joomla! Day Deutschland 2012 - Active SecurityJoomla! Day Deutschland 2012 - Active Security
Joomla! Day Deutschland 2012 - Active Security
Nicholas Dionysopoulos
 
Microservices with Micronaut
Microservices with MicronautMicroservices with Micronaut
Microservices with Micronaut
QAware GmbH
 
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
Puppet
 
ずばり動く!kumofs と ずばり動かないケース
ずばり動く!kumofs と ずばり動かないケースずばり動く!kumofs と ずばり動かないケース
ずばり動く!kumofs と ずばり動かないケース
Sadayuki Furuhashi
 
Analyze Virtual Machine Overhead Compared to Bare Metal with Tracing
Analyze Virtual Machine Overhead Compared to Bare Metal with TracingAnalyze Virtual Machine Overhead Compared to Bare Metal with Tracing
Analyze Virtual Machine Overhead Compared to Bare Metal with Tracing
ScyllaDB
 
Analyzing OS X Systems Performance with the USE Method
Analyzing OS X Systems Performance with the USE MethodAnalyzing OS X Systems Performance with the USE Method
Analyzing OS X Systems Performance with the USE Method
Brendan Gregg
 
Performance tests with gatling
Performance tests with gatlingPerformance tests with gatling
Performance tests with gatling
SoftwareMill
 
分散Key-valueストアkumofsの思想と設計
分散Key-valueストアkumofsの思想と設計分散Key-valueストアkumofsの思想と設計
分散Key-valueストアkumofsの思想と設計
Sadayuki Furuhashi
 
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
Ji-Woong Choi
 
How NOT to write in Node.js
How NOT to write in Node.jsHow NOT to write in Node.js
How NOT to write in Node.js
Piotr Pelczar
 
SFO15-202: Towards Multi-Threaded Tiny Code Generator (TCG) in QEMU
SFO15-202: Towards Multi-Threaded Tiny Code Generator (TCG) in QEMUSFO15-202: Towards Multi-Threaded Tiny Code Generator (TCG) in QEMU
SFO15-202: Towards Multi-Threaded Tiny Code Generator (TCG) in QEMU
Linaro
 
Scaling sql server 2014 parallel insert
Scaling sql server 2014 parallel insertScaling sql server 2014 parallel insert
Scaling sql server 2014 parallel insert
Chris Adkin
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
Tom Croucher
 
Ad

Recently uploaded (20)

What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Ad

Scaling real world applications using gevent

  • 1. Concurrency & Gevent Scaling Real World Applications
  • 2. Concurrency handling a number of things at the same time Examples: (Incoming) WebServers, Database Servers (Outgoing) SSH Mux
  • 3. SSH Mux ● Execute a command on a remote SSH server ● Handle concurrent SSH Clients ● Command execution time varies from seconds to days ● Command execution happens on remote servers, SSH mux is I/O bound
  • 4. SSH Client 1. Init session 2. Authenticate 3. Get a channel 4. Issue command 5. Read output
  • 5. Need Concurrency? ● Process blocks on read() ● No new connections can be inititated ● Need ability to handle multiple clients at the same time
  • 6. Multiprocessing ● One process is the master ● Master can spawn workers ● Each worker handles one request at a time ● Pre-forked pool of workers
  • 8. SSH Mux Memory Usage ssh mux memory usage 600 500 400 Memory (MB) 300 Processes 200 100 0 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 # Concurrent Reqs
  • 9. SSH Mux Performace ssh mux performance sheet 160 140 120 100 Time(s) 80 Processes 60 40 20 0 20 40 80 150 200 400 800 1200 1500 1800 2100 # Concurrent Reqs
  • 10. Multiprocessing yay ● Easy to get started ● OS guaranteed process isolation & fairness ● Covers up for misbehaving workers ● Add more concurrency by adding more workers ● Convenient when numbers are smaller numbers
  • 11. Multiprocessing nay ● Concurrency limited by number of processes ● Memory heavy ● Implicit scheduling ● Synchronization is not trivial
  • 12. More Concurrency? ● Command execution is happening on remote servers, we are mostly blocked on I/O ● Handle multiple I/O in a single process?
  • 13. Gevent gevent is a coroutine-based Python networking library that uses greenlet to provide a high-level synchronous API on top of the libevent event loop.
  • 14. Greenlets ● Lightweight 'threads' - not OS threads ● Explicit scheduling - Cooperative ● Minimal stack ● Application decides execution flow ● Easy to synchronize/ Avoid locks ● All run inside one process
  • 15. Libevent ● Use fastest mechanism to poll (portable) ● Fast Event loop ● In Gevent, event loop runs in a greenlet (event hub) ● Instead of blocking, greenlets switch to event hub ● It's all done behind the scene
  • 16. Monkey Patching Monkey patching Modifies behaviour of blocking calls such as select, sleep to non-blocking Patches the python standard socket library
  • 17. Gevent ● Greenlet 1 is running ● Greenlet 2 and 3 are ready
  • 18. Gevent ● Greenlet 1 has to wait for read ● Greenlet 1 switches to Event hub
  • 19. Gevent ● Event hub switches to Greenlet 3
  • 20. Gevent ● Greenlet 2 runs
  • 21. Gevent ● Greenlet 2 wants to sleep ● Greenlet 2 switches to Event hub
  • 22. Gevent ● Greenlet 1 data has come, moved to ready state ● Eventhub switches to Greenlet 3
  • 23. Gevent ● Greenlet 3 runs
  • 24. Gevent ● When Greenlet 1 resumes, its from next instruction ● It's as if it were a blocking call
  • 25. Green SSH Client 1. Init session 2. Authenticate 3. Get a channel 4. Issue command 5. Read output
  • 27. Going Concurrent Use pre-forked processes to use all cores
  • 28. Memory usage ssh mux memory usage 45 40 35 30 Memory(MB) 25 Gevent+Processes 20 15 10 5 0 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 # Concurrent Reqs
  • 29. SSH Mux Performace ssh mux performace chart 70 60 50 40 Time(s) Gevent+Processes 30 20 10 0 20 40 80 150 200 400 800 1200 1500 1800 2100 # Concurrent Reqs
  • 30. SSH Mux memory usage ssh mux memory usage 600 500 400 Memory(MB) Processes 300 Gevent 200 100 0 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 # Concurrent Reqs
  • 31. SSH Mux Performance ssh mux performance sheet 160 140 120 100 Processes Time(s) 80 Gevent+Processes 60 40 20 0 20 40 80 150 200 400 800 1200 1500 1800 2100 # Concurrent Reqs
  • 32. Gevent yay! ● Untwist – write linear non blocking code ● Explicit scheduling, dictate the execution flow ● Timeouts ● Events, AsyncResults for Synchronization ● gevent.wsgi ● Pre-spawned pool of greenlets
  • 33. Gevent beware of ● No multicore support ● Not great for CPU bound applications ● Third party libs must be green (non blocking) ● Misbehaving workers can be lethal ● No fairness when it comes to scheduling
  • 34. Take Away ● Gevent lets you write asynchronous code in a synchronous manner ● No multicore support, still need multiprocessing ● Not so great for CPU bound applications ● Split your application into CPU bound and IO bound parts ● Be willing to contribute patches ● Code available at [email protected]:aaloksood/pyexamples.git
  • 35. Thank you That's all folks!
  • 36. Countdown Timer ● Count down from 200000000 ● Split work among workers
  • 37. Threads Multithreading wonder 25 20 15 1 Core Time(s) 4 cores 10 5 0 1 2 3 4 5 6 7 8 9 10 # Workers
  • 38. One core Execution time One Core 14.5 14 13.5 13 Processes 1 Core Time (s) 12.5 Gevent_1 12 Gevent_4 11.5 11 10.5 1 2 3 4 5 6 7 8 9 10 # Workers
  • 39. Four cores Execution time 4 cores 25 20 Process 15 Threads Time(s) Gevent_1 10 Gevent_4 5 0 1 2 3 4 5 6 7 8 9 10 # Workers