2 # This example measures the performance of encrypted
3 # storage access through Amazon Simple Storage Service
6 # In order to run this example, you must provide a valid
7 # S3 bucket name and have the following variables defined
8 # in your current environment:
10 # - AWS_SECRET_ACCESS_KEY
11 # - AWS_DEFAULT_REGION
12 # These can also be set using keywords.
20 from pyoram.util.misc import MemorySize
21 from pyoram.encrypted_storage.encrypted_block_storage import \
26 pyoram.SHOW_PROGRESS_BAR = True
28 # Set S3 bucket name here
29 # (by default, we pull this from the environment
30 # for testing purposes)
31 bucket_name = os.environ.get('PYORAM_AWS_TEST_BUCKET')
33 # Set the storage location and size
34 storage_name = "heap.bin"
37 # one block per bucket in the
38 # storage heap of height 8
39 block_count = 2**(8+1)-1
43 print("Storage Name: %s" % (storage_name))
44 print("Block Count: %s" % (block_count))
45 print("Block Size: %s" % (MemorySize(block_size)))
46 print("Total Memory: %s"
47 % (MemorySize(block_size*block_count)))
48 print("Actual Storage Required: %s"
50 EncryptedBlockStorage.compute_storage_size(
56 print("Setting Up Encrypted Block Storage")
57 setup_start = time.time()
58 with EncryptedBlockStorage.setup(storage_name,
62 bucket_name=bucket_name,
63 ignore_existing=True) as f:
64 print("Total Setup Time: %2.f s"
65 % (time.time()-setup_start))
66 print("Total Data Transmission: %s"
67 % (MemorySize(f.bytes_sent + f.bytes_received)))
70 # We close the device and reopen it after
71 # setup to reset the bytes sent and bytes
73 with EncryptedBlockStorage(storage_name,
76 bucket_name=bucket_name) as f:
79 start_time = time.time()
80 for t in tqdm.tqdm(list(range(test_count)),
81 desc="Running I/O Performance Test"):
82 f.read_block(random.randint(0,f.block_count-1))
83 stop_time = time.time()
84 print("Access Block Avg. Data Transmitted: %s (%.3fx)"
85 % (MemorySize((f.bytes_sent + f.bytes_received)/float(test_count)),
86 (f.bytes_sent + f.bytes_received)/float(test_count)/float(block_size)))
87 print("Access Block Avg. Latency: %.2f ms"
88 % ((stop_time-start_time)/float(test_count)*1000))
91 if __name__ == "__main__":
92 main() # pragma: no cover