Category Archives: Uncategorized

Running Flask with Gunicorn

Been playing with Python Flask writing some backend REST API for our game backend.
Trying to work on deploying the API using Gunicorn using gevent

sudo apt-get install libevent-1.4-2
sudo apt-get install libevent-dev

easy_install greenlet
easy_install gevent

My Gunicorn config file:

$ cat gunicorn.py 

import os

def numCPUs():
    if not hasattr(os, "sysconf"):
        raise RuntimeError("No sysconf detected.")
    return os.sysconf("SC_NPROCESSORS_ONLN")

bind = "0.0.0.0:8000"
workers = numCPUs() * 2 + 1
backlog = 2048
#worker_class ="sync"
worker_class =  "gevent" 
debug = True
daemon = True
pidfile ="/tmp/gunicorn.pid"
logfile ="/tmp/gunicorn.log"

Running the Flask Application:

$ gunicorn -c gunicorn.py mp:app 
$ tail /tmp/gunicorn.log
2011-04-19 10:33:40 [1594] [INFO] Starting gunicorn 0.12.1
2011-04-19 10:33:40 [1594] [INFO] Listening at: http://0.0.0.0:8000 (1594)
2011-04-19 10:33:40 [1594] [INFO] Using worker: gevent
2011-04-19 10:33:40 [1595] [INFO] Booting worker with pid: 1595
2011-04-19 10:33:40 [1596] [INFO] Booting worker with pid: 1596
2011-04-19 10:33:40 [1597] [INFO] Booting worker with pid: 1597

Woops.. seems working.
Time to run load testing with ab and siege.

Amazon RDS: Rotating slow_log and general_log

Using RDS with slow_log enabled and encountering this error:
mysql> select * from slow_log;
ERROR 1194 (HY000): Table ‘slow_log’ is marked as crashed and should be repaired

Fixed by:
mysql> CALL mysql.rds_rotate_slow_log;

If the same error happens when general_log is enabled, we can use:
mysql> CALL mysql.rds_rotate_general_log;

These two commands are needed to be run periodically (assuming slow_log and general_log are enabled). If the logs are getting bigger, it may affects performance of the RDS instance.