summaryrefslogtreecommitdiff
path: root/test/perf/poolload.py
blob: 090827709da5d372ed680db0ce12e98a91e238ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# this program should open three connections.  then after five seconds, the remaining
# 45 threads should receive a timeout error.  then the program will just stop until
# ctrl-C is pressed.  it should *NOT* open a bunch of new connections.

from sqlalchemy import *
import sqlalchemy.pool as pool
import psycopg2 as psycopg
import thread,time
psycopg = pool.manage(psycopg,pool_size=2,max_overflow=1, timeout=5, echo=True)
print psycopg
db = create_engine('postgres://scott:tiger@127.0.0.1/test',pool=psycopg,strategy='threadlocal')
print db.connection_provider._pool
metadata = MetaData(db)

users_table = Table('users', metadata,
  Column('user_id', Integer, primary_key=True),
  Column('user_name', String(40)),
  Column('password', String(10)))
metadata.create_all()

class User(object):
    pass
usermapper = mapper(User, users_table)

#Then i create loads of threads and in run() of each thread:
def run():
    session = create_session()
    transaction = session.create_transaction()
    query = session.query(User)
    u1=query.select(User.c.user_id==3)
    
for x in range(0,50):
    thread.start_new_thread(run, ())

while True:
    time.sleep(5)