Your SlideShare is downloading. ×
Djangoday lt 20120420
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Djangoday lt 20120420

710
views

Published on

Published in: Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
710
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 10 uWSGI tricks Roberto De Ioris (Unbit) DjangoDay 2012giovedì 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:4040giovedì 26 aprile 12
  • 3. uwsgitop 127.0.0.1:4040giovedì 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("its 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,0giovedì 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.confgiovedì 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 = 3giovedì 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 = 2giovedì 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 closedgiovedì 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/ugliestappgiovedì 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/foogiovedì 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.pygiovedì 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 = 10giovedì 26 aprile 12