4 from allmydata import uri, storage
5 from allmydata.immutable import upload
6 from allmydata.interfaces import DEFAULT_MAX_SEGMENT_SIZE
7 from allmydata.util import mathutil
9 def roundup(size, blocksize=4096):
10 return blocksize * mathutil.div_ceil(size, blocksize)
14 def __init__(self, length):
17 def seek(self, offset, whence=0):
23 self.fp = self.length - offset
27 def calc(filesize, params=(3,7,10), segsize=DEFAULT_MAX_SEGMENT_SIZE):
28 num_shares = params[2]
29 if filesize <= upload.Uploader.URI_LIT_SIZE_THRESHOLD:
30 urisize = len(uri.LiteralFileURI("A"*filesize).to_string())
34 u = upload.FileUploader(None) # XXX changed
36 # unfortunately, Encoder doesn't currently lend itself to answering
37 # this question without measuring a filesize, so we have to give it a
39 data = BigFakeString(filesize)
40 u.set_filehandle(data)
41 u.set_encryption_key("a"*16)
42 sharesize, blocksize = u.setup_encoder()
44 # 0x20 bytes of offsets
45 # 0x04 bytes of extension length
46 # 0x1ad bytes of extension (=429)
48 num_segments = mathutil.div_ceil(filesize, segsize)
49 num_share_hashes = int(math.log(mathutil.next_power_of_k(num_shares, 2),
51 sharesize = storage.allocated_size(sharesize, num_segments,
54 sharespace = num_shares * roundup(sharesize)
55 urisize = len(uri.pack_uri(storage_index="a"*32,
57 uri_extension_hash="a"*32,
58 needed_shares=params[0],
59 total_shares=params[2],
62 return urisize, sharesize, sharespace
65 filesize = int(sys.argv[1])
66 urisize, sharesize, sharespace = calc(filesize)
67 print "urisize:", urisize
68 print "sharesize: %10d" % sharesize
69 print "sharespace: %10d" % sharespace
70 print "desired expansion: %1.1f" % (1.0 * 10 / 3)
71 print "effective expansion: %1.1f" % (1.0 * sharespace / filesize)
75 while filesize < 2**20:
76 urisize, sharesize, sharespace = calc(int(filesize))
77 expansion = 1.0 * sharespace / int(filesize)
78 print "%d,%d,%d,%1.2f" % (int(filesize), urisize, sharespace, expansion)
79 filesize = filesize * 2**0.5
81 if __name__ == '__main__':
82 if sys.argv[1] == "chart":