41
41
import java .util .concurrent .atomic .AtomicInteger ;
42
42
import java .util .concurrent .atomic .AtomicLong ;
43
43
import java .util .function .BiFunction ;
44
+ import java .util .function .Consumer ;
44
45
import java .util .function .Function ;
45
46
import java .util .function .Supplier ;
46
47
import org .slf4j .Logger ;
@@ -56,6 +57,7 @@ class DefaultPerformanceMetrics implements PerformanceMetrics {
56
57
private final boolean summaryFile ;
57
58
private final PrintWriter out ;
58
59
private final boolean includeByteRates ;
60
+ private final boolean includeBatchSize ;
59
61
private final Supplier <String > memoryReportSupplier ;
60
62
private volatile Closeable closingSequence = () -> {};
61
63
private volatile long lastPublishedCount = 0 ;
@@ -73,11 +75,13 @@ class DefaultPerformanceMetrics implements PerformanceMetrics {
73
75
String metricsPrefix ,
74
76
boolean summaryFile ,
75
77
boolean includeByteRates ,
78
+ boolean batchSize ,
76
79
boolean confirmLatency ,
77
80
Supplier <String > memoryReportSupplier ,
78
81
PrintWriter out ) {
79
82
this .summaryFile = summaryFile ;
80
83
this .includeByteRates = includeByteRates ;
84
+ this .includeBatchSize = batchSize ;
81
85
this .memoryReportSupplier = memoryReportSupplier ;
82
86
this .out = out ;
83
87
this .metricsPrefix = metricsPrefix ;
@@ -116,6 +120,7 @@ public void start(String description) throws Exception {
116
120
long startTime = System .nanoTime ();
117
121
118
122
String metricPublished = metricsName ("published" );
123
+ String metricPublishBatchSize = metricsName ("publish_batch_size" );
119
124
String metricProducerConfirmed = metricsName ("producer_confirmed" );
120
125
String metricConsumed = metricsName ("consumed" );
121
126
String metricChunkSize = metricsName ("chunk_size" );
@@ -133,6 +138,10 @@ public void start(String description) throws Exception {
133
138
metricChunkSize ,
134
139
metricLatency ));
135
140
141
+ if (this .includeBatchSize ) {
142
+ allMetrics .add (metricPublishBatchSize );
143
+ }
144
+
136
145
if (confirmLatency ()) {
137
146
allMetrics .add (metricConfirmLatency );
138
147
}
@@ -191,6 +200,17 @@ public void start(String description) throws Exception {
191
200
});
192
201
});
193
202
203
+ Consumer <StringBuilder > publishBatchSizeCallback ;
204
+ if (this .includeBatchSize ) {
205
+ HistogramSupport publishBatchSize = meterRegistry .get (metricPublishBatchSize ).summary ();
206
+ Function <HistogramSupport , String > formatPublishBatchSize =
207
+ histogram -> String .format ("publish batch size %.0f" , histogram .takeSnapshot ().mean ());
208
+ publishBatchSizeCallback =
209
+ sb -> sb .append (formatPublishBatchSize .apply (publishBatchSize )).append (", " );
210
+ } else {
211
+ publishBatchSizeCallback = ignored -> {};
212
+ }
213
+
194
214
HistogramSupport chunkSize = meterRegistry .get (metricChunkSize ).summary ();
195
215
Function <HistogramSupport , String > formatChunkSize =
196
216
histogram -> String .format ("chunk size %.0f" , histogram .takeSnapshot ().mean ());
@@ -244,6 +264,7 @@ public void start(String description) throws Exception {
244
264
.append (", " );
245
265
}
246
266
builder .append (formatLatency .apply ("latency" , latency )).append (", " );
267
+ publishBatchSizeCallback .accept (builder );
247
268
builder .append (formatChunkSize .apply (chunkSize ));
248
269
this .out .println (builder );
249
270
String memoryReport = this .memoryReportSupplier .get ();
@@ -299,6 +320,7 @@ public void start(String description) throws Exception {
299
320
.append (", " );
300
321
}
301
322
builder .append (formatLatencySummary .apply ("latency" , latency )).append (", " );
323
+ publishBatchSizeCallback .accept (builder );
302
324
builder .append (formatChunkSize .apply (chunkSize ));
303
325
this .out .println ();
304
326
this .out .println (builder );
0 commit comments