summaryrefslogtreecommitdiffstats
path: root/qa/tasks/radosbenchsweep.py
blob: df0ba1ed1c5aef9922bab5efe4e8a9dd8f7e15a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
"""
Rados benchmarking sweep
"""
import contextlib
import logging
import re

from io import BytesIO
from itertools import product

from teuthology.orchestra import run
from teuthology import misc as teuthology


log = logging.getLogger(__name__)


@contextlib.contextmanager
def task(ctx, config):
    """
    Execute a radosbench parameter sweep

    Puts radosbench in a loop, taking values from the given config at each
    iteration. If given, the min and max values below create a range, e.g.
    min_replicas=1 and max_replicas=3 implies executing with 1-3 replicas.

    Parameters:

        clients: [client list]
        time: seconds to run (default=120)
        sizes: [list of object sizes] (default=[4M])
        mode: <write|read|seq> (default=write)
        repetitions: execute the same configuration multiple times (default=1)
        min_num_replicas: minimum number of replicas to use (default = 3)
        max_num_replicas: maximum number of replicas to use (default = 3)
        min_num_osds: the minimum number of OSDs in a pool (default=all)
        max_num_osds: the maximum number of OSDs in a pool (default=all)
        file: name of CSV-formatted output file (default='radosbench.csv')
        columns: columns to include (default=all)
          - rep: execution number (takes values from 'repetitions')
          - num_osd: number of osds for pool
          - num_replica: number of replicas
          - avg_throughput: throughput
          - avg_latency: latency
          - stdev_throughput:
          - stdev_latency:

    Example:
    - radsobenchsweep:
        columns: [rep, num_osd, num_replica, avg_throughput, stdev_throughput]
    """
    log.info('Beginning radosbenchsweep...')
    assert isinstance(config, dict), 'expecting dictionary for configuration'

    # get and validate config values
    # {

    # only one client supported for now
    if len(config.get('clients', [])) != 1:
        raise Exception("Only one client can be specified")

    # only write mode
    if config.get('mode', 'write') != 'write':
        raise Exception("Only 'write' mode supported for now.")

    # OSDs
    total_osds_in_cluster = teuthology.num_instances_of_type(ctx.cluster, 'osd')
    min_num_osds = config.get('min_num_osds', total_osds_in_cluster)
    max_num_osds = config.get('max_num_osds', total_osds_in_cluster)

    if max_num_osds > total_osds_in_cluster:
        raise Exception('max_num_osds cannot be greater than total in cluster')
    if min_num_osds < 1:
        raise Exception('min_num_osds cannot be less than 1')
    if min_num_osds > max_num_osds:
        raise Exception('min_num_osds cannot be greater than max_num_osd')
    osds = range(0, (total_osds_in_cluster + 1))

    # replicas
    min_num_replicas = config.get('min_num_replicas', 3)
    max_num_replicas = config.get('max_num_replicas', 3)

    if min_num_replicas < 1:
        raise Exception('min_num_replicas cannot be less than 1')
    if min_num_replicas > max_num_replicas:
        raise Exception('min_num_replicas cannot be greater than max_replicas')
    if max_num_replicas > max_num_osds:
        raise Exception('max_num_replicas cannot be greater than max_num_osds')
    replicas = range(min_num_replicas, (max_num_replicas + 1))

    # object size
    sizes = config.get('size', [4 << 20])

    # repetitions
    reps = range(config.get('repetitions', 1))

    # file
    fname = config.get('file', 'radosbench.csv')
    f = open('{}/{}'.format(ctx.archive, fname), 'w')
    f.write(get_csv_header(config) + '\n')
    # }

    # set default pools size=1 to avoid 'unhealthy' issues
    ctx.manager.set_pool_property('data', 'size', 1)
    ctx.manager.set_pool_property('metadata', 'size', 1)
    ctx.manager.set_pool_property('rbd', 'size', 1)

    current_osds_out = 0

    # sweep through all parameters
    for osds_out, size, replica, rep in product(osds, sizes, replicas, reps):

        osds_in = total_osds_in_cluster - osds_out

        if osds_in == 0:
            # we're done
            break

        if current_osds_out != osds_out:
            # take an osd out
            ctx.manager.raw_cluster_cmd(
                'osd', 'reweight', str(osds_out-1), '0.0')
            wait_until_healthy(ctx, config)
            current_osds_out = osds_out

        if osds_in not in range(min_num_osds, (max_num_osds + 1)):
            # no need to execute with a number of osds that wasn't requested
            continue

        if osds_in < replica:
            # cannot execute with more replicas than available osds
            continue

        run_radosbench(ctx, config, f, osds_in, size, replica, rep)

    f.close()

    yield


def get_csv_header(conf):
    all_columns = [
        'rep', 'num_osd', 'num_replica', 'avg_throughput',
        'avg_latency', 'stdev_throughput', 'stdev_latency'
    ]
    given_columns = conf.get('columns', None)
    if given_columns and len(given_columns) != 0:
        for column in given_columns:
            if column not in all_columns:
                raise Exception('Unknown column ' + column)
        return ','.join(conf['columns'])
    else:
        conf['columns'] = all_columns
        return ','.join(all_columns)


def run_radosbench(ctx, config, f, num_osds, size, replica, rep):
    pool = ctx.manager.create_pool_with_unique_name()

    ctx.manager.set_pool_property(pool, 'size', replica)

    wait_until_healthy(ctx, config)

    log.info('Executing with parameters: ')
    log.info('  num_osd =' + str(num_osds))
    log.info('  size =' + str(size))
    log.info('  num_replicas =' + str(replica))
    log.info('  repetition =' + str(rep))

    for role in config.get('clients', ['client.0']):
        assert isinstance(role, str)
        PREFIX = 'client.'
        assert role.startswith(PREFIX)
        id_ = role[len(PREFIX):]
        (remote,) = ctx.cluster.only(role).remotes.keys()

        proc = remote.run(
            args=[
                'adjust-ulimits',
                'ceph-coverage',
                '{}/archive/coverage'.format(teuthology.get_testdir(ctx)),
                'rados',
                '--no-log-to-stderr',
                '--name', role,
                '-b', str(size),
                '-p', pool,
                'bench', str(config.get('time', 120)), 'write',
            ],
            logger=log.getChild('radosbench.{id}'.format(id=id_)),
            stdin=run.PIPE,
            stdout=BytesIO(),
            wait=False
        )

        # parse output to get summary and format it as CSV
        proc.wait()
        out = proc.stdout.getvalue()
        all_values = {
            'stdev_throughput': re.sub(r'Stddev Bandwidth: ', '', re.search(
                r'Stddev Bandwidth:.*', out).group(0)),
            'stdev_latency': re.sub(r'Stddev Latency: ', '', re.search(
                r'Stddev Latency:.*', out).group(0)),
            'avg_throughput': re.sub(r'Bandwidth \(MB/sec\): ', '', re.search(
                r'Bandwidth \(MB/sec\):.*', out).group(0)),
            'avg_latency': re.sub(r'Average Latency: ', '', re.search(
                r'Average Latency:.*', out).group(0)),
            'rep': str(rep),
            'num_osd': str(num_osds),
            'num_replica': str(replica)
        }
        values_to_write = []
        for column in config['columns']:
            values_to_write.extend([all_values[column]])
        f.write(','.join(values_to_write) + '\n')

    ctx.manager.remove_pool(pool)


def wait_until_healthy(ctx, config):
    first_mon = teuthology.get_first_mon(ctx, config)
    (mon_remote,) = ctx.cluster.only(first_mon).remotes.keys()
    teuthology.wait_until_healthy(ctx, mon_remote)