1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
8 from . import run_test_server
9 from . import arvados_testutil as tutil
10 from . import manifest_examples
11 from .performance.performance_profiler import profiled
13 class CollectionBenchmark(run_test_server.TestCaseWithServers,
14 tutil.ArvadosBaseTestCase,
15 manifest_examples.ManifestExamples):
20 def list_recursive(cls, coll, parent_name=None):
21 if parent_name is None:
22 current_name = coll.stream_name()
24 current_name = '{}/{}'.format(parent_name, coll.name)
27 for item in cls.list_recursive(coll[name], current_name):
34 super(CollectionBenchmark, cls).setUpClass()
35 run_test_server.authorize_with('active')
36 cls.api_client = arvados.api('v1')
37 cls.keep_client = arvados.KeepClient(api_client=cls.api_client,
38 local_store=cls.local_store)
41 def profile_new_collection_from_manifest(self, manifest_text):
42 return arvados.collection.Collection(manifest_text)
45 def profile_new_collection_from_server(self, uuid):
46 return arvados.collection.Collection(uuid)
49 def profile_new_collection_copying_bytes_from_collection(self, src):
50 dst = arvados.collection.Collection()
51 with tutil.mock_keep_responses('x'*self.TEST_BLOCK_SIZE, 200):
52 for name in self.list_recursive(src):
53 with src.open(name, 'rb') as srcfile, dst.open(name, 'wb') as dstfile:
54 dstfile.write(srcfile.read())
58 def profile_new_collection_copying_files_from_collection(self, src):
59 dst = arvados.collection.Collection()
60 with tutil.mock_keep_responses('x'*self.TEST_BLOCK_SIZE, 200):
61 for name in self.list_recursive(src):
62 dst.copy(name, name, src)
66 def profile_collection_list_files(self, coll):
67 return sum(1 for name in self.list_recursive(coll))
69 def test_medium_sized_manifest(self):
70 """Exercise manifest-handling code.
72 Currently, this test puts undue emphasis on some code paths
73 that don't reflect typical use because the contrived example
74 manifest has some unusual characteristics:
78 * Every block is identical, so block caching patterns are
81 * Every file begins and ends at a block boundary.
85 'files_per_stream': 100,
86 'blocks_per_file': 20,
87 'bytes_per_block': self.TEST_BLOCK_SIZE,
89 my_manifest = self.make_manifest(**specs)
91 coll = self.profile_new_collection_from_manifest(my_manifest)
94 self.profile_new_collection_from_server(coll.manifest_locator())
96 num_items = self.profile_collection_list_files(coll)
97 self.assertEqual(num_items, specs['streams'] * specs['files_per_stream'])
99 self.profile_new_collection_copying_bytes_from_collection(coll)
101 self.profile_new_collection_copying_files_from_collection(coll)