More Related Content Similar to Jk rubyslava 25 Similar to Jk rubyslava 25 (20) Jk rubyslava 252. Čo to robí?
• Search engine
• Booking engine
• UX
• Customer support
• Magic & Science
5. Tech
• Javascript, everywhere (CanJS)
– yeoman, node, grunt, bower, testacular
• Python
• MongoDB & Redis
• Celery & uWSGI
• Nginx & MySQL & stuff
• Trello & Apiary
6. uWSGI
• uwsgi/wsgi vs uWSGI
• wsgi = slabšie http pre py
– PEP 333 a 3333
• uWSGI – lepítko medzi web fw a nginx
• čo Tornado/Diesel?
7. uWSGi features
• performance
• funguje všade (nginx, apache…)
• multiprotocol (uwsgi, http, whatever)
• shared memory
• zerg
• management workerov
• pluginy
8. Performance
• Throughput (req/sec)
• Danke - http://blog.kgriffs.com
9. Config Nginx
upstream uwsgicluster {
server 127.0.0.1:9999;
server 127.0.0.1:10000 backup=1;
}
server {
location /images {
root /var/www/obrazky;
}
location /lietadla {
include uwsgi_params;
uwsgi_pass uwsgicluster;
uwsgi_read_timeout 60; uwsgi_connect_timeout 60;
}
}
10. uWSGI config
[uwsgi]
socket = 127.0.0.1:9999
master = true #master proces
processes = 5
harakiri = 20 #max 20s na dotaz
max-requests=15 #max req na 1 proces
limit-as=500 #max memory na 1 proces
memory-report=true
carbon = 127.0.0.1:2003 #graphite
file = lietadlo.py
daemonize = lietadlo.log
touch-reload = lietadlo.py
11. Shared memory - Py
/home/virtualenv/bin/uwsgi -s :3033 --pyshell --cache 1000
*** Cache subsystem initialized: 64MB (key: 2096 bytes, keys: 2096000 bytes, data:
65536000 bytes) preallocated ***
uwsgi socket 0 bound to TCP address :3033 fd 3
import uwsgi
uwsgi.cache_set("foo_key1", "foo_value")
key = uwsgi.cache_get("foo_key")
from redis import Redis
redis = Redis(unix_socket_path="/var/run/redis/redis.sock", db = 7)
redis.set("foo_key","foo_value")
key = redis.get("foo_key")
d = {}
d["foo_key "] = "foo_value"
key = d["foo_key "]
12. Shared memory - perfo
25
20
15
Py dict
10 uWSGI
Redis
5
0
Get request Spotreba ram pre 10 procesov
13. Shared mem : Redis
from datetime import datetime
80:1
opak = 10000
start = datetime.now()
for x in range(opak):
key=uwsgi.cache_get("foo_key")
print datetime.now()-start
0:00:00.006963
start = datetime.now()
for x in range(opak):
key = redis.get("foo_key")
print datetime.now()-start
0:00:00.545974
start = datetime.now()
for x in range(opak):
key = d["foo_key "]
print datetime.now()-start
0:00:00.003890
15. Zerg deploy
./uwsgi –M –p 8 --pidfile main.pid --module welcome --zerg-server /var/run/mutalisk
./uwsgi --zerg /var/run/mutalisk --pidfile test.pid s--master --processes 4 --module
welcome
uwsgi --pause main.pid
#Naskočí zerg… shit shit shit
uwsgi --resume main.pid
uwsgi --stop test.pid
16. Logging v uWSGI
• oddelenie error/access logov
• Mongo, Redis, ZeroMQ, network, Graphite
• Alert system
• Do budúcna Sentry/Airbrake (uWSGI 1.9)
17. Top prusers v SP
• TSP
• Optimalizácia memory/sorted sets v Redise
• uWSGI 1.9 :)