Skip to content

async-db test with python, gevent, postgresql and sqlalchemy

Notifications You must be signed in to change notification settings

gdamjan/async-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Setup

export PYTHONUSERBASE=$PWD/py-env
pip2 install --user -r requirements.txt

Prepare database

If you never had postgres setup:

sudo -u postgres initdb --locale en_US.UTF-8 -D /var/lib/postgres/data
sudo systemctl start postgresql

For mysql/mariadb just start it with sudo systemctl start mysqld, it'll connect using root on localhost which should work out of the box.

Test

Run the app:

uwsgi --ini uwsgi.ini --thr # to work with 1000 thread workers
uwsgi --ini uwsgi.ini --gev # to work with 1000 async gevent cores

Add --env DB=MYSQL to run tests against MySQL/MariaDB (using oursql + greenify).

Test requests:

time curl localhost:8080 -i & \
time curl localhost:8080 -i & \
time curl localhost:8080 -i & \
wait

Observations

The threading library must be patched when using gevent with SQLAlchemy, since the connection pool uses thread locks. Those locks will deadlock (huh) the interpreter udner gevent if not patched with gevent.monkey.patch_thread(). SQLAlchemy before 0.9.3 didn't have those locks, but it probably would fail strangely when used with normal threads.

About

async-db test with python, gevent, postgresql and sqlalchemy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages