-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0786c60
commit 1701070
Showing
18 changed files
with
103 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
app = flask.Flask("python-web-perf") | ||
|
||
pool = None | ||
|
||
@app.route("/test") | ||
def test(): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,14 @@ | ||
import random | ||
import aiopg | ||
|
||
pool = None | ||
|
||
async def get_pool(): | ||
global pool | ||
if pool is None: | ||
pool = await aiopg.create_pool( | ||
"dbname=test user=test password=test port=5432 host=perf-db") | ||
return pool | ||
|
||
max_n = 1000_000 - 1 | ||
|
||
|
||
async def get_row(): | ||
pool = await get_pool() | ||
async with pool.acquire() as conn: | ||
async with aiopg.connect(dbname='test', user='test', password='test', port=5432, host='perf-dbpool') as conn: | ||
async with conn.cursor() as cursor: | ||
index = random.randint(1, max_n) | ||
await cursor.execute("select a, b from test where a = %s", (index,)) | ||
#await cursor.execute("select pg_sleep(0.01); select a, b from test where a = %s", (index,)) | ||
((a, b),) = await cursor.fetchall() | ||
return a, b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import psycopg2 | ||
from psycopg2 import extensions | ||
|
||
from meinheld import trampoline | ||
|
||
def patch_psycopg(): | ||
"""Configure Psycopg to be used with eventlet in non-blocking way.""" | ||
if not hasattr(extensions, 'set_wait_callback'): | ||
raise ImportError( | ||
"support for coroutines not available in this Psycopg version (%s)" | ||
% psycopg2.__version__) | ||
|
||
extensions.set_wait_callback(wait_callback) | ||
|
||
def wait_callback(conn, timeout=-1): | ||
"""A wait callback useful to allow eventlet to work with Psycopg.""" | ||
while 1: | ||
state = conn.poll() | ||
if state == extensions.POLL_OK: | ||
break | ||
elif state == extensions.POLL_READ: | ||
trampoline(conn.fileno(), read=True) | ||
elif state == extensions.POLL_WRITE: | ||
trampoline(conn.fileno(), write=True) | ||
else: | ||
raise psycopg2.OperationalError( | ||
"Bad result from poll: %r" % state) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
import os | ||
import psycopg2 | ||
import psycopg2.pool | ||
import random | ||
|
||
pool = None | ||
|
||
def get_pool(): | ||
global pool | ||
if pool is None: | ||
pool = psycopg2.pool.SimpleConnectionPool( | ||
1, 4, database="test", user="test", password="test", port=5432, | ||
host='perf-db', | ||
) | ||
return pool | ||
|
||
if os.getenv('USE_MEINHELD'): | ||
from meinheld_psycopg2 import patch_psycopg | ||
patch_psycopg() | ||
elif os.getenv('USE_GEVENT'): | ||
from psycogreen.gevent import patch_psycopg | ||
patch_psycopg() | ||
|
||
max_n = 1000_000 - 1 | ||
|
||
|
||
def get_row(): | ||
conn = get_pool().getconn() | ||
conn = psycopg2.connect(dbname='test', user='test', password='test', | ||
port=5432, host='perf-dbpool') | ||
cursor = conn.cursor() | ||
index = random.randint(1, max_n) | ||
cursor.execute("select a, b from test where a = %s;", (index,)) | ||
#cursor.execute("select pg_sleep(0.01); select a, b from test where a = %s;", (index,)) | ||
((a, b),) = cursor.fetchall() | ||
cursor.close() | ||
get_pool().putconn(conn) | ||
conn.commit() | ||
conn.close() | ||
return a, b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"test" "md505a671c66aefea124cc08b76ea6d30bb" | ||
"postgres" "md53175bce1d3201d16594cebf9d7eb3f9d" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ uwsgi | |
aiopg | ||
psycopg2-binary | ||
gevent | ||
psycogreen | ||
meinheld | ||
falcon | ||
sanic | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
gunicorn --bind :8001 -w $PWPWORKERS app_bottle:app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
gunicorn --bind :8001 -w $PWPWORKERS app_falcon:app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
export USE_GEVENT=1 | ||
gunicorn --bind :8001 -w $PWPWORKERS app_bottle:app --worker-class gunicorn.workers.ggevent.GeventWorker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
export USE_GEVENT=1 | ||
gunicorn --bind :8001 -w $PWPWORKERS app_falcon:app --worker-class gunicorn.workers.ggevent.GeventWorker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
export USE_GEVENT=1 | ||
gunicorn --bind :8001 -w $PWPWORKERS app_flask:app --worker-class gunicorn.workers.ggevent.GeventWorker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
export USE_MEINHELD=1 | ||
gunicorn --bind :8001 -w $PWPWORKERS app_bottle:app --worker-class "egg:meinheld#gunicorn_worker" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
export USE_MEINHELD=1 | ||
gunicorn --bind :8001 -w $PWPWORKERS app_falcon:app --worker-class "egg:meinheld#gunicorn_worker" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
export USE_MEINHELD=1 | ||
gunicorn --bind :8001 -w $PWPWORKERS app_flask:app --worker-class "egg:meinheld#gunicorn_worker" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters