~david-goetz/swift/zero_byte_obj_audit

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
#!/usr/bin/python
# Copyright (c) 2010-2011 OpenStack, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os
import sys
import signal
import uuid
from optparse import OptionParser

from swift.common.bench import BenchController
from swift.common.utils import readconf, LogAdapter, NamedFormatter

# The defaults should be sufficient to run swift-bench on a SAIO
CONF_DEFAULTS = {
    'auth': '',
    'user': '',
    'key': '',
    'object_sources': '',
    'put_concurrency': '10',
    'get_concurrency': '10',
    'del_concurrency': '10',
    'concurrency': '',
    'object_size': '1',
    'num_objects': '1000',
    'num_gets': '10000',
    'delete': 'yes',
    'container_name': uuid.uuid4().hex,
    'num_containers': '20',
    'use_proxy': 'yes',
    'url': '',
    'account': '',
    'devices': 'sdb1',
    'log_level': 'INFO',
    'timeout': '10',
    }

SAIO_DEFAULTS = {
    'auth': 'http://saio:11000/v1.0',
    'user': 'test:tester',
    'key': 'testing',
    }

if __name__ == '__main__':
    usage = "usage: %prog [OPTIONS] [CONF_FILE]"
    usage += """\n\nConf file with SAIO defaults:

    [bench]
    auth = http://saio:11000/v1.0
    user = test:tester
    key = testing
    concurrency = 10
    object_size = 1
    num_objects = 1000
    num_gets = 10000
    delete = yes
    """
    parser = OptionParser(usage=usage)
    parser.add_option('', '--saio', dest='saio', action='store_true',
                      default=False, help='Run benchmark with SAIO defaults')
    parser.add_option('-A', '--auth', dest='auth',
                      help='URL for obtaining an auth token')
    parser.add_option('-U', '--user', dest='user',
                      help='User name for obtaining an auth token')
    parser.add_option('-K', '--key', dest='key',
                      help='Key for obtaining an auth token')
    parser.add_option('-u', '--url', dest='url',
                      help='Storage URL')
    parser.add_option('-c', '--concurrency', dest='concurrency',
                      help='Number of concurrent connections to use')
    parser.add_option('-s', '--object-size', dest='object_size',
                      help='Size of objects to PUT (in bytes)')
    parser.add_option('-n', '--num-objects', dest='num_objects',
                      help='Number of objects to PUT')
    parser.add_option('-g', '--num-gets', dest='num_gets',
                      help='Number of GET operations to perform')
    parser.add_option('-x', '--no-delete', dest='delete', action='store_false',
                      help='If set, will not delete the objects created')

    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit(1)
    options, args = parser.parse_args()
    if options.saio:
        CONF_DEFAULTS.update(SAIO_DEFAULTS)
    if args:
        conf = args[0]
        if not os.path.exists(conf):
            sys.exit("No such conf file: %s" % conf)
        conf = readconf(conf, 'bench', log_name='swift-bench',
            defaults=CONF_DEFAULTS)
    else:
        conf = CONF_DEFAULTS
    parser.set_defaults(**conf)
    options, _junk = parser.parse_args()
    if options.concurrency is not '':
        options.put_concurrency = options.concurrency
        options.get_concurrency = options.concurrency
        options.del_concurrency = options.concurrency

    def sigterm(signum, frame):
        sys.exit('Termination signal received.')
    signal.signal(signal.SIGTERM, sigterm)

    logger = logging.getLogger()
    logger.setLevel({
        'debug': logging.DEBUG,
        'info': logging.INFO,
        'warning': logging.WARNING,
        'error': logging.ERROR,
        'critical': logging.CRITICAL}.get(
            options.log_level.lower(), logging.INFO))
    loghandler = logging.StreamHandler()
    logger.addHandler(loghandler)
    logger = LogAdapter(logger)
    logformat = NamedFormatter('swift-bench', logger,
                   fmt='%(server)s %(asctime)s %(levelname)s %(message)s')
    loghandler.setFormatter(logformat)

    controller = BenchController(logger, options)
    controller.run()