воскресенье, 8 ноября 2009 г.

Cherokee + uWSGI + Django How-To

Навеяно:
http://habrahabr.ru/blogs/python/67475/
http://m.habrahabr.ru/post/70531/
---

Решил тут я попробывать веб-сервер cherokee для django-сайта. Обычно используется flup-прослойка, а я хотел задействовать uwsgi.

Что я сделал (опишу успешные шаги):
1. создал новый django-проект
2. создал новый app "dummy" с простым выводом:
def index(request):
    return HttpResponse('hello from django!')
3. установил cherokee последнюю версию из svn (на сайте чероки описано как это сделать), т.к. в текущей 0.99.19 нет визарда для настройки uWSGI...
4. сайты у меня находятся в каталоге /var/www-cherokee (владелец www-data)
5. в каталог django1 я скопировал свой проект.
6. в /var/www-cherokee нужно поместить uwsgi.xml - это конфигурационный файл для запуска джанго-сайта. содержание моего:
<uwsgi>
    <pythonpath>/var/www-cherokee/</pythonpath>
    <pythonpath>/var/www-cherokee/django1</pythonpath>
    <app mountpoint="/">
        <script>/django1/django_wsgi</script>
    </app>
</uwsgi>
обратите внимание на пути в pythonpath - без них работать не будет.
7. в /var/www-cherokee/django1 помещаем скрипт для вызова джанго (django_wsgi):
#some code for run on cherokee web server

import os
import django.core.handlers.wsgi
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
application = django.core.handlers.wsgi.WSGIHandler()
8. в настройках cherokee (в которые легко попасть через sudo cherokee-admin -u и потом в браузере http://localhost:9090) нужно в разделе "Virtual Server: default" вызвать "wizards"->platforms ->uWSGI ->run wizard.
так же в параметре "Interpreter" проверьте путь до конфига uwsgi.xml (у меня строка выглядит так: /usr/bin/uwsgi -s /tmp/cherokee-source11.sock -C -x /var/www-cherokee/uwsgi.xml )

В принципе - все. Перезапустил сервер и в браузере увидел "hello..."

П.С.: о сломанных копьях в процессе конфигурации я умолчу. если что - я настраивал по этому посту.
П.П.С: если что то не работает (я сначала получал только "uwsgi error" в браузере) - попробуйте запустить в окне терминала строчку из настройки интерпретатора (/usr/bin/uwsgi -s /tmp/cherokee-source11.sock -C -x /var/www-cherokee/uwsgi.xml) и не закрывая его обновить страницу в браузере. потом в терминале можно увидеть ошибки (я так нашел неправильно указанный путь)... ВНИМАНИЕ! после запуска интерпретатора в ручную нужно удалять файл /tmp/cherokee-source11.sock (в моем случае)!

---
тесты:
1. flup
2. uWSGI

= 1 =============
Document Length: 18 bytes

Concurrency Level: 10
Time taken for tests: 102.068 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 1660166 bytes
HTML transferred: 180018 bytes
Requests per second: 97.97 [#/sec] (mean)
Time per request: 102.068 [ms] (mean)
Time per request: 10.207 [ms] (mean, across all concurrent requests)
Transfer rate: 15.88 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 1.8 0 39
Processing: 3 101 241.3 39 3777
Waiting: 0 98 236.6 38 3777
Total: 3 102 241.3 40 3778

Percentage of the requests served within a certain time (ms)
50% 40
66% 56
75% 69
80% 79
90% 171
95% 292
98% 1125
99% 1226
100% 3778 (longest request)

= 2 =============
Document Length: 18 bytes

Concurrency Level: 10
Time taken for tests: 20.044 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 1660000 bytes
HTML transferred: 180000 bytes
Requests per second: 498.90 [#/sec] (mean)
Time per request: 20.044 [ms] (mean)
Time per request: 2.004 [ms] (mean, across all concurrent requests)
Transfer rate: 80.88 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 0 4
Processing: 3 19 5.4 19 46
Waiting: 3 19 5.3 19 46
Total: 5 20 5.3 19 47

Percentage of the requests served within a certain time (ms)
50% 19
66% 20
75% 22
80% 23
90% 27
95% 30
98% 34
99% 38
100% 47 (longest request)

= результат ======================
flup/uWSGI
Requests per second: 1 к 5
Transfer rate: 1 к 5

В основном 1 к 5!

Комментариев нет: