Statistics
| Branch: | Tag: | Revision:

root / pithos / lib / hashfiler / blocker_test.py @ 5bd53e3b

History | View | Annotate | Download (1.6 kB)

1
#!/usr/bin/env python
2

    
3
from random import getrandbits, randint, seed
4
from time import time
5
from struct import pack
6
from sys import argv
7
from os import system
8

    
9
from pithos.lib.hashfiler import Blocker
10

    
11
blocksize = 4*1024*1024
12
#blocker = Blocker(blockroot=".blocker.test", blocksize=blocksize, hashtype='sha256')
13
blocker = Blocker(**{'blockroot':".blocker.test", 'blocksize':blocksize, 'hashtype':'sha256'})
14

    
15
seed(91489)
16
NR_BLOCKS = int(argv[1]) if len(argv) > 1 else 300
17

    
18
def get_rand_bytes(low, high):
19
    s = ''
20
    nr = randint(low, high)
21
    for i in xrange(0, nr, 1024):
22
        r = getrandbits(64)
23
        s += pack("@Q", r) * 128
24

    
25
    if len(s) > nr:
26
        s = s[:nr]
27

    
28
    return s
29

    
30
data = {}
31
blocks = []
32
append = blocks.append
33

    
34
t = time()
35
size = 0
36
for i in xrange(NR_BLOCKS):
37
    block = get_rand_bytes(256, blocksize)
38
    size += len(block)
39
    append(block)
40
t = time() - t
41
print ("generated %s random blocks of total %s bytes in %s seconds, %.0f bytes/sec" % 
42
       (NR_BLOCKS, size, t, size/t))
43

    
44
t = time()
45
hashes, stored = blocker.block_stor(blocks)
46
system("sync")
47
t = time() - t
48
print ("stored %s blocks of total %s bytes in %s seconds, %.0f bytes/sec" % 
49
       (NR_BLOCKS, size, t, size/t))
50

    
51
assert(len(hashes) == len(stored))
52

    
53
t = time()
54
missing = blocker.block_ping(hashes)
55
t = time() - t
56
print ("pinged %s blocks in %s seconds, %.0f blocks/sec" % 
57
       (NR_BLOCKS, t, NR_BLOCKS/t))
58

    
59
assert(len(missing) == 0)
60

    
61
t = time()
62
theblocks = blocker.block_retr(hashes)
63
t = time() - t
64
print ("retrieved %s blocks of %s total bytes in %s seconds, %.0f bytes/sec" % 
65
       (NR_BLOCKS, size, t, size/t))
66

    
67
assert(theblocks == blocks)
68