-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark-purge-store.py
executable file
·58 lines (50 loc) · 1.3 KB
/
benchmark-purge-store.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python3
import time
import logging
from usercouch.misc import TempCouch
from microfiber import Database, random_id
from filestore import DIGEST_BYTES
from dmedia.util import get_db
from dmedia.metastore import MetaStore, BufferedSave, TimeDelta
logging.basicConfig(level=logging.DEBUG)
couch = TempCouch()
env = couch.bootstrap()
db= get_db(env, True)
log_db = db.database('log-1')
log_db.ensure()
ms = MetaStore(db, log_db)
store_id1 = random_id()
store_id2 = random_id()
store_id3 = random_id()
count = 15 * 1000
buf = BufferedSave(db, 100)
print('Saving {} docs...'.format(count))
for i in range(count):
doc = {
'_id': random_id(DIGEST_BYTES),
'time': time.time(),
'type': 'dmedia/file',
'origin': 'user',
'atime': int(time.time()),
'bytes': 12345678,
'stored': {
store_id1: {
'copies': 1,
'mtime': int(time.time()),
},
store_id2: {
'copies': 2,
'mtime': int(time.time()),
},
store_id3: {
'copies': 1,
'mtime': int(time.time()),
},
},
}
buf.save(doc)
buf.flush()
t = TimeDelta()
ms.purge_all()
print('Rate: {} per second'.format(count * 3 // t.delta))
print('')