1
##############################################################################
3
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
6
# This software is subject to the provisions of the Zope Public License,
7
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE
13
##############################################################################
14
usage="""Test speed of a ZODB storage
18
-d file The data file to use as input.
19
The default is this script.
21
-n n The number of repititions
23
-s module A module that defines a 'Storage'
24
attribute, which is an open storage.
25
If not specified, a FileStorage will ne
28
-z Test compressing data
32
-L Test loads as well as stores by minimizing
33
the cache after eachrun
37
-C Run with a persistent client cache
39
-U Run ZEO using a Unix domain socket
41
-t n Number of concurrent threads to run.
45
import sys, os, getopt, time
46
##sys.path.insert(0, os.getcwd())
51
from ZODB.POSException import ConflictError
52
from ZEO.tests import forker
54
class P(persistent.Persistent):
57
fs_name = "zeo-speed.fs"
59
class ZEOExit(asyncore.file_dispatcher):
60
"""Used to exit ZEO.StorageServer when run is done"""
65
def handle_read(self):
70
def handle_close(self):
71
print "Parent process exited unexpectedly"
76
os.unlink(fs_name + ".lock")
77
os.unlink(fs_name + ".tmp")
79
def work(db, results, nrep, compress, data, detailed, minimize, threadno=None):
81
for r in 1, 10, 100, 1000:
96
v = getattr(p, str(i), P())
97
if compress is not None:
101
setattr(p, str(i), v)
103
except ConflictError:
104
conflicts = conflicts + 1
112
print "%s\t%s\t%.4f\t%d" % (j, r, t, conflicts)
114
print "%s\t%s\t%.4f\t%d\t%d" % (j, r, t, conflicts,
116
results[r].append((t, conflicts))
117
rt=d=p=v=None # release all references
123
opts, args = getopt.getopt(args, 'zd:n:Ds:LMt:U')
134
if o=='-n': nrep = int(v)
135
elif o=='-d': data = v
139
compress = zlib.compress
146
os.environ['STUPID_LOG_FILE']=''
147
os.environ['STUPID_LOG_SEVERITY']='-999'
158
s = __import__(s, globals(), globals(), ('__doc__',))
162
s, server, pid = forker.start_zeo("FileStorage",
163
(fs_name, 1), domain=domain)
165
data=open(data).read()
167
# disable cache deactivation
169
cache_deactivate_after=6000,)
171
print "Beginning work..."
172
results={1:[], 10:[], 100:[], 1000:[]}
176
for i in range(threads):
177
t = threading.Thread(target=work,
178
args=(db, results, nrep, compress, data,
179
detailed, minimize, i))
187
work(db, results, nrep, compress, data, detailed, minimize)
189
if server is not None:
195
print "num\tmean\tmin\tmax"
196
for r in 1, 10, 100, 1000:
198
for time, conf in results[r]:
201
print "%d\t%.4f\t%.4f\t%.4f" % (r, t, min(times), max(times))
210
## c = zlib.compressobj()
212
## return o + c.flush()
214
if __name__=='__main__':