5
from os.path import join as opj
6
from os.path import isdir
8
from atop.store import Store, Item, SubStore
9
from atop.store import Pool, DateIndex, UIDIndex
10
from atop.store import ITEM, INDEX, STORE_ID
11
from atop.store import Inconsistency, NameIndex
12
from quotient import mimemessage
14
from twisted.trial import unittest
15
from twisted.cred.portal import Portal
16
from twisted.cred.credentials import UsernamePassword
17
from twisted.python.components import Interface
18
from twisted.python.util import sibpath
20
class BenchmarkStore(unittest.TestCase):
23
mailDirectory = os.environ.get("BENCH_MESSAGES") or "/home/amir/test/test150"
28
store = Store(opj(d, "db"), opj(d, "files"))
29
avatar = store.transact(SubStore, store)
31
for f in os.listdir(self.mailDirectory):
32
mp = mimemessage.MIMEMessageReceiver(avatar, self.msgs.append, True)
33
mp.feedFileNow(file(opj(self.mailDirectory, f)))
35
def benchmarkMessageInsertion(self):
37
s = Store(opj(p, "db"), opj(p, "files"))
40
# Insert all the messages nCopies times
41
for i in range(self.nCopies):
42
a = s.transact(SubStore, s)
44
path = a.storeID, a.nextID()
45
s.transact(s._saveItemToPath, m, a.storeID, a.nextID())
47
self.recordStat({"throughput": (len(self.msgs) / t, "Messages / second")})
49
def benchmarkBloat(self):
51
s = Store(opj(p, "db"), opj(p, "files"))
56
path = a.storeID, a.nextID()
57
s._saveItemToPath(m, a.storeID, a.nextID())
62
for fname in os.listdir(dname):
63
fname = opj(dname, fname)
64
s += os.stat(fname).st_size
68
dbSize = sizeOf(opj(p, "db"))
69
fSize = float(sizeOf(opj(p, "files")))
70
self.recordStat({"bloat": ((dbSize / fSize), "DB Size / Message Size")})