summaryrefslogtreecommitdiff
path: root/sandbox
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/stress.py28
-rw-r--r--sandbox/stress2.py42
-rw-r--r--sandbox/tzhalf.py9
3 files changed, 61 insertions, 18 deletions
diff --git a/sandbox/stress.py b/sandbox/stress.py
index bb31800..48e0a59 100644
--- a/sandbox/stress.py
+++ b/sandbox/stress.py
@@ -1,19 +1,11 @@
-import psycopg
-import psycopg.extras
+import psycopg2
+import threading, os, time, gc
-conn = psycopg.connect('dbname=test')
-#curs = conn.cursor()
-#curs.execute("CREATE TABLE itest (n int4)")
-
-#for i in xrange(10000000):
-# curs = conn.cursor()
-# curs.execute("INSERT INTO itest VALUES (1)")
-# curs.execute("SELECT '2003-12-12 10:00:00'::timestamp AS foo")
-# curs.execute("SELECT 'xxx' AS foo")
-# curs.fetchall()
-# curs.close()
-
-curs = conn.cursor(factory=psycopg.extras.DictCursor)
-curs.execute("select 1 as foo")
-x = curs.fetchone()
-print x['foo']
+for i in range(20000):
+ conn = psycopg2.connect('dbname=test')
+ del conn
+ if i%200 == 0:
+ datafile = os.popen('ps -p %s -o rss' % os.getpid())
+ line = datafile.readlines(2)[1].strip()
+ datafile.close()
+ print str(i) + '\t' + line
diff --git a/sandbox/stress2.py b/sandbox/stress2.py
new file mode 100644
index 0000000..0e36dfc
--- /dev/null
+++ b/sandbox/stress2.py
@@ -0,0 +1,42 @@
+import psycopg2
+
+import threading, os, time, gc
+
+super_lock = threading.Lock()
+
+def f():
+ try:
+ conn = psycopg2.connect('dbname=testx')
+ #c = db.cursor()
+ #c.close()
+ #conn.close()
+ del conn
+ except:
+ pass
+ #print "ERROR"
+
+def g():
+ n = 30
+ k = 0
+ i = 1
+ while i > 0:
+ while n > 0:
+ threading.Thread(target=f).start()
+ time.sleep(0.001)
+ threading.Thread(target=f).start()
+ time.sleep(0.001)
+ threading.Thread(target=f).start()
+ n -= 1
+ while threading.activeCount() > 1:
+ time.sleep(0.01)
+ datafile = os.popen('ps -p %s -o rss' % os.getpid())
+ line = datafile.readlines(2)[1].strip()
+ datafile.close()
+ n = 30
+ print str(k*n) + '\t' + line
+ k += 1
+
+ while threading.activeCount()>1:
+ pass
+
+g() \ No newline at end of file
diff --git a/sandbox/tzhalf.py b/sandbox/tzhalf.py
new file mode 100644
index 0000000..8e38441
--- /dev/null
+++ b/sandbox/tzhalf.py
@@ -0,0 +1,9 @@
+import datetime
+import time
+import psycopg2
+
+conn = psycopg2.connect("dbname=test")
+curs = conn.cursor()
+curs.execute("set timezone = 'Asia/Calcutta'")
+curs.execute("SELECT now()")
+print curs.fetchone()[0]