Skip to content

Commit 4ff4daa

Browse files
committed
Refactor inner callback conditional
1 parent a55a429 commit 4ff4daa

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

tools/src/main/java/org/apache/kafka/tools/ProducerPerformance.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,11 @@ void start(String[] args) throws IOException {
101101
record = new ProducerRecord<>(config.topicName, payload);
102102

103103
long sendStartMs = System.currentTimeMillis();
104-
if (config.warmupRecords > 0) {
105-
if (i < config.warmupRecords) {
106-
cb = new PerfCallback(sendStartMs, payload.length, stats);
107-
} else {
108-
if (i == config.warmupRecords) {
109-
steadyStateStats = new Stats(config.numRecords - config.warmupRecords, DEFAULT_REPORTING_INTERVAL_MS, config.warmupRecords > 0);
110-
stats.steadyStateActive = true;
111-
}
112-
cb = new PerfCallback(sendStartMs, payload.length, stats, steadyStateStats);
113-
}
114-
} else {
115-
cb = new PerfCallback(sendStartMs, payload.length, stats);
104+
if ( config.warmupRecords > 0 && i == config.warmupRecords ) {
105+
steadyStateStats = new Stats(config.numRecords - config.warmupRecords, DEFAULT_REPORTING_INTERVAL_MS, config.warmupRecords > 0);
106+
stats.steadyStateActive = true;
116107
}
108+
cb = new PerfCallback(sendStartMs, payload.length, stats, steadyStateStats);
117109
producer.send(record, cb);
118110

119111
currentTransactionSize++;
@@ -173,7 +165,6 @@ KafkaProducer<byte[], byte[]> createKafkaProducer(Properties props) {
173165
}
174166

175167
Callback cb;
176-
177168
Stats stats;
178169
Stats steadyStateStats;
179170

@@ -510,13 +501,6 @@ static final class PerfCallback implements Callback {
510501
private final Stats stats;
511502
private final Stats steadyStateStats;
512503

513-
public PerfCallback(long start, int bytes, Stats stats) {
514-
this.start = start;
515-
this.stats = stats;
516-
this.steadyStateStats = null;
517-
this.bytes = bytes;
518-
}
519-
520504
public PerfCallback(long start, int bytes, Stats stats, Stats steadyStateStats) {
521505
this.start = start;
522506
this.stats = stats;

0 commit comments

Comments
 (0)