1
+ """ Usage: python benchmark.py ["database backend list" | backend1] [backend2]
2
+
3
+ Import the backend (anydbm, sqlite by default) and run some performance
4
+ tests. Example:
5
+
6
+ test default anypy and sqlite backends
7
+
8
+ python benchmark.py
9
+
10
+ test mysql and sqlite backends
11
+
12
+ python benchmark.py mysql sqlite
13
+
14
+ or
15
+
16
+ python benchmark.py "mysql sqlite"
17
+
18
+ test all backends
19
+
20
+ python benchmark.py anydbm mysql postgresql sqlite
21
+
22
+
23
+ """
1
24
from __future__ import print_function
2
25
import sys , os , time
3
26
import importlib , signal , shutil
17
40
18
41
from test .db_test_base import config
19
42
43
+ # global for the default signal hander so
44
+ # my signal handler can reset before it raises signal.
20
45
int_sig_default_handler = None
21
46
22
47
def setupSchema (db , module ):
@@ -38,26 +63,39 @@ def setupSchema(db, module):
38
63
def rm_db_on_signal (sig , frame ):
39
64
print ("removing incomplete database %s due to interruption." %
40
65
config .DATABASE )
66
+
41
67
shutil .rmtree (config .DATABASE )
68
+
42
69
signal .signal (signal .SIGINT , int_sig_default_handler )
70
+ # re-raise the signal so the normal signal handling runs.
43
71
signal .raise_signal (signal .SIGTERM )
44
72
45
73
def main (backendname , time = time .time , numissues = 10 ):
46
74
global int_sig_default_handler
75
+
47
76
try :
48
77
backend = importlib .import_module ("roundup.backends.back_%s" %
49
78
backendname )
50
79
except ImportError :
80
+ print ("Unable to import %s backend." % backendname )
51
81
return
52
82
53
83
times = []
54
84
55
85
config .DATABASE = os .path .join ('_benchmark' , '%s-%s' % (backendname ,
56
86
numissues ))
87
+
88
+ config .RDBMS_NAME = "rounduptest_%s" % numissues
89
+
57
90
if not os .path .exists (config .DATABASE ):
58
91
int_sig_default_handler = signal .signal (signal .SIGINT , rm_db_on_signal )
59
92
db = backend .Database (config , 'admin' )
60
93
setupSchema (db , backend )
94
+
95
+ # if we are re-initializing, delete any existing db
96
+ db .clear ()
97
+ db .commit ()
98
+
61
99
# create a whole bunch of stuff
62
100
db .user .create (** {'username' : 'admin' , 'roles' : 'Admin' })
63
101
db .status .create (name = "unread" )
@@ -85,7 +123,7 @@ def main(backendname, time=time.time, numissues=10):
85
123
db = backend .Database (config , 'admin' )
86
124
setupSchema (db , backend )
87
125
88
- sys .stdout .write ('%7s : %-6d' % (backendname , numissues ))
126
+ sys .stdout .write ('%10s : %-6d' % (backendname [: 10 ] , numissues ))
89
127
sys .stdout .flush ()
90
128
91
129
times .append (('start' , time ()))
@@ -142,17 +180,35 @@ def main(backendname, time=time.time, numissues=10):
142
180
sys .stdout .flush ()
143
181
144
182
if __name__ == '__main__' :
183
+ if len (sys .argv ) == 2 :
184
+ test_databases = sys .argv [1 ].split ()
185
+ elif len (sys .argv ) > 2 :
186
+ test_databases = sys .argv [1 :]
187
+ else :
188
+ test_databases = ['anydbm' , 'sqlite' ]
189
+
145
190
# 0 1 2 3 4 5 6
146
191
# 01234567890123456789012345678901234567890123456789012345678901234
147
- print ('Test name fetch journl jprops lookup filter filtml TOTAL ' )
148
- for name in 'anydbm sqlite' . split () :
192
+ print ('Test name fetch journl jprops lookup filter filtml TOTAL ' )
193
+ for name in test_databases :
149
194
main (name )
150
- for name in 'anydbm sqlite' . split () :
195
+ for name in test_databases :
151
196
main (name , numissues = 20 )
152
- for name in 'anydbm sqlite' . split () :
197
+ for name in test_databases :
153
198
main (name , numissues = 100 )
199
+
154
200
# don't even bother benchmarking the dbm backends > 100!
155
- for name in 'sqlite' .split ():
201
+ try :
202
+ test_databases .remove ('anydbm' )
203
+ except ValueError :
204
+ # anydbm not present; this is fine
205
+ pass
206
+
207
+ for name in test_databases :
156
208
main (name , numissues = 1000 )
157
209
210
+ for name in test_databases :
211
+ main (name , numissues = 10000 )
212
+
213
+
158
214
# vim: set et sts=4 sw=4 :
0 commit comments