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