1 from __future__ import absolute_import
5 from . import run_test_server
6 from . import arvados_testutil as tutil
7 from . import manifest_examples
8 from .performance.performance_profiler import profiled
10 class CollectionBenchmark(run_test_server.TestCaseWithServers,
11 tutil.ArvadosBaseTestCase,
12 manifest_examples.ManifestExamples):
17 def list_recursive(cls, coll, parent_name=None):
18 if parent_name is None:
19 current_name = coll.stream_name()
21 current_name = '{}/{}'.format(parent_name, coll.name)
24 for item in cls.list_recursive(coll[name], current_name):
31 super(CollectionBenchmark, cls).setUpClass()
32 run_test_server.authorize_with('active')
33 cls.api_client = arvados.api('v1')
34 cls.keep_client = arvados.KeepClient(api_client=cls.api_client,
35 local_store=cls.local_store)
38 def profile_new_collection_from_manifest(self, manifest_text):
39 return arvados.collection.Collection(manifest_text)
42 def profile_new_collection_from_server(self, uuid):
43 return arvados.collection.Collection(uuid)
46 def profile_new_collection_copying_bytes_from_collection(self, src):
47 dst = arvados.collection.Collection()
48 with tutil.mock_keep_responses('x'*self.TEST_BLOCK_SIZE, 200):
49 for name in self.list_recursive(src):
50 with src.open(name, 'rb') as srcfile, dst.open(name, 'wb') as dstfile:
51 dstfile.write(srcfile.read())
55 def profile_new_collection_copying_files_from_collection(self, src):
56 dst = arvados.collection.Collection()
57 with tutil.mock_keep_responses('x'*self.TEST_BLOCK_SIZE, 200):
58 for name in self.list_recursive(src):
59 dst.copy(name, name, src)
63 def profile_collection_list_files(self, coll):
64 return sum(1 for name in self.list_recursive(coll))
66 def test_medium_sized_manifest(self):
67 """Exercise manifest-handling code.
69 Currently, this test puts undue emphasis on some code paths
70 that don't reflect typical use because the contrived example
71 manifest has some unusual characteristics:
75 * Every block is identical, so block caching patterns are
78 * Every file begins and ends at a block boundary.
82 'files_per_stream': 100,
83 'blocks_per_file': 20,
84 'bytes_per_block': self.TEST_BLOCK_SIZE,
86 my_manifest = self.make_manifest(**specs)
88 coll = self.profile_new_collection_from_manifest(my_manifest)
91 self.profile_new_collection_from_server(coll.manifest_locator())
93 num_items = self.profile_collection_list_files(coll)
94 self.assertEqual(num_items, specs['streams'] * specs['files_per_stream'])
96 self.profile_new_collection_copying_bytes_from_collection(coll)
98 self.profile_new_collection_copying_files_from_collection(coll)