3 # Bench backup block-job
5 # Copyright (c) 2020 Virtuozzo International GmbH.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 from results_to_text
import results_to_text
26 from bench_block_job
import bench_block_copy
, drv_file
, drv_nbd
, drv_qcow2
29 def bench_func(env
, case
):
30 """ Handle one "cell" of benchmarking table. """
31 cmd_options
= env
['cmd-options'] if 'cmd-options' in env
else {}
32 return bench_block_copy(env
['qemu-binary'], env
['cmd'],
34 case
['source'], case
['target'])
40 # paths with colon not supported, so we just split by ':'
41 dirs
= dict(d
.split(':') for d
in args
.dir)
45 nbd
= args
.nbd
.split(':')
47 port
= '10809' if len(nbd
) == 1 else nbd
[1]
48 nbd_drv
= drv_nbd(host
, port
)
51 src
, dst
= t
.split(':')
53 if src
== 'nbd' and dst
== 'nbd':
54 raise ValueError("Can't use 'nbd' label for both src and dst")
56 if (src
== 'nbd' or dst
== 'nbd') and not nbd_drv
:
57 raise ValueError("'nbd' label used but --nbd is not given")
61 elif args
.qcow2_sources
:
62 source
= drv_qcow2(drv_file(dirs
[src
] + '/test-source.qcow2'))
64 source
= drv_file(dirs
[src
] + '/test-source')
67 test_cases
.append({'id': t
, 'source': source
, 'target': nbd_drv
})
70 if args
.target_cache
== 'both':
71 target_caches
= ['direct', 'cached']
73 target_caches
= [args
.target_cache
]
75 for c
in target_caches
:
76 o_direct
= c
== 'direct'
77 fname
= dirs
[dst
] + '/test-target'
80 target
= drv_file(fname
, o_direct
=o_direct
)
82 target
= drv_qcow2(target
)
85 if args
.target_cache
== 'both':
88 test_cases
.append({'id': test_id
, 'source': source
,
91 binaries
= [] # list of (<label>, <path>, [<options>])
92 for i
, q
in enumerate(args
.env
):
93 name_path
= q
.split(':')
94 if len(name_path
) == 1:
96 path_opts
= name_path
[0].split(',')
98 assert len(name_path
) == 2 # paths with colon not supported
100 path_opts
= name_path
[1].split(',')
102 binaries
.append((label
, path_opts
[0], path_opts
[1:]))
107 for i
, q
in enumerate(args
.env
):
112 if ':' in label_path
:
113 # path with colon inside is not supported
114 label
, path
= label_path
.split(':')
115 bin_paths
[label
] = path
116 elif label_path
in bin_paths
:
118 path
= bin_paths
[label
]
122 bin_paths
[label
] = path
129 elif opt
== 'copy-range=on':
130 x_perf
['use-copy-range'] = True
131 elif opt
== 'copy-range=off':
132 x_perf
['use-copy-range'] = False
133 elif opt
.startswith('max-workers='):
134 x_perf
['max-workers'] = int(opt
.split('=')[1])
138 backup_options
['x-perf'] = x_perf
141 backup_options
['compress'] = True
146 'id': f
'mirror({label})',
147 'cmd': 'blockdev-mirror',
152 'id': f
'backup({label})\n' + '\n'.join(opts
),
153 'cmd': 'blockdev-backup',
154 'cmd-options': backup_options
,
158 result
= simplebench
.bench(bench_func
, test_envs
, test_cases
,
159 count
=args
.count
, initial_run
=args
.initial_run
,
160 drop_caches
=args
.drop_caches
)
161 with
open('results.json', 'w') as f
:
162 json
.dump(result
, f
, indent
=4)
163 print(results_to_text(result
))
166 class ExtendAction(argparse
.Action
):
167 def __call__(self
, parser
, namespace
, values
, option_string
=None):
168 items
= getattr(namespace
, self
.dest
) or []
170 setattr(namespace
, self
.dest
, items
)
173 if __name__
== '__main__':
174 p
= argparse
.ArgumentParser('Backup benchmark', epilog
='''
177 (LABEL:PATH|LABEL|PATH)[,max-workers=N][,use-copy-range=(on|off)][,mirror]
179 LABEL short name for the binary
180 PATH path to the binary
181 max-workers set x-perf.max-workers of backup job
182 use-copy-range set x-perf.use-copy-range of backup job
183 mirror use mirror job instead of backup''',
184 formatter_class
=argparse
.RawTextHelpFormatter
)
185 p
.add_argument('--env', nargs
='+', help='''\
186 Qemu binaries with labels and options, see below
187 "ENV format" section''',
189 p
.add_argument('--dir', nargs
='+', help='''\
190 Directories, each containing "test-source" and/or
191 "test-target" files, raw images to used in
192 benchmarking. File path with label, like
193 label:/path/to/directory''',
195 p
.add_argument('--nbd', help='''\
196 host:port for remote NBD image, (or just host, for
197 default port 10809). Use it in tests, label is "nbd"
198 (but you cannot create test nbd:nbd).''')
199 p
.add_argument('--test', nargs
='+', help='''\
200 Tests, in form source-dir-label:target-dir-label''',
202 p
.add_argument('--compressed', help='''\
203 Use compressed backup. It automatically means
204 automatically creating qcow2 target with
205 lazy_refcounts for each test run''', action
='store_true')
206 p
.add_argument('--qcow2-sources', help='''\
207 Use test-source.qcow2 images as sources instead of
208 test-source raw images''', action
='store_true')
209 p
.add_argument('--target-cache', help='''\
210 Setup cache for target nodes. Options:
211 direct: default, use O_DIRECT and aio=native
212 cached: use system cache (Qemu default) and aio=threads (Qemu default)
213 both: generate two test cases for each src:dst pair''',
214 default
='direct', choices
=('direct', 'cached', 'both'))
216 p
.add_argument('--count', type=int, default
=3, help='''\
217 Number of test runs per table cell''')
219 # BooleanOptionalAction helps to support --no-initial-run option
220 p
.add_argument('--initial-run', action
=argparse
.BooleanOptionalAction
,
222 Do additional initial run per cell which doesn't count in result,
225 p
.add_argument('--drop-caches', action
='store_true', help='''\
226 Do "sync; echo 3 > /proc/sys/vm/drop_caches" before each test run''')
228 bench(p
.parse_args())