Commit 83c69678 authored by Levin Zimmermann's avatar Levin Zimmermann

Demonstrate how resizing needs less disk space than creating orphans

parents
import os
import sys
from golang import defer, func
import numpy as np
import transaction
import ZODB, ZODB.FileStorage
from wendelin.bigarray.array_zodb import ZBigArray
storage_path = "tzbigarray.fs"
try:
os.remove(storage_path)
except:
pass
@func
def root(func):
storage = ZODB.FileStorage.FileStorage(storage_path, pack_gc=False)
db = ZODB.DB(storage)
connection = db.open()
root = connection.root
defer(connection.close)
defer(db.close)
defer(storage.close)
func(root, storage, db)
def t(root, storage, db):
def _(msg):
print(msg + '\n')
#print("array: %s" % str(arr[:]))
print("\tshape: %s" % str(arr.shape))
print("\tstorage length: %s" % len(storage))
print("\tstorage size: %s" % _getstoragesize())
print('\n')
arr = root.zbigarray = ZBigArray(shape=[0, 2], dtype=int)
transaction.commit()
_("Create new ZBigArray")
_append_zblk(arr)
_("Append ~one ZBlk to ZBigAray")
db.pack()
_("Pack database (1)")
arr.resize((0, 2))
transaction.commit()
_("Resize array (set length to 0)")
_append_zblk(arr)
_("Add new data again to array (to have same size as before)")
db.pack()
_("Pack database (2)")
_append_zblk(arr)
_("Add more new data")
db.pack()
_("Pack database (3)")
def _append_zblk(arr, size=2):
elements = 200000 # roughly the size of 1xZBlk0
arr.append([[0 for _ in range(size)] for _ in range(int(elements / size))])
transaction.commit()
def _getstoragesize():
return os.path.getsize(storage_path)
if __name__ == "__main__":
root(t)
import os
import sys
from golang import defer, func
import numpy as np
import transaction
import ZODB, ZODB.FileStorage
from wendelin.bigarray.array_zodb import ZBigArray
storage_path = "tzbigarray.fs"
try:
os.remove(storage_path)
except:
pass
@func
def root(func):
storage = ZODB.FileStorage.FileStorage(storage_path, pack_gc=False)
db = ZODB.DB(storage)
connection = db.open()
root = connection.root
defer(connection.close)
defer(db.close)
defer(storage.close)
func(root, storage, db)
def t(root, storage, db):
def _(msg):
print(msg + '\n')
#print("array: %s" % str(arr[:]))
print("\tshape: %s" % str(arr.shape))
print("\tstorage length: %s" % len(storage))
print("\tstorage size: %s" % _getstoragesize())
print('\n')
arr = root.zbigarray = ZBigArray(shape=[0, 2], dtype=int)
transaction.commit()
_("Create new ZBigArray (1)")
_append_zblk(arr)
_("Append ~one ZBlk to ZBigAray")
db.pack()
_("Pack database (1)")
root.zbigarray = None
transaction.commit()
_("De-refer initial ZBigArray")
arr = root.zbigarray = ZBigArray(shape=[0, 2], dtype=int)
transaction.commit()
_("Create new ZBigArray (2)")
_append_zblk(arr)
_("Add new data to newly created array")
db.pack()
_("Pack database (2)")
_append_zblk(arr)
_("Add more new data")
db.pack()
_("Pack database (3)")
def _append_zblk(arr, size=2):
elements = 200000 # roughly the size of 1xZBlk0
arr.append([[0 for _ in range(size)] for _ in range(int(elements / size))])
transaction.commit()
def _getstoragesize():
return os.path.getsize(storage_path)
if __name__ == "__main__":
root(t)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment