[Zodb-checkins] SVN: zodbbench/trunk/zodbbench/ Lots of fiddling,
and "a real" (ableit very simple) benchmark.
Tim Peters
tim.one at comcast.net
Thu Oct 6 16:47:31 EDT 2005
Log message for revision 38833:
Lots of fiddling, and "a real" (ableit very simple) benchmark.
Changed:
A zodbbench/trunk/zodbbench/benchmarks/
A zodbbench/trunk/zodbbench/benchmarks/__init__.py
A zodbbench/trunk/zodbbench/benchmarks/one_minute_commit.py
U zodbbench/trunk/zodbbench/utils.py
-=-
Added: zodbbench/trunk/zodbbench/benchmarks/__init__.py
===================================================================
--- zodbbench/trunk/zodbbench/benchmarks/__init__.py 2005-10-06 20:45:56 UTC (rev 38832)
+++ zodbbench/trunk/zodbbench/benchmarks/__init__.py 2005-10-06 20:47:31 UTC (rev 38833)
@@ -0,0 +1 @@
+# Makes this a package.
Property changes on: zodbbench/trunk/zodbbench/benchmarks/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zodbbench/trunk/zodbbench/benchmarks/one_minute_commit.py
===================================================================
--- zodbbench/trunk/zodbbench/benchmarks/one_minute_commit.py 2005-10-06 20:45:56 UTC (rev 38832)
+++ zodbbench/trunk/zodbbench/benchmarks/one_minute_commit.py 2005-10-06 20:47:31 UTC (rev 38833)
@@ -0,0 +1,66 @@
+############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+############################################################################
+
+"""How many commits can we finish in one minute?
+
+This starts with an empty database and an empty IIBTree t. Then it does:
+
+ i = 0
+ while less than a minute has passed:
+ t[i] = i
+ commit
+ i += 1
+
+and reports on how many commits it completed in one minute.
+"""
+
+from BTrees.IIBTree import IIBTree
+
+from zodbbench.utils import now, tcommit, BenchBase
+
+class OneMinute(BenchBase):
+ name = "one-minute commit"
+
+ def __init__(self):
+ self.open_fs()
+
+ def drive(self):
+ try:
+ t = self.conn.root()['tree'] = IIBTree()
+ i = 0
+ start = now()
+ deadline = start + 60 # one minute
+ while now() < deadline:
+ t[i] = i
+ tcommit()
+ i += 1
+ self.elapsed = now() - start
+ self.ntransactions = i
+ finally:
+ self.close_and_delete()
+
+ def report(self):
+ msg = "Did %d commits in %.1f seconds, for %.2f txn/sec." % (
+ self.ntransactions,
+ self.elapsed,
+ self.ntransactions / self.elapsed)
+ BenchBase.report(self, msg)
+
+def main():
+ om = OneMinute()
+ om.drive()
+ om.report()
+
+if __name__ == "__main__":
+ main()
Property changes on: zodbbench/trunk/zodbbench/benchmarks/one_minute_commit.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: zodbbench/trunk/zodbbench/utils.py
===================================================================
--- zodbbench/trunk/zodbbench/utils.py 2005-10-06 20:45:56 UTC (rev 38832)
+++ zodbbench/trunk/zodbbench/utils.py 2005-10-06 20:47:31 UTC (rev 38833)
@@ -20,8 +20,10 @@
"""
import sys
+import tempfile
import ZODB
+from ZODB.FileStorage import FileStorage
__all__ = ['tcommit', # commit current transaction
'tabort', # abort current transaction
@@ -31,13 +33,16 @@
# an approximation to the best-resolution wall-clock timer
# available.
'now', # time.clock on Windows, time.time elsewhere
+
+ # A base class for benchmarks, capturing some common needs.
+ 'BenchBase',
]
# Figure out which version of ZODB is in use.
first_two = map(int, ZODB.__version__.split('.')[:2])
assert len(first_two) == 2
-if first_two <= (3, 2):
+if first_two <= [3, 2]:
# ZODB 3.2.0 or earlier.
# `get_transaction` magically appears in __builtin__ as a result of
@@ -59,11 +64,58 @@
del transaction
+del first_two
+
if sys.platform == "win32":
from time import clock as now
else:
from time import time as now
-del sys
-del ZODB
-del first_two
\ No newline at end of file
+class BenchBase(object):
+ name = None # subclass should override with benchmark name
+
+ def open_fs(self, path=None):
+ """Open a FileStorage.
+
+ If `path` is None (the default), a new FileStorage is created
+ in a temp directory.
+
+ These attributes are set on `self`:
+
+ path path to the .fs file
+ storage the FileStorage instance
+ db DB(storage)
+ conn db.open(), a connection to the FileStorage
+ """
+
+ if path is None:
+ self.path = tempfile.mktemp(suffix=".fs")
+ else:
+ self.path = path
+ self.storage = FileStorage(self.path)
+ self.db = ZODB.DB(self.storage)
+ self.conn = self.db.open()
+
+ def close_and_delete(self):
+ "Close self.db and delete files associated with the storage."""
+
+ self.db.close()
+
+ # Storage .cleanup methods delete all files associated with a
+ # storage (like .fs, .index, .lock, etc). They generally don't
+ # exist before ZODB 3.2, though.
+ self.storage.cleanup()
+
+
+ def report(self, msg):
+ """Display a report to stdout.
+
+ The starts by listing the name of the benchmark (self.name),
+ then gives the Python and ZODB versions in use, and then displays
+ `msg`.
+ """
+
+ print "Benchmark", self.name
+ print "Python version:", sys.version
+ print "ZODB version:", ZODB.__version__
+ print msg
More information about the Zodb-checkins
mailing list