Skip to content

Commit 23f3c93

Browse files
committed
Write a fresh record batch per iteration
1 parent e6f3efc commit 23f3c93

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

jmh-benchmarks/src/main/java/org/apache/kafka/jmh/log/TestLinearWriteSpeed.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public static void main(String[] args) throws Exception {
155155

156156
MemoryRecords messageSet = MemoryRecords.withRecords(compression, recordsList.toArray(new SimpleRecord[0]));
157157
Writable[] writables = new Writable[numFiles];
158+
LogWritable[] logs = new LogWritable[numFiles];
158159
KafkaScheduler scheduler = new KafkaScheduler(1);
159160
scheduler.startup();
160161

@@ -169,7 +170,7 @@ public static void main(String[] args) throws Exception {
169170
logProperties.put(TopicConfig.SEGMENT_BYTES_CONFIG, Integer.toString(segmentSize));
170171
logProperties.put(TopicConfig.FLUSH_MESSAGES_INTERVAL_CONFIG, Long.toString(flushInterval));
171172
LogConfig logConfig = new LogConfig(logProperties);
172-
writables[i] = new LogWritable(new File(dir, "kafka-test-" + i), logConfig, scheduler, messageSet);
173+
logs[i] = new LogWritable(new File(dir, "kafka-test-" + i), logConfig, scheduler, messageSet);
173174
} else {
174175
System.err.println("Must specify what to write to with one of --log, --channel, or --mmap");
175176
Exit.exit(1);
@@ -186,10 +187,17 @@ public static void main(String[] args) throws Exception {
186187
long written = 0L;
187188
long totalWritten = 0L;
188189
long lastReport = beginTest;
190+
int writeSize = 0;
189191

190192
while (totalWritten + bufferSize < bytesToWrite) {
191193
long start = System.nanoTime();
192-
int writeSize = writables[(int) (count % numFiles)].write();
194+
if (options.has(logOpt)) {
195+
messageSet = MemoryRecords.withRecords(compression, recordsList.toArray(new SimpleRecord[0]));
196+
logs[(int) (count % numFiles)].messages = messageSet;
197+
writeSize = logs[(int) (count % numFiles)].write();
198+
} else {
199+
writeSize = writables[(int) (count % numFiles)].write();
200+
}
193201
long elapsed = System.nanoTime() - start;
194202
maxLatency = Math.max(elapsed, maxLatency);
195203
totalLatency += elapsed;
@@ -215,8 +223,14 @@ public static void main(String[] args) throws Exception {
215223
double elapsedSecs = (System.nanoTime() - beginTest) / (1000.0 * 1000.0 * 1000.0);
216224
System.out.println((bytesToWrite / (1024.0 * 1024.0 * elapsedSecs)) + " MB per sec");
217225
scheduler.shutdown();
218-
for (Writable writable : writables) {
219-
writable.close();
226+
if (options.has(logOpt)) {
227+
for (LogWritable log : logs) {
228+
log.close();
229+
}
230+
} else {
231+
for (Writable writable : writables) {
232+
writable.close();
233+
}
220234
}
221235
}
222236

0 commit comments

Comments
 (0)