5 import arvados_testutil as tutil
6 import manifest_examples
7 from performance.performance_profiler import profiled
9 class CollectionBenchmark(run_test_server.TestCaseWithServers,
10 tutil.ArvadosBaseTestCase,
11 manifest_examples.ManifestExamples):
16 def list_recursive(cls, coll, parent_name=None):
17 if parent_name is None:
18 current_name = coll.stream_name()
20 current_name = '{}/{}'.format(parent_name, coll.name)
23 for item in cls.list_recursive(coll[name], current_name):
30 super(CollectionBenchmark, cls).setUpClass()
31 run_test_server.authorize_with('active')
32 cls.api_client = arvados.api('v1')
33 cls.keep_client = arvados.KeepClient(api_client=cls.api_client,
34 local_store=cls.local_store)
37 def profile_new_collection_from_manifest(self, manifest_text):
38 return arvados.collection.Collection(manifest_text)
41 def profile_new_collection_from_server(self, uuid):
42 return arvados.collection.Collection(uuid)
45 def profile_new_collection_copying_bytes_from_collection(self, src):
46 dst = arvados.collection.Collection()
47 with tutil.mock_keep_responses('x'*self.TEST_BLOCK_SIZE, 200):
48 for name in self.list_recursive(src):
49 with src.open(name) as srcfile, dst.open(name, 'w') as dstfile:
50 dstfile.write(srcfile.read())
54 def profile_new_collection_copying_files_from_collection(self, src):
55 dst = arvados.collection.Collection()
56 with tutil.mock_keep_responses('x'*self.TEST_BLOCK_SIZE, 200):
57 for name in self.list_recursive(src):
58 dst.copy(name, name, src)
62 def profile_collection_list_files(self, coll):
63 return sum(1 for name in self.list_recursive(coll))
65 def test_medium_sized_manifest(self):
66 """Exercise manifest-handling code.
68 Currently, this test puts undue emphasis on some code paths
69 that don't reflect typical use because the contrived example
70 manifest has some unusual characteristics:
74 * Every block is identical, so block caching patterns are
77 * Every file begins and ends at a block boundary.
81 'files_per_stream': 100,
82 'blocks_per_file': 20,
83 'bytes_per_block': self.TEST_BLOCK_SIZE,
85 my_manifest = self.make_manifest(**specs)
87 coll = self.profile_new_collection_from_manifest(my_manifest)
90 self.profile_new_collection_from_server(coll.manifest_locator())
92 num_items = self.profile_collection_list_files(coll)
93 self.assertEqual(num_items, specs['streams'] * specs['files_per_stream'])
95 self.profile_new_collection_copying_bytes_from_collection(coll)
97 self.profile_new_collection_copying_files_from_collection(coll)