diff --git a/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/log/TestLinearWriteSpeed.java b/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/log/TestLinearWriteSpeed.java index d924e85e525..cb2e1104f05 100644 --- a/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/log/TestLinearWriteSpeed.java +++ b/jmh-benchmarks/src/main/java/org/apache/kafka/jmh/log/TestLinearWriteSpeed.java @@ -63,19 +63,22 @@ import joptsimple.OptionSpec; public class TestLinearWriteSpeed { public static void main(String[] args) throws Exception { - var option = createOptions(new OptionParser(), args); - long bytesToWrite = option.options.valueOf(option.bytesOpt); - int bufferSize = option.options.valueOf(option.sizeOpt); - int numFiles = option.options.valueOf(option.filesOpt); - long reportingInterval = option.options.valueOf(option.reportingIntervalOpt); - String dir = option.options.valueOf(option.dirOpt); - long maxThroughputBytes = option.options.valueOf(option.maxThroughputOpt) * 1024L * 1024L; + var parser = new OptionParser(); + var option = createOptions(parser); + OptionSet options = parser.parse(args); + CommandLineUtils.checkRequiredArgs(parser, options, option.bytesOpt, option.sizeOpt); + long bytesToWrite = options.valueOf(option.bytesOpt); + int bufferSize = options.valueOf(option.sizeOpt); + int numFiles = options.valueOf(option.filesOpt); + long reportingInterval = options.valueOf(option.reportingIntervalOpt); + String dir = options.valueOf(option.dirOpt); + long maxThroughputBytes = options.valueOf(option.maxThroughputOpt) * 1024L * 1024L; ByteBuffer buffer = ByteBuffer.allocate(bufferSize); - int messageSize = option.options.valueOf(option.messageSizeOpt); - long flushInterval = option.options.valueOf(option.flushIntervalOpt); - CompressionType compressionType = CompressionType.forName(option.options.valueOf(option.compressionCodecOpt)); + int messageSize = options.valueOf(option.messageSizeOpt); + long flushInterval = options.valueOf(option.flushIntervalOpt); + CompressionType compressionType = CompressionType.forName(options.valueOf(option.compressionCodecOpt)); Compression.Builder compressionBuilder = Compression.of(compressionType); - Integer compressionLevel = option.options.valueOf(option.compressionLevelOpt); + Integer compressionLevel = options.valueOf(option.compressionLevelOpt); if (compressionLevel != null) setupCompression(compressionType, compressionBuilder, compressionLevel); Compression compression = compressionBuilder.build(); @@ -95,11 +98,11 @@ public class TestLinearWriteSpeed { scheduler.startup(); for (int i = 0; i < numFiles; i++) { - if (option.options.has(option.mmapOpt)) { + if (options.has(option.mmapOpt)) { writables[i] = new MmapWritable(new File(dir, "kafka-test-" + i + ".dat"), bytesToWrite / numFiles, buffer); - } else if (option.options.has(option.channelOpt)) { + } else if (options.has(option.channelOpt)) { writables[i] = new ChannelWritable(new File(dir, "kafka-test-" + i + ".dat"), buffer); - } else if (option.options.has(option.logOpt)) { + } else if (options.has(option.logOpt)) { int segmentSize = ThreadLocalRandom.current().nextInt(512) * 1024 * 1024 + 64 * 1024 * 1024; Properties logProperties = new Properties(); logProperties.put(TopicConfig.SEGMENT_BYTES_CONFIG, Integer.toString(segmentSize)); @@ -294,7 +297,6 @@ public class TestLinearWriteSpeed { private final OptionSpec channelOpt; private final OptionSpec logOpt; private final OptionSpec mmapOpt; - private final OptionSet options; private Options( OptionSpec dirOpt, @@ -309,8 +311,7 @@ public class TestLinearWriteSpeed { OptionSpec compressionLevelOpt, OptionSpec channelOpt, OptionSpec logOpt, - OptionSpec mmapOpt, - OptionSet options + OptionSpec mmapOpt ) { this.dirOpt = dirOpt; this.bytesOpt = bytesOpt; @@ -325,11 +326,10 @@ public class TestLinearWriteSpeed { this.channelOpt = channelOpt; this.logOpt = logOpt; this.mmapOpt = mmapOpt; - this.options = options; } } - private static Options createOptions(OptionParser parser, String[] args) { + private static Options createOptions(OptionParser parser) { OptionSpec dirOpt = parser.accepts("dir", "The directory to write to.") .withRequiredArg() .describedAs("path") @@ -390,8 +390,6 @@ public class TestLinearWriteSpeed { OptionSpec channelOpt = parser.accepts("channel", "Do writes to file channels."); OptionSpec logOpt = parser.accepts("log", "Do writes to kafka logs."); OptionSpec mmapOpt = parser.accepts("mmap", "Do writes to mmap file."); - OptionSet options = parser.parse(args); - CommandLineUtils.checkRequiredArgs(parser, options, bytesOpt, sizeOpt); return new Options( dirOpt, @@ -406,8 +404,7 @@ public class TestLinearWriteSpeed { compressionLevelOpt, channelOpt, logOpt, - mmapOpt, - options + mmapOpt ); } } \ No newline at end of file