SlideShare a Scribd company logo
Adam Lowry
PDX Python, 2010-07-13
So you have a WSGI
        app
 def app(environ, start_response):
     data = "Hello, World!n"
     start_response("200 OK", [
         ("Content-Type", "text/plain"),
         ("Content-Length", str(len(data)))
     ])
     return iter([data])
Now you have a server

$ gunicorn   -w 4 myapp:app
2010-06-05   23:27:07 [16800]   [INFO]   Arbiter booted
2010-06-05   23:27:07 [16800]   [INFO]   Listening at: http://127.0.0.1:8000
2010-06-05   23:27:07 [16801]   [INFO]   Worker spawned (pid: 16801)
2010-06-05   23:27:07 [16802]   [INFO]   Worker spawned (pid: 16802)
2010-06-05   23:27:07 [16803]   [INFO]   Worker spawned (pid: 16803)
2010-06-05   23:27:07 [16804]   [INFO]   Worker spawned (pid: 16804)
15:50 |termie| when the gunicorn fights, it wins
02:43 |termie| when the gunicorn urinates the result is a perfect mixture
               of champagne and green charteuse
16:41 |termie| the gunicorn shoots _you_
09:51 |termie| the gunicorn cannot be managed




                         http://thegunicorn.com/
Details

• a port of Ruby’s Unicorn
• prefork
• WSGI, Django, Paster
• Light on resources, extensible
Configuration

• Paster INI
• Python config file
• Command line
Fast Clients Only




http://commons.wikimedia.org/wiki/File:Slow_Loris_Female.jpg
nginx
upstream app_server {
        server unix:/tmp/gunicorn.sock fail_timeout=0;
}

server {
           listen 80 default;
           server_name adam.therobots.org;

           location / {
               proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
               proxy_set_header Host $http_host;
               proxy_redirect off;

              if (!-f $request_filename) {
                  proxy_pass http://app_server;
                  break;
              }
       }
}
What about slow
          resources?

gunicorn -k egg:gunicorn#eventlet myapp:app
gunicorn -k egg:gunicorn#gevent myapp:app
More about
  gunicorn                     More about me
    http://gunicorn.org/        http://adam.therobots.org/
http://pypi.python.org/pypi/   http://twitter.com/robotadam
          gunicorn                 adam@therobots.org
http://github.com/benoitc/
          gunicorn/
Bonus Module!
     http://pypi.python.org/pypi/setproctitle


www-data   9256   0.2   2.6   16696   13416   ?   S   Jun27   57:16   gunicorn:   master   [zine-prefork]
www-data   9257   0.2   5.7   36204   29272   ?   S   Jun27   69:25   gunicorn:   worker   [zine-prefork]
www-data   9258   0.3   5.7   36304   29388   ?   S   Jun27   75:52   gunicorn:   worker   [zine-prefork]
www-data   9259   0.3   5.9   37232   30220   ?   S   Jun27   75:02   gunicorn:   worker   [zine-prefork]
www-data   9260   0.3   5.7   36644   29560   ?   S   Jun27   75:29   gunicorn:   worker   [zine-prefork]

More Related Content

PDF
GoLang & GoatCore
PDF
Gitosis on Mac OS X Server
PDF
JSLab. Домников Виталий. "ES6 генераторы и Koa.js"
PDF
Virthualenvwrapper
PPTX
Sensu wrapper-sensu-summit
ZIP
robrighter's Node.js presentation for DevChatt
PPT
Qtp Scripts
PPT
GoLang & GoatCore
Gitosis on Mac OS X Server
JSLab. Домников Виталий. "ES6 генераторы и Koa.js"
Virthualenvwrapper
Sensu wrapper-sensu-summit
robrighter's Node.js presentation for DevChatt
Qtp Scripts

What's hot (20)

PDF
Javascript Continues Integration in Jenkins with AngularJS
PDF
PuppetDB: New Adventures in Higher-Order Automation - PuppetConf 2013
PDF
Productivity tips for developers
PDF
Puppet camp Portland 2015: -windows (1)
PDF
Tupperware
PDF
PHP 机智问答
PPTX
CouchDB Day NYC 2017: Replication
PPTX
Linux basic3
PDF
Tdc 2013 - Ecossistema Ruby
PDF
ES6 generators
PPT
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
PDF
G*なクラウド ~雲のかなたに~
PDF
Go初心者がGoでコマンドラインツールの作成に挑戦した話
PDF
Getting Started with Puppet on Windows - PuppetConf 2014
PDF
Pydata-Python tools for webscraping
PDF
Open Social Data (Jaca), Alejandro Rivero
PDF
Kotlinのcoroutine、async/awaitと同じでしょ?って思ってたけど意外と洗練されててすごいなぁって思った話をさせてほしい
PDF
Ring: Web Apps in Idiomatic Clojure
PDF
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NY
PDF
G* on GAE/J 挑戦編
Javascript Continues Integration in Jenkins with AngularJS
PuppetDB: New Adventures in Higher-Order Automation - PuppetConf 2013
Productivity tips for developers
Puppet camp Portland 2015: -windows (1)
Tupperware
PHP 机智问答
CouchDB Day NYC 2017: Replication
Linux basic3
Tdc 2013 - Ecossistema Ruby
ES6 generators
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
G*なクラウド ~雲のかなたに~
Go初心者がGoでコマンドラインツールの作成に挑戦した話
Getting Started with Puppet on Windows - PuppetConf 2014
Pydata-Python tools for webscraping
Open Social Data (Jaca), Alejandro Rivero
Kotlinのcoroutine、async/awaitと同じでしょ?って思ってたけど意外と洗練されててすごいなぁって思った話をさせてほしい
Ring: Web Apps in Idiomatic Clojure
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NY
G* on GAE/J 挑戦編
Ad

Viewers also liked (6)

PPT
Super Fast Gevent Introduction
PDF
Python and pandas as back end to real-time data driven applications by Giovan...
PPT
1KEY Dashboard - 1KEY Agile
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
Super Fast Gevent Introduction
Python and pandas as back end to real-time data driven applications by Giovan...
1KEY Dashboard - 1KEY Agile
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 gunicorn introduction (20)

PDF
Quick and Dirty Python Deployments with Heroku
PPTX
Using Coroutines to Create Efficient, High-Concurrency Web Applications
KEY
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PDF
Batteries not included
PDF
Alternative Infrastucture
PDF
Evented applications with RabbitMQ and CakePHP
PDF
WSGI, Django, Gunicorn
PDF
Multiple django applications on a single server with nginx
PDF
Toster - Understanding the Rails Web Model and Scalability Options
PDF
Understanding the Rails web model and scalability options
PPTX
uWSGI - Swiss army knife for your Python web apps
PDF
OpenERP 6.1 Framework Changes
PDF
Scaling Django with gevent
PDF
Denys Serhiienko "ASGI in depth"
PDF
Socket programming, and openresty
KEY
PHP to Python with No Regrets
ODP
Apache httpd 2.4: The Cloud Killer App
KEY
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
PDF
Deploying And Monitoring Rails
PPTX
HELM kubernetes package manager for beginner's
Quick and Dirty Python Deployments with Heroku
Using Coroutines to Create Efficient, High-Concurrency Web Applications
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
Batteries not included
Alternative Infrastucture
Evented applications with RabbitMQ and CakePHP
WSGI, Django, Gunicorn
Multiple django applications on a single server with nginx
Toster - Understanding the Rails Web Model and Scalability Options
Understanding the Rails web model and scalability options
uWSGI - Swiss army knife for your Python web apps
OpenERP 6.1 Framework Changes
Scaling Django with gevent
Denys Serhiienko "ASGI in depth"
Socket programming, and openresty
PHP to Python with No Regrets
Apache httpd 2.4: The Cloud Killer App
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
Deploying And Monitoring Rails
HELM kubernetes package manager for beginner's

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
A Presentation on Artificial Intelligence
PDF
Machine learning based COVID-19 study performance prediction
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Cloud computing and distributed systems.
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Spectral efficient network and resource selection model in 5G networks
gpt5_lecture_notes_comprehensive_20250812015547.pdf
A comparative analysis of optical character recognition models for extracting...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Encapsulation_ Review paper, used for researhc scholars
MYSQL Presentation for SQL database connectivity
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
NewMind AI Weekly Chronicles - August'25-Week II
Programs and apps: productivity, graphics, security and other tools
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
A Presentation on Artificial Intelligence
Machine learning based COVID-19 study performance prediction
Chapter 3 Spatial Domain Image Processing.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Building Integrated photovoltaic BIPV_UPV.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Cloud computing and distributed systems.
Network Security Unit 5.pdf for BCA BBA.
Agricultural_Statistics_at_a_Glance_2022_0.pdf

gunicorn introduction

  • 2. So you have a WSGI app def app(environ, start_response): data = "Hello, World!n" start_response("200 OK", [ ("Content-Type", "text/plain"), ("Content-Length", str(len(data))) ]) return iter([data])
  • 3. Now you have a server $ gunicorn -w 4 myapp:app 2010-06-05 23:27:07 [16800] [INFO] Arbiter booted 2010-06-05 23:27:07 [16800] [INFO] Listening at: http://127.0.0.1:8000 2010-06-05 23:27:07 [16801] [INFO] Worker spawned (pid: 16801) 2010-06-05 23:27:07 [16802] [INFO] Worker spawned (pid: 16802) 2010-06-05 23:27:07 [16803] [INFO] Worker spawned (pid: 16803) 2010-06-05 23:27:07 [16804] [INFO] Worker spawned (pid: 16804)
  • 4. 15:50 |termie| when the gunicorn fights, it wins 02:43 |termie| when the gunicorn urinates the result is a perfect mixture of champagne and green charteuse 16:41 |termie| the gunicorn shoots _you_ 09:51 |termie| the gunicorn cannot be managed http://thegunicorn.com/
  • 5. Details • a port of Ruby’s Unicorn • prefork • WSGI, Django, Paster • Light on resources, extensible
  • 6. Configuration • Paster INI • Python config file • Command line
  • 8. nginx upstream app_server { server unix:/tmp/gunicorn.sock fail_timeout=0; } server { listen 80 default; server_name adam.therobots.org; location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; if (!-f $request_filename) { proxy_pass http://app_server; break; } } }
  • 9. What about slow resources? gunicorn -k egg:gunicorn#eventlet myapp:app gunicorn -k egg:gunicorn#gevent myapp:app
  • 10. More about gunicorn More about me http://gunicorn.org/ http://adam.therobots.org/ http://pypi.python.org/pypi/ http://twitter.com/robotadam gunicorn adam@therobots.org http://github.com/benoitc/ gunicorn/
  • 11. Bonus Module! http://pypi.python.org/pypi/setproctitle www-data 9256 0.2 2.6 16696 13416 ? S Jun27 57:16 gunicorn: master [zine-prefork] www-data 9257 0.2 5.7 36204 29272 ? S Jun27 69:25 gunicorn: worker [zine-prefork] www-data 9258 0.3 5.7 36304 29388 ? S Jun27 75:52 gunicorn: worker [zine-prefork] www-data 9259 0.3 5.9 37232 30220 ? S Jun27 75:02 gunicorn: worker [zine-prefork] www-data 9260 0.3 5.7 36644 29560 ? S Jun27 75:29 gunicorn: worker [zine-prefork]

Editor's Notes

  • #2: A bit of a stretch -- an app, not a module/package But works with nearly any python web application, and is easy_installable/pip installable gunicorn is a simple Python web server.
  • #4: 4 workers, all listening on shared socket python path colon callable name (defaults to ‘application’) Pronounced gee-unicorn, günicorn, but I always call it gunicorn
  • #5: I’m not the only one
  • #6: Want something stable and simple, easy to reason about
  • #12: Setting the process name is useful for multi-process environments Hard to do cross-platform This uses code from PostgreSQL, which is always awesome