Last active
August 29, 2015 14:05
-
-
Save mwatts15/9dbe431d8e76d79de415 to your computer and use it in GitHub Desktop.
How long does it take to open and close a Sleepycat (Berkeley DB) store versus a persisted ZODB store?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rdflib as R | |
from subprocess import call | |
from time import time | |
def median(mylist): | |
# from http://stackoverflow.com/questions/10482339/how-to-find-median | |
sorts = sorted(mylist) | |
length = len(sorts) | |
if not length % 2: | |
return (sorts[length / 2] + sorts[length / 2 - 1]) / 2.0 | |
return sorts[length / 2] | |
def main(): | |
print "Spinning wheels..." | |
times = [] | |
for x in range(100): | |
this_file = __file__ | |
this_db = this_file + '.db' | |
t0=time() | |
s = R.ConjunctiveGraph('Sleepycat') | |
s.open(this_db, create=True) | |
s.close() | |
call('rm -rf '+this_db, shell=True) | |
t1=time() | |
times.append(t1-t0) | |
print 'total time:',sum(times) | |
print 'average time for (up/down):', sum(times)/len(times) | |
print 'median time for (up/down):', median(times) | |
if __name__ == '__main__': | |
main() | |
# Output on | |
# CPU | |
# vendor_id : GenuineIntel | |
# cpu family : 6 | |
# model : 42 | |
# model name : Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz | |
# Disk | |
# description: ATA Disk | |
# product: SAMSUNG HM641JI | |
# | |
# Spinning wheels... | |
# total time: 150.357907772 | |
# average time for (up/down): 1.50357907772 | |
# median time for (up/down): 1.53333353996 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rdflib as R | |
import ZODB | |
import os | |
import transaction | |
from ZODB.FileStorage import FileStorage | |
from subprocess import call | |
from time import time | |
def median(mylist): | |
# from http://stackoverflow.com/questions/10482339/how-to-find-median | |
sorts = sorted(mylist) | |
length = len(sorts) | |
if not length % 2: | |
return (sorts[length / 2] + sorts[length / 2 - 1]) / 2.0 | |
return sorts[length / 2] | |
def main(): | |
print "Spinning wheels..." | |
times = [] | |
for x in range(100): | |
this_file = __file__ | |
this_db = this_file + '.db' | |
t0=time() | |
fs=FileStorage(this_db) | |
zdb=ZODB.DB(fs) | |
conn=zdb.open() | |
root=conn.root() | |
if 'rdflib' not in root: | |
root['rdflib'] = R.ConjunctiveGraph('ZODB') | |
graph = root['rdflib'] | |
try: | |
transaction.commit() | |
except Exception as e: | |
# catch commit exception and close db. | |
# otherwise db would stay open and follow up tests | |
# will detect the db in error state | |
print 'Forced to abort transaction on ZODB store opening' | |
transaction.abort() | |
transaction.begin() | |
graph.open(this_db) | |
graph.close() | |
try: | |
transaction.commit() | |
except Exception as e: | |
# catch commit exception and close db. | |
# otherwise db would stay open and follow up tests | |
# will detect the db in error state | |
traceback.print_exc() | |
L.warning('Forced to abort transaction on ZODB store closing') | |
transaction.abort() | |
conn.close() | |
zdb.close() | |
os.unlink(this_db) | |
os.unlink(this_db + '.index') | |
os.unlink(this_db + '.tmp') | |
os.unlink(this_db + '.lock') | |
t1=time() | |
times.append(t1-t0) | |
print 'total time:',sum(times) | |
print 'average time for (up/down):', sum(times)/len(times) | |
print 'median time for (up/down):', median(times) | |
if __name__ == '__main__': | |
main() | |
# Output on | |
# CPU | |
# vendor_id : GenuineIntel | |
# cpu family : 6 | |
# model : 42 | |
# model name : Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz | |
# Disk | |
# description: ATA Disk | |
# product: SAMSUNG HM641JI | |
# | |
# Spinning wheels... | |
# total time: 9.39678382874 | |
# average time for (up/down): 0.0939678382874 | |
# median time for (up/down): 0.0895910263062 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment