2. June 2013

Configure Nginx with uWSGI to serve Pootle

It’s quite easy to set up Pootle. Just follow the manual – Quickstart.

virtualenv /var/www/pootle/env/
 source /var/www/pootle/env/bin/activate
 (env) $ pip install pootle
 (env) $ pootle init
 (env) $ pootle syncdb --noinput
 (env) $ pootle initdb

You can start Pootle with default CherryPy server. In order to boost performance it is necessary to use more powerfull server.

Let’s take intermediate step and serve Pootle by uWSGI.

First of all you’ll need to create wsgi.py file, because this file is missing in default Pootle installation. File: /var/www/pootle/wsgi.py

import os

# this part is only required when running from checkout instead of an install
try:
    import sys
    ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
    sys.path.insert(0, ROOT_DIR) # Top level directory
    import syspath_override
except ImportError:
    # not running from checkout
    pass

# comment the above lines if running from install

os.environ['DJANGO_SETTINGS_MODULE'] = 'pootle.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

You can start uWSGI server by following command:

uwsgi --socket 127.0.0.1:3031 --chdir /var/www/pootle/lib/python2.7/site-packages/pootle --wsgi-file wsgi.py --master --virtualenv /var/www/pootle/ --http ":9090"

This will create uWSGI server and you can test it by connecting to http://localhost:9090

Let’s take further step and configure Nginx to server Pootle. We can modify previous command, because we do not need to server it as http at port 9090:

uwsgi --socket 127.0.0.1:3031 --chdir /var/www/pootle/lib/python2.7/site-packages/pootle --wsgi-file wsgi.py --master --virtualenv /var/www/pootle/

Create webroot directory where you will put static assets, just to avoid information leackage. Store there symlinks to assets and static files.

mkdir /var/www/pootle/webroot
ln -s /var/www/pootle/lib/python2.7/site-packages/pootle/assets /var/www/pootle/webroot/
ln -s /var/www/pootle/lib/python2.7/site-packages/pootle/static /var/www/pootle/webroot/

Store configuration to /etc/nginx/sites-available and create symlink to /etc/nginx/sites-enabled. Configuration of site:

upstream emperor {
  server 127.0.0.1:3031;
}

server {
  listen 80;
  server_name pootle.sinusgear.com;
  root /var/www/pootle/webroot;

  access_log /var/log/nginx/pootle.sinusgear.com_access.log;
  error_log /var/log/nginx/pootle.sinusgear.com_error.log;

  location / {
    location ~* ^.+\.$ {
      root /var/www/pootle/webroot/static/styles;
      expires 30d;
    }
    try_files $uri @django;
  }

  location @django {
    root /var/www/pootle;
    include uwsgi_params;
    uwsgi_param UWSGI_FASTROUTER_KEY $host;
    uwsgi_pass emperor;
  }

  location = /robots.txt {
    root /var/www/pootle/webroot/static/;
    access_log off;
  }

  location ~* ^.+\.py$ {
    return 404;
  }
}

Reload Nginx and Pootle should be much faster 🙂

I recommend book Mastering Nginx. You can learn there much more about Nginx configuration.

29. May 2013

Solution: KVM guest IO very slow

One problem of virtual server based on qemu KVM is that IO operations are slow in some cases.

The most common reason is that virtual disks are stored on RAID and virtual is using default HDD configuration.

It is recommended to turn off cache and set io operations to native:

<driver name='qemu' type='raw' cache='none' io='native'/>

There is very good article at serverfault. You can find there further explanations.

7. March 2012

Web stress test by Apache Benchmarking Tool

Sometimes you need to identify bottleneck of web application.

You can use Selenium to record and repeat the same steps over and over.

Another solution is to use Apache Benchmarking Tool.

E.g. You need to send 1000 requests in 10 concurrent threads to localhost:

ab -c 10 -n 1000 http://localhost/

For Debian users: you can find this mighty command in apache2-utils package.

Sample result:

Server Software:        Apache-Coyote/1.1
Server Hostname:        localhost
Server Port:            80

Document Path:          /
Document Length:        405 bytes

Concurrency Level:      10
Time taken for tests:   0.524 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      650000 bytes
HTML transferred:       405000 bytes
Requests per second:    1907.13 [#/sec] (mean)
Time per request:       5.243 [ms] (mean)
Time per request:       0.524 [ms] (mean, across all concurrent requests)
Transfer rate:          1210.58 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   0.5      2       4
Processing:     0    3   0.5      3       4
Waiting:        0    2   0.7      2       4
Total:          2    5   0.3      5       8

14. June 2011

Air 2.7 – performance improvement for iOS apps

AIR 2.7 was released! Many new things and improvements. AIR now supports Mac, Win, Android and Blackberry devices.

You can use JavaScript, ActionScript, HTML, MXML or native code to build your application.

See full article at blogs.adobe.com.

3. June 2011

Gotcha – performance on iOS and Android – Flash Builder – debug vs release

Several developers mentioned tricky gotcha of Flex and ActionScript apps on iOS and Android.

Flash Builder produces debug version of code by default. Debug code contains a lot of additional stuff that slow down application on target device. E.g. You’ll get 5-8 fps. That is very poor.

In order to test performance make sure that you’re using release version of project without debug information. Same code will work much faster – e.g. 20-24 fps.