SlideShare a Scribd company logo
Super Fast Gevent
By Walter Liu
Agenda
• Simple Example
• About Gevent
• About libevent
• Monkey patch of gevent
• Other notes
• About monkey patch
C10K problem and Gevent
Performance
Simple Example
Super Fast Gevent Introduction
Super Fast Gevent Introduction
About GEvent
• Fast event loop based on libevent or libevent2
• Light weight execution unit based on greenlets
• Use Monkey patch
• See monkey patch to know what it works on.
• Simple API
• Fast WSGI server
libevent
• /dev/poll
• kqueue(2)
• event ports
• POSIX select(2)
• Windows select()
• poll(2)
• epoll(4)
• Diff in different platform
Gevent Monkey Patch
• socket (dns=True)
• ssl
• os.fork()
• time.sleep()
• select
• threading => become co-routine
• _thread_local.local
• subprocess
• sys
• stdin, stdout, stderr
Other Notes
• Monkey patch
• It’s patching sys.modules, so it’s global patching.
• Apply monkey patch before other import. (especially on thread)
• Apply monkey patch after fork/multi-process.
• Be noted about 3rd
party library compatibility
• Be noted about blocking functions in your program.
• Gevent with Python web framework
• Played uWSGI with gevent. (very good performance)
• Tried using it in Django to accelerate crawling.
• How about gunicorn?
Monkey patch
Monkey patch example
Good for unit test
Tips
• Life time of monkey patch is till the end of process.
• You may chose not to monkey unpatch, but it may breaks the
whole program.
• Basically, it’s a dirty workaround.
• Thus, only use it on unit test or something like gevent.

More Related Content

PPTX
Getting to Know Airflow
PPTX
Airflow - a data flow engine
PPTX
Airflow at WePay
PDF
Intro to Airflow: Goodbye Cron, Welcome scheduled workflow management
PPTX
Running Airflow Workflows as ETL Processes on Hadoop
PDF
Apache Airflow
PDF
Apache Airflow Architecture
PPTX
Apache Airflow Introduction
Getting to Know Airflow
Airflow - a data flow engine
Airflow at WePay
Intro to Airflow: Goodbye Cron, Welcome scheduled workflow management
Running Airflow Workflows as ETL Processes on Hadoop
Apache Airflow
Apache Airflow Architecture
Apache Airflow Introduction

What's hot (20)

PDF
Apache airflow
PDF
How we use Fluentd in Treasure Data
PPTX
Elk meetup boston - logz.io
PDF
Airflow introduction
PDF
Introducing Apache Airflow and how we are using it
PDF
Virtualization at Gilt - Rangarajan Radhakrishnan
PPTX
Airflow Clustering and High Availability
PDF
CDK Meetup: Rule the World through IaC
PDF
How I learned to time travel, or, data pipelining and scheduling with Airflow
PDF
Using Elastic to Monitor Anything
PDF
Serverless Swift for Mobile Developers
PDF
Using Elastic to Monitor Everything - Christoph Wurm, Elastic - DevOpsDays Te...
PDF
Kibana + timelion: time series with the elastic stack
PDF
Monitoring kubernetes across data center and cloud
PPTX
Airflow presentation
PDF
Docker Usage Patterns - Meetup Docker Paris - November, 10th 2015
PDF
Zentral QueryCon 2018
PDF
Building a Data Ingestion & Processing Pipeline with Spark & Airflow
PDF
CS80A Foothill College Open Source Talk
PPTX
SYNCING IN JAVASCRIPT: MULTI-CLIENT COLLABORATION THROUGH DATA SHARING (Steve...
Apache airflow
How we use Fluentd in Treasure Data
Elk meetup boston - logz.io
Airflow introduction
Introducing Apache Airflow and how we are using it
Virtualization at Gilt - Rangarajan Radhakrishnan
Airflow Clustering and High Availability
CDK Meetup: Rule the World through IaC
How I learned to time travel, or, data pipelining and scheduling with Airflow
Using Elastic to Monitor Anything
Serverless Swift for Mobile Developers
Using Elastic to Monitor Everything - Christoph Wurm, Elastic - DevOpsDays Te...
Kibana + timelion: time series with the elastic stack
Monitoring kubernetes across data center and cloud
Airflow presentation
Docker Usage Patterns - Meetup Docker Paris - November, 10th 2015
Zentral QueryCon 2018
Building a Data Ingestion & Processing Pipeline with Spark & Airflow
CS80A Foothill College Open Source Talk
SYNCING IN JAVASCRIPT: MULTI-CLIENT COLLABORATION THROUGH DATA SHARING (Steve...
Ad

Viewers also liked (6)

KEY
gunicorn introduction
PPT
1KEY Dashboard - 1KEY Agile
PPT
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
PPT
Web Servers (ppt)
PDF
3 Things Every Sales Team Needs to Be Thinking About in 2017
PDF
How to Become a Thought Leader in Your Niche
gunicorn introduction
1KEY Dashboard - 1KEY Agile
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Web Servers (ppt)
3 Things Every Sales Team Needs to Be Thinking About in 2017
How to Become a Thought Leader in Your Niche
Ad

Similar to Super Fast Gevent Introduction (11)

PDF
Gevent be or not to be
PDF
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
PDF
Monkey-patching in Python: a magic trick or a powerful tool?
PPTX
Scaling django
PPTX
Gevent rabbit rpc
PDF
It’s 2021. Why are we -still- rebooting for patches? A look at Live Patching.
KEY
Gevent what's the point
PDF
Scaling Django with gevent
PDF
Linux Kernel Live Patching
PDF
Linux Foundation Mentorship Sessions - Kernel Livepatch: An Introduction
PDF
Linux Kernel - Let's Contribute!
Gevent be or not to be
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
Monkey-patching in Python: a magic trick or a powerful tool?
Scaling django
Gevent rabbit rpc
It’s 2021. Why are we -still- rebooting for patches? A look at Live Patching.
Gevent what's the point
Scaling Django with gevent
Linux Kernel Live Patching
Linux Foundation Mentorship Sessions - Kernel Livepatch: An Introduction
Linux Kernel - Let's Contribute!

More from Walter Liu (17)

PDF
Generative AI 在手機遊戲發行上的應用介紹.pdf
PDF
Infrastructure as code using Kubernetes
PDF
手機遊戲數位行銷工具淺談
PDF
關於第三方追蹤廣告再行銷的那些事兒
PDF
Kubernetes Workshop
PDF
Using Kubernetes to deploy Django in GCP
PDF
Game DDOS Prevention
PPTX
HTTP/2 to web dev
PPTX
HTTP/2 Introduction
PDF
Consul - service discovery and others
PPTX
Docker introduction
PPTX
WRS GIT Branching Model - draft
PPTX
Salty OPS – Saltstack Introduction
PDF
Django deployment and rpm+yum
PDF
Game Localization in Python
PPTX
Service production from d3 pitfall viewpoint
PPTX
Celery in the Django
Generative AI 在手機遊戲發行上的應用介紹.pdf
Infrastructure as code using Kubernetes
手機遊戲數位行銷工具淺談
關於第三方追蹤廣告再行銷的那些事兒
Kubernetes Workshop
Using Kubernetes to deploy Django in GCP
Game DDOS Prevention
HTTP/2 to web dev
HTTP/2 Introduction
Consul - service discovery and others
Docker introduction
WRS GIT Branching Model - draft
Salty OPS – Saltstack Introduction
Django deployment and rpm+yum
Game Localization in Python
Service production from d3 pitfall viewpoint
Celery in the Django

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation theory and applications.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Getting Started with Data Integration: FME Form 101
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
A Presentation on Artificial Intelligence
Diabetes mellitus diagnosis method based random forest with bat algorithm
20250228 LYD VKU AI Blended-Learning.pptx
Spectral efficient network and resource selection model in 5G networks
Mobile App Security Testing_ A Comprehensive Guide.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation theory and applications.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Big Data Technologies - Introduction.pptx
Programs and apps: productivity, graphics, security and other tools
Assigned Numbers - 2025 - Bluetooth® Document
The Rise and Fall of 3GPP – Time for a Sabbatical?
Getting Started with Data Integration: FME Form 101
Unlocking AI with Model Context Protocol (MCP)
Per capita expenditure prediction using model stacking based on satellite ima...
Building Integrated photovoltaic BIPV_UPV.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
cuic standard and advanced reporting.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
A Presentation on Artificial Intelligence

Super Fast Gevent Introduction

  • 1. Super Fast Gevent By Walter Liu
  • 2. Agenda • Simple Example • About Gevent • About libevent • Monkey patch of gevent • Other notes • About monkey patch
  • 3. C10K problem and Gevent Performance
  • 7. About GEvent • Fast event loop based on libevent or libevent2 • Light weight execution unit based on greenlets • Use Monkey patch • See monkey patch to know what it works on. • Simple API • Fast WSGI server
  • 8. libevent • /dev/poll • kqueue(2) • event ports • POSIX select(2) • Windows select() • poll(2) • epoll(4) • Diff in different platform
  • 9. Gevent Monkey Patch • socket (dns=True) • ssl • os.fork() • time.sleep() • select • threading => become co-routine • _thread_local.local • subprocess • sys • stdin, stdout, stderr
  • 10. Other Notes • Monkey patch • It’s patching sys.modules, so it’s global patching. • Apply monkey patch before other import. (especially on thread) • Apply monkey patch after fork/multi-process. • Be noted about 3rd party library compatibility • Be noted about blocking functions in your program. • Gevent with Python web framework • Played uWSGI with gevent. (very good performance) • Tried using it in Django to accelerate crawling. • How about gunicorn?
  • 14. Tips • Life time of monkey patch is till the end of process. • You may chose not to monkey unpatch, but it may breaks the whole program. • Basically, it’s a dirty workaround. • Thus, only use it on unit test or something like gevent.