|
| 1 | +/* |
| 2 | + * Copyright 2017 Quobyte Inc. All rights reserved. |
| 3 | + * Author: flangner@quobyte.com |
| 4 | + */ |
| 5 | +package com.quobyte.s3bench; |
| 6 | + |
| 7 | +import java.io.File; |
| 8 | +import java.io.FileInputStream; |
| 9 | +import java.io.IOException; |
| 10 | +import java.io.InputStream; |
| 11 | +import java.util.Properties; |
| 12 | + |
| 13 | +class Configuration { |
| 14 | + |
| 15 | + static enum Mode { |
| 16 | + CHUNKED("benchmark_chunked"), |
| 17 | + PRESIGNED("benchmark_presigned"), |
| 18 | + UNSIGNED("benchmark_unsigned"); |
| 19 | + |
| 20 | + private final String propertiesKey; |
| 21 | + |
| 22 | + private Mode(String propertiesKey) { |
| 23 | + this.propertiesKey = propertiesKey; |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + private static final String DEFAULT_URI = "/com/quobyte/s3bench/default.properties"; |
| 28 | + |
| 29 | + /** |
| 30 | + * Fallback, if default.properties could not be loaded. |
| 31 | + */ |
| 32 | + private static final boolean DEFAULT_CLIENT_MD5_VERIFICATION = false; |
| 33 | + private static final int DEFAULT_SAMPLE_COUNT = 10; |
| 34 | + private static final int DEFAULT_OPS_OBJECT_SIZE = 4 * 1024; |
| 35 | + private static final int DEFAULT_TP_OBJECT_SIZE = 128 * 1024 * 1024; |
| 36 | + private static final int DEFAULT_MULTI_OPS_CLIENTS = 10; |
| 37 | + private static final int DEFAULT_MULTI_OPS_THREADS = 10; |
| 38 | + private static final int DEFAULT_MULTI_TP_CLIENTS = 2; |
| 39 | + private static final int DEFAULT_MULTI_TP_THREADS = 5; |
| 40 | + private static final int DEFAULT_MULTI_STREAM_RUNTIME_S = 60; |
| 41 | + |
| 42 | + private static final boolean DEFAULT_BENCHMARK_UNSIGNED = true; |
| 43 | + private static final boolean DEFAULT_BENCHMARK_PRESIGNED = true; |
| 44 | + private static final boolean DEFAULT_BENCHMARK_CHUNKED = true; |
| 45 | + private static final boolean DEFAULT_BENCHMARK_TP = true; |
| 46 | + private static final boolean DEFAULT_BENCHMARK_OPS = true; |
| 47 | + private static final boolean DEFAULT_BENCHMARK_GET = true; |
| 48 | + private static final boolean DEFAULT_BENCHMARK_SINGLE_STREAM = true; |
| 49 | + private static final boolean DEFAULT_BENCHMARK_MULTI_STREAM = true; |
| 50 | + private static final boolean DEFAULT_PATH_STYLE = true; |
| 51 | + private static final boolean DEFAULT_USE_SSL = false; |
| 52 | + |
| 53 | + private static final boolean DEFAULT_CREATE_BUCKET = true; |
| 54 | + private static final boolean DEFAULT_CLEAN_AFTER_RUN = false; |
| 55 | + |
| 56 | + private final Properties properties; |
| 57 | + |
| 58 | + Configuration(String path) { |
| 59 | + properties = new Properties(); |
| 60 | + if (path != null && !path.isEmpty()) { |
| 61 | + try (FileInputStream fis = new FileInputStream(new File(path))) { |
| 62 | + properties.load(fis); |
| 63 | + } catch (IOException e) { |
| 64 | + System.err.println("Could not load properties from " + path + " because " + e); |
| 65 | + } |
| 66 | + } else { |
| 67 | + try (InputStream fis = getClass().getResourceAsStream(DEFAULT_URI)) { |
| 68 | + properties.load(fis); |
| 69 | + } catch (IOException e) { |
| 70 | + System.err.println("Could not load default properties from " + DEFAULT_URI + " because " |
| 71 | + + e); |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + boolean isClientMd5VerificationEnabled() { |
| 77 | + return getBooleanProperty("client_md5_verification", DEFAULT_CLIENT_MD5_VERIFICATION); |
| 78 | + } |
| 79 | + |
| 80 | + int getSampleCount() { |
| 81 | + return getIntProperty("sample_count", DEFAULT_SAMPLE_COUNT); |
| 82 | + } |
| 83 | + |
| 84 | + boolean benchmarkUnsigned() { |
| 85 | + return getBooleanProperty(Mode.UNSIGNED.propertiesKey, DEFAULT_BENCHMARK_UNSIGNED); |
| 86 | + } |
| 87 | + |
| 88 | + boolean benchmarkPresigned() { |
| 89 | + return getBooleanProperty(Mode.PRESIGNED.propertiesKey, DEFAULT_BENCHMARK_PRESIGNED); |
| 90 | + } |
| 91 | + |
| 92 | + boolean benchmarkChunked() { |
| 93 | + return getBooleanProperty(Mode.CHUNKED.propertiesKey, DEFAULT_BENCHMARK_CHUNKED); |
| 94 | + } |
| 95 | + |
| 96 | + boolean benchmarkTp() { |
| 97 | + return getBooleanProperty("benchmark_tp", DEFAULT_BENCHMARK_TP); |
| 98 | + } |
| 99 | + |
| 100 | + boolean benchmarkOps() { |
| 101 | + return getBooleanProperty("benchmark_ops", DEFAULT_BENCHMARK_OPS); |
| 102 | + } |
| 103 | + |
| 104 | + boolean benchmarkSingleStream() { |
| 105 | + return getBooleanProperty("benchmark_single_stream", DEFAULT_BENCHMARK_SINGLE_STREAM); |
| 106 | + } |
| 107 | + |
| 108 | + boolean benchmarkMultiStream() { |
| 109 | + return getBooleanProperty("benchmark_multi_stream", DEFAULT_BENCHMARK_MULTI_STREAM); |
| 110 | + } |
| 111 | + |
| 112 | + boolean benchmarkGet() { |
| 113 | + return getBooleanProperty("benchmark_get", DEFAULT_BENCHMARK_GET); |
| 114 | + } |
| 115 | + |
| 116 | + boolean pathStyle() { |
| 117 | + return getBooleanProperty("path_style", DEFAULT_PATH_STYLE); |
| 118 | + } |
| 119 | + |
| 120 | + boolean useSsl() { |
| 121 | + return getBooleanProperty("use_ssl", DEFAULT_USE_SSL); |
| 122 | + } |
| 123 | + |
| 124 | + boolean createBucket() { |
| 125 | + return getBooleanProperty("create_bucket", DEFAULT_CREATE_BUCKET); |
| 126 | + } |
| 127 | + |
| 128 | + |
| 129 | + boolean cleanAfterRun() { |
| 130 | + return getBooleanProperty("clean_after_run", DEFAULT_CLEAN_AFTER_RUN); |
| 131 | + } |
| 132 | + |
| 133 | + int getOpsObjectSize() { |
| 134 | + return getIntProperty("ops_object_size", DEFAULT_OPS_OBJECT_SIZE); |
| 135 | + } |
| 136 | + |
| 137 | + int getTpObjectSize() { |
| 138 | + return getIntProperty("tp_object_size", DEFAULT_TP_OBJECT_SIZE); |
| 139 | + } |
| 140 | + |
| 141 | + int getMultiOpsClients() { |
| 142 | + return getIntProperty("multi_stream_ops_clients", DEFAULT_MULTI_OPS_CLIENTS); |
| 143 | + } |
| 144 | + |
| 145 | + int getMultiOpsThreads() { |
| 146 | + return getIntProperty("multi_stream_ops_threads", DEFAULT_MULTI_OPS_THREADS); |
| 147 | + } |
| 148 | + |
| 149 | + int getMultiTpClients() { |
| 150 | + return getIntProperty("multi_stream_tp_clients", DEFAULT_MULTI_TP_CLIENTS); |
| 151 | + } |
| 152 | + |
| 153 | + int getMultiTpThreads() { |
| 154 | + return getIntProperty("multi_stream_tp_threads", DEFAULT_MULTI_TP_THREADS); |
| 155 | + } |
| 156 | + |
| 157 | + int getMultiStreamRuntimeS() { |
| 158 | + return getIntProperty("multi_stream_runtime_s", DEFAULT_MULTI_STREAM_RUNTIME_S); |
| 159 | + } |
| 160 | + |
| 161 | + private boolean getBooleanProperty(String key, boolean defaultValue) { |
| 162 | + try { |
| 163 | + return Boolean.valueOf((String) properties.get(key)); |
| 164 | + } catch (Throwable t) { |
| 165 | + return defaultValue; |
| 166 | + } |
| 167 | + } |
| 168 | + |
| 169 | + private int getIntProperty(String key, int defaultValue) { |
| 170 | + try { |
| 171 | + return Integer.valueOf((String) properties.get(key)); |
| 172 | + } catch (Throwable t) { |
| 173 | + return defaultValue; |
| 174 | + } |
| 175 | + } |
| 176 | +} |
0 commit comments