SlideShare uma empresa Scribd logo
1 de 13
Baixar para ler offline
10 uWSGI tricks
                        Roberto De Ioris (Unbit)
                           DjangoDay 2012




giovedì 26 aprile 12
Trick 1:
                          pip install uwsgitop
                 [uwsgi]
                 wsgi-file = /var/www/myapp/wsgi.py
                 master = true
                 processes = 4
                 http-socket = :8080
                 stats = 127.0.0.1:4040




giovedì 26 aprile 12
uwsgitop 127.0.0.1:4040




giovedì 26 aprile 12
Trick 2:
                       sessions cleaner via cron
                   from uwsgidecorators import *
                 from django.contrib.sessions.models import Session

                 # equivalent to 40 2 * * *
                 @cron(40, 2, -1, -1, -1)
                 def clear_django_session(num):
                     print("it's 2:40: clearing django sessions")
                     Session.objects.all().delete()




giovedì 26 aprile 12
Trick 3:
                           requests offloading
                 [uwsgi]
                 wsgi-file = /var/www/myapp/wsgi.py
                 master = true
                 processes = 4
                 socket = 192.168.0.1:3032
                 route = ^/oldsite uwsgi:192.168.0.17:3030,0,0
                 route = ^/oldersite uwsgi:/tmp/socket,0,0
                 route = ^/foo uwsgi:192.168.0.22:3031,0,0


giovedì 26 aprile 12
Trick 4:
                         attaching daemons
                 [uwsgi]
                 wsgi-file = /var/www/myapp/wsgi.py
                 master = true
                 processes = 4
                 socket = 192.168.0.1:3032
                 attach-daemon = memcached -p 5050 -m 64
                 attach-daemon = memcached -p 6060 -m 100
                 attach-daemon = redis-server redis.conf


giovedì 26 aprile 12
Trick 5:
                  autoreloading (during development)
                 [uwsgi]
                 wsgi-file = /var/www/myapp/wsgi.py
                 master = true
                 processes = 4
                 socket = 192.168.0.1:3032
                 python-autoreload = 3




giovedì 26 aprile 12
Trick 6:
                       adaptive process spawning
                 [uwsgi]
                 wsgi-file = /var/www/myapp/wsgi.py
                 master = true
                 processes = 20
                 socket = 192.168.0.1:3032
                 cheaper = 2




giovedì 26 aprile 12
Trick 7:
                               reload on exception
                 [uwsgi]
                 wsgi-file = /var/www/myapp/wsgi.py
                 master = true
                 processes = 4
                 socket = 192.168.0.1:3032
                 reload-on-exception-type = MyException
                 reload-on-exception-repr = psycopg2.InterfaceError: connection already closed




giovedì 26 aprile 12
Trick 8:
                            aliasing modules
                 [uwsgi]
                 wsgi-file = /var/www/myapp/wsgi.py
                 master = true
                 processes = 4
                 socket = 192.168.0.1:3032
                 pymodule-alias = fooapp.models=/tmp/testmodel.py
                 pymodule-alias = anotherapp.view=/tmp/viste.py
                 pymodule-alias = uglyapp=/tmp/ugliestapp


giovedì 26 aprile 12
Trick 9:
                                 virtualenv
                 [uwsgi]
                 wsgi-file = /var/www/myapp/wsgi.py
                 master = true
                 processes = 4
                 socket = 192.168.0.1:3032
                 virtualenv = /var/www/envs/foo




giovedì 26 aprile 12
Trick 10:
                                placeholders
                 [uwsgi]
                 applicazione = /var/www/myapp
                 master = true
                 processes = 4
                 socket = 192.168.0.1:3032

                 wsgi-file = %(applicazione)/wsgi.py




giovedì 26 aprile 12
Bonus Trick:
                                   KSM
                 [uwsgi]
                 wsgi-file = /var/www/myapp/wsgi.py
                 master = true
                 processes = 4
                 socket = 192.168.0.1:3032
                 ksm = 10




giovedì 26 aprile 12

Mais conteúdo relacionado

Mais de WEBdeBS

Virtualenv
VirtualenvVirtualenv
VirtualenvWEBdeBS
 
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia ContiniWEBdeBS
 
Iga workflow
Iga workflowIga workflow
Iga workflowWEBdeBS
 
PepperTweet - Project presentation Startup Weekend Brescia
PepperTweet - Project presentation Startup Weekend BresciaPepperTweet - Project presentation Startup Weekend Brescia
PepperTweet - Project presentation Startup Weekend BresciaWEBdeBS
 
Peppertweet - Presentazione Startup Weekend Brescia
Peppertweet - Presentazione Startup Weekend BresciaPeppertweet - Presentazione Startup Weekend Brescia
Peppertweet - Presentazione Startup Weekend BresciaWEBdeBS
 
NoSql Day - Chiusura
NoSql Day - ChiusuraNoSql Day - Chiusura
NoSql Day - ChiusuraWEBdeBS
 
NoSql Day - Apertura
NoSql Day - AperturaNoSql Day - Apertura
NoSql Day - AperturaWEBdeBS
 

Mais de WEBdeBS (8)

Virtualenv
VirtualenvVirtualenv
Virtualenv
 
Fagungis
FagungisFagungis
Fagungis
 
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia Contini
 
Iga workflow
Iga workflowIga workflow
Iga workflow
 
PepperTweet - Project presentation Startup Weekend Brescia
PepperTweet - Project presentation Startup Weekend BresciaPepperTweet - Project presentation Startup Weekend Brescia
PepperTweet - Project presentation Startup Weekend Brescia
 
Peppertweet - Presentazione Startup Weekend Brescia
Peppertweet - Presentazione Startup Weekend BresciaPeppertweet - Presentazione Startup Weekend Brescia
Peppertweet - Presentazione Startup Weekend Brescia
 
NoSql Day - Chiusura
NoSql Day - ChiusuraNoSql Day - Chiusura
NoSql Day - Chiusura
 
NoSql Day - Apertura
NoSql Day - AperturaNoSql Day - Apertura
NoSql Day - Apertura
 

Último

Mael Chiabrera, Software Developer; Viola Bongini, Digital Experience Designe...
Mael Chiabrera, Software Developer; Viola Bongini, Digital Experience Designe...Mael Chiabrera, Software Developer; Viola Bongini, Digital Experience Designe...
Mael Chiabrera, Software Developer; Viola Bongini, Digital Experience Designe...Associazione Digital Days
 
Edoardo Di Pietro – “Virtual Influencer vs Umano: Rubiamo il lavoro all’AI”
Edoardo Di Pietro – “Virtual Influencer vs Umano: Rubiamo il lavoro all’AI”Edoardo Di Pietro – “Virtual Influencer vs Umano: Rubiamo il lavoro all’AI”
Edoardo Di Pietro – “Virtual Influencer vs Umano: Rubiamo il lavoro all’AI”Associazione Digital Days
 
Alessandro Nasi, COO @Djungle Studio – “Cosa delegheresti alla copia di te st...
Alessandro Nasi, COO @Djungle Studio – “Cosa delegheresti alla copia di te st...Alessandro Nasi, COO @Djungle Studio – “Cosa delegheresti alla copia di te st...
Alessandro Nasi, COO @Djungle Studio – “Cosa delegheresti alla copia di te st...Associazione Digital Days
 
Gabriele Mittica, CEO @Corley Cloud – “Come creare un’azienda “nativa in clou...
Gabriele Mittica, CEO @Corley Cloud – “Come creare un’azienda “nativa in clou...Gabriele Mittica, CEO @Corley Cloud – “Come creare un’azienda “nativa in clou...
Gabriele Mittica, CEO @Corley Cloud – “Come creare un’azienda “nativa in clou...Associazione Digital Days
 
Alessio Mazzotti, Aaron Brancotti; Writer, Screenwriter, Director, UX, Autore...
Alessio Mazzotti, Aaron Brancotti; Writer, Screenwriter, Director, UX, Autore...Alessio Mazzotti, Aaron Brancotti; Writer, Screenwriter, Director, UX, Autore...
Alessio Mazzotti, Aaron Brancotti; Writer, Screenwriter, Director, UX, Autore...Associazione Digital Days
 
Daniele Lunassi, CEO & Head of Design @Eye Studios – “Creare prodotti e servi...
Daniele Lunassi, CEO & Head of Design @Eye Studios – “Creare prodotti e servi...Daniele Lunassi, CEO & Head of Design @Eye Studios – “Creare prodotti e servi...
Daniele Lunassi, CEO & Head of Design @Eye Studios – “Creare prodotti e servi...Associazione Digital Days
 
Programma Biennale Tecnologia 2024 Torino
Programma Biennale Tecnologia 2024 TorinoProgramma Biennale Tecnologia 2024 Torino
Programma Biennale Tecnologia 2024 TorinoQuotidiano Piemontese
 
Federico Bottino, Lead Venture Builder – “Riflessioni sull’Innovazione: La Cu...
Federico Bottino, Lead Venture Builder – “Riflessioni sull’Innovazione: La Cu...Federico Bottino, Lead Venture Builder – “Riflessioni sull’Innovazione: La Cu...
Federico Bottino, Lead Venture Builder – “Riflessioni sull’Innovazione: La Cu...Associazione Digital Days
 
Luigi Di Carlo, CEO & Founder @Evometrika srl – “Ruolo della computer vision ...
Luigi Di Carlo, CEO & Founder @Evometrika srl – “Ruolo della computer vision ...Luigi Di Carlo, CEO & Founder @Evometrika srl – “Ruolo della computer vision ...
Luigi Di Carlo, CEO & Founder @Evometrika srl – “Ruolo della computer vision ...Associazione Digital Days
 

Último (9)

Mael Chiabrera, Software Developer; Viola Bongini, Digital Experience Designe...
Mael Chiabrera, Software Developer; Viola Bongini, Digital Experience Designe...Mael Chiabrera, Software Developer; Viola Bongini, Digital Experience Designe...
Mael Chiabrera, Software Developer; Viola Bongini, Digital Experience Designe...
 
Edoardo Di Pietro – “Virtual Influencer vs Umano: Rubiamo il lavoro all’AI”
Edoardo Di Pietro – “Virtual Influencer vs Umano: Rubiamo il lavoro all’AI”Edoardo Di Pietro – “Virtual Influencer vs Umano: Rubiamo il lavoro all’AI”
Edoardo Di Pietro – “Virtual Influencer vs Umano: Rubiamo il lavoro all’AI”
 
Alessandro Nasi, COO @Djungle Studio – “Cosa delegheresti alla copia di te st...
Alessandro Nasi, COO @Djungle Studio – “Cosa delegheresti alla copia di te st...Alessandro Nasi, COO @Djungle Studio – “Cosa delegheresti alla copia di te st...
Alessandro Nasi, COO @Djungle Studio – “Cosa delegheresti alla copia di te st...
 
Gabriele Mittica, CEO @Corley Cloud – “Come creare un’azienda “nativa in clou...
Gabriele Mittica, CEO @Corley Cloud – “Come creare un’azienda “nativa in clou...Gabriele Mittica, CEO @Corley Cloud – “Come creare un’azienda “nativa in clou...
Gabriele Mittica, CEO @Corley Cloud – “Come creare un’azienda “nativa in clou...
 
Alessio Mazzotti, Aaron Brancotti; Writer, Screenwriter, Director, UX, Autore...
Alessio Mazzotti, Aaron Brancotti; Writer, Screenwriter, Director, UX, Autore...Alessio Mazzotti, Aaron Brancotti; Writer, Screenwriter, Director, UX, Autore...
Alessio Mazzotti, Aaron Brancotti; Writer, Screenwriter, Director, UX, Autore...
 
Daniele Lunassi, CEO & Head of Design @Eye Studios – “Creare prodotti e servi...
Daniele Lunassi, CEO & Head of Design @Eye Studios – “Creare prodotti e servi...Daniele Lunassi, CEO & Head of Design @Eye Studios – “Creare prodotti e servi...
Daniele Lunassi, CEO & Head of Design @Eye Studios – “Creare prodotti e servi...
 
Programma Biennale Tecnologia 2024 Torino
Programma Biennale Tecnologia 2024 TorinoProgramma Biennale Tecnologia 2024 Torino
Programma Biennale Tecnologia 2024 Torino
 
Federico Bottino, Lead Venture Builder – “Riflessioni sull’Innovazione: La Cu...
Federico Bottino, Lead Venture Builder – “Riflessioni sull’Innovazione: La Cu...Federico Bottino, Lead Venture Builder – “Riflessioni sull’Innovazione: La Cu...
Federico Bottino, Lead Venture Builder – “Riflessioni sull’Innovazione: La Cu...
 
Luigi Di Carlo, CEO & Founder @Evometrika srl – “Ruolo della computer vision ...
Luigi Di Carlo, CEO & Founder @Evometrika srl – “Ruolo della computer vision ...Luigi Di Carlo, CEO & Founder @Evometrika srl – “Ruolo della computer vision ...
Luigi Di Carlo, CEO & Founder @Evometrika srl – “Ruolo della computer vision ...
 

Djangoday lt 20120420

  • 1. 10 uWSGI tricks Roberto De Ioris (Unbit) DjangoDay 2012 giovedì 26 aprile 12
  • 2. Trick 1: pip install uwsgitop [uwsgi] wsgi-file = /var/www/myapp/wsgi.py master = true processes = 4 http-socket = :8080 stats = 127.0.0.1:4040 giovedì 26 aprile 12
  • 4. Trick 2: sessions cleaner via cron from uwsgidecorators import * from django.contrib.sessions.models import Session # equivalent to 40 2 * * * @cron(40, 2, -1, -1, -1) def clear_django_session(num): print("it's 2:40: clearing django sessions") Session.objects.all().delete() giovedì 26 aprile 12
  • 5. Trick 3: requests offloading [uwsgi] wsgi-file = /var/www/myapp/wsgi.py master = true processes = 4 socket = 192.168.0.1:3032 route = ^/oldsite uwsgi:192.168.0.17:3030,0,0 route = ^/oldersite uwsgi:/tmp/socket,0,0 route = ^/foo uwsgi:192.168.0.22:3031,0,0 giovedì 26 aprile 12
  • 6. Trick 4: attaching daemons [uwsgi] wsgi-file = /var/www/myapp/wsgi.py master = true processes = 4 socket = 192.168.0.1:3032 attach-daemon = memcached -p 5050 -m 64 attach-daemon = memcached -p 6060 -m 100 attach-daemon = redis-server redis.conf giovedì 26 aprile 12
  • 7. Trick 5: autoreloading (during development) [uwsgi] wsgi-file = /var/www/myapp/wsgi.py master = true processes = 4 socket = 192.168.0.1:3032 python-autoreload = 3 giovedì 26 aprile 12
  • 8. Trick 6: adaptive process spawning [uwsgi] wsgi-file = /var/www/myapp/wsgi.py master = true processes = 20 socket = 192.168.0.1:3032 cheaper = 2 giovedì 26 aprile 12
  • 9. Trick 7: reload on exception [uwsgi] wsgi-file = /var/www/myapp/wsgi.py master = true processes = 4 socket = 192.168.0.1:3032 reload-on-exception-type = MyException reload-on-exception-repr = psycopg2.InterfaceError: connection already closed giovedì 26 aprile 12
  • 10. Trick 8: aliasing modules [uwsgi] wsgi-file = /var/www/myapp/wsgi.py master = true processes = 4 socket = 192.168.0.1:3032 pymodule-alias = fooapp.models=/tmp/testmodel.py pymodule-alias = anotherapp.view=/tmp/viste.py pymodule-alias = uglyapp=/tmp/ugliestapp giovedì 26 aprile 12
  • 11. Trick 9: virtualenv [uwsgi] wsgi-file = /var/www/myapp/wsgi.py master = true processes = 4 socket = 192.168.0.1:3032 virtualenv = /var/www/envs/foo giovedì 26 aprile 12
  • 12. Trick 10: placeholders [uwsgi] applicazione = /var/www/myapp master = true processes = 4 socket = 192.168.0.1:3032 wsgi-file = %(applicazione)/wsgi.py giovedì 26 aprile 12
  • 13. Bonus Trick: KSM [uwsgi] wsgi-file = /var/www/myapp/wsgi.py master = true processes = 4 socket = 192.168.0.1:3032 ksm = 10 giovedì 26 aprile 12