summaryrefslogtreecommitdiff
path: root/test/perf/poolload.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-08-04 06:21:58 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-08-04 06:21:58 +0000
commit8f94457e56450988d5e18f66ee33dcb26c749caa (patch)
tree34036557b8f009db542df0976dc225d1bbcfd809 /test/perf/poolload.py
parent2ca2c769cdf77ff8f1fdcf9ad7e606676fcffee3 (diff)
downloadsqlalchemy-8f94457e56450988d5e18f66ee33dcb26c749caa.tar.gz
adjustments to pool stemming from changes made for [ticket:224].
overflow counter should only be decremented if the connection actually succeeded. added a test script to attempt testing this.
Diffstat (limited to 'test/perf/poolload.py')
-rw-r--r--test/perf/poolload.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/perf/poolload.py b/test/perf/poolload.py
new file mode 100644
index 000000000..1b130f568
--- /dev/null
+++ b/test/perf/poolload.py
@@ -0,0 +1,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 = BoundMetaData(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) \ No newline at end of file