Skip to content

Commit f773292

Browse files
authored
Metrics: add journalCbQueueLatency (#3364)
1 parent 414772d commit f773292

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookKeeperServerStats.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public interface BookKeeperServerStats {
162162
String INDEX_INMEM_ILLEGAL_STATE_DELETE = "INDEX_INMEM_ILLEGAL_STATE_DELETE";
163163
String JOURNAL_FORCE_WRITE_QUEUE_SIZE = "JOURNAL_FORCE_WRITE_QUEUE_SIZE";
164164
String JOURNAL_CB_QUEUE_SIZE = "JOURNAL_CB_QUEUE_SIZE";
165+
String JOURNAL_CB_QUEUED_LATENCY = "JOURNAL_CB_QUEUED_LATENCY";
165166
String JOURNAL_NUM_FORCE_WRITES = "JOURNAL_NUM_FORCE_WRITES";
166167
String JOURNAL_NUM_FLUSH_EMPTY_QUEUE = "JOURNAL_NUM_FLUSH_EMPTY_QUEUE";
167168
String JOURNAL_NUM_FLUSH_MAX_OUTSTANDING_BYTES = "JOURNAL_NUM_FLUSH_MAX_OUTSTANDING_BYTES";

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,18 @@ static class QueueEntry implements Runnable {
303303
WriteCallback cb;
304304
Object ctx;
305305
long enqueueTime;
306+
long enqueueCbThreadPooleQueueTime;
306307
boolean ackBeforeSync;
307308

308309
OpStatsLogger journalAddEntryStats;
310+
OpStatsLogger journalCbQueuedLatency;
309311
Counter journalCbQueueSize;
310312
Counter callbackTime;
311313

312314
static QueueEntry create(ByteBuf entry, boolean ackBeforeSync, long ledgerId, long entryId,
313315
WriteCallback cb, Object ctx, long enqueueTime, OpStatsLogger journalAddEntryStats,
314-
Counter journalCbQueueSize, Counter callbackTime) {
316+
Counter journalCbQueueSize, OpStatsLogger journalCbQueuedLatency,
317+
Counter callbackTime) {
315318
QueueEntry qe = RECYCLER.get();
316319
qe.entry = entry;
317320
qe.ackBeforeSync = ackBeforeSync;
@@ -321,13 +324,20 @@ static QueueEntry create(ByteBuf entry, boolean ackBeforeSync, long ledgerId, lo
321324
qe.entryId = entryId;
322325
qe.enqueueTime = enqueueTime;
323326
qe.journalAddEntryStats = journalAddEntryStats;
327+
qe.journalCbQueuedLatency = journalCbQueuedLatency;
324328
qe.journalCbQueueSize = journalCbQueueSize;
325329
qe.callbackTime = callbackTime;
326330
return qe;
327331
}
328332

333+
public void setEnqueueCbThreadPooleQueueTime(long enqueueCbThreadPooleQueueTime) {
334+
this.enqueueCbThreadPooleQueueTime = enqueueCbThreadPooleQueueTime;
335+
}
336+
329337
@Override
330338
public void run() {
339+
journalCbQueuedLatency.registerSuccessfulEvent(
340+
MathUtils.elapsedNanos(enqueueCbThreadPooleQueueTime), TimeUnit.NANOSECONDS);
331341
long startTime = System.nanoTime();
332342
if (LOG.isDebugEnabled()) {
333343
LOG.debug("Acknowledge Ledger: {}, Entry: {}", ledgerId, entryId);
@@ -392,6 +402,7 @@ public int process(boolean shouldForceWrite) throws IOException {
392402
for (int i = 0; i < forceWriteWaiters.size(); i++) {
393403
QueueEntry qe = forceWriteWaiters.get(i);
394404
if (qe != null) {
405+
qe.setEnqueueCbThreadPooleQueueTime(MathUtils.nowInNano());
395406
cbThreadPool.execute(qe);
396407
}
397408
}
@@ -943,6 +954,7 @@ public void logAddEntry(long ledgerId, long entryId, ByteBuf entry,
943954
entry, ackBeforeSync, ledgerId, entryId, cb, ctx, MathUtils.nowInNano(),
944955
journalStats.getJournalAddEntryStats(),
945956
journalStats.getJournalCbQueueSize(),
957+
journalStats.getJournalCbQueuedLatency(),
946958
callbackTime));
947959
}
948960

@@ -952,6 +964,7 @@ void forceLedger(long ledgerId, WriteCallback cb, Object ctx) {
952964
BookieImpl.METAENTRY_ID_FORCE_LEDGER, cb, ctx, MathUtils.nowInNano(),
953965
journalStats.getJournalForceLedgerStats(),
954966
journalStats.getJournalCbQueueSize(),
967+
journalStats.getJournalCbQueuedLatency(),
955968
callbackTime));
956969
// Increment afterwards because the add operation could fail.
957970
journalStats.getJournalQueueSize().inc();
@@ -1118,6 +1131,7 @@ journalFormatVersionToWrite, getBufferedChannelBuilder(),
11181131
if (entry != null && (!syncData || entry.ackBeforeSync)) {
11191132
toFlush.set(i, null);
11201133
numEntriesToFlush--;
1134+
entry.setEnqueueCbThreadPooleQueueTime(MathUtils.nowInNano());
11211135
cbThreadPool.execute(entry);
11221136
}
11231137
}

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/stats/JournalStats.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.apache.bookkeeper.bookie.BookKeeperServerStats.CATEGORY_SERVER;
2424
import static org.apache.bookkeeper.bookie.BookKeeperServerStats.FORCE_LEDGER;
2525
import static org.apache.bookkeeper.bookie.BookKeeperServerStats.JOURNAL_ADD_ENTRY;
26+
import static org.apache.bookkeeper.bookie.BookKeeperServerStats.JOURNAL_CB_QUEUED_LATENCY;
2627
import static org.apache.bookkeeper.bookie.BookKeeperServerStats.JOURNAL_CB_QUEUE_SIZE;
2728
import static org.apache.bookkeeper.bookie.BookKeeperServerStats.JOURNAL_CREATION_LATENCY;
2829
import static org.apache.bookkeeper.bookie.BookKeeperServerStats.JOURNAL_FLUSH_LATENCY;
@@ -153,6 +154,13 @@ public class JournalStats {
153154
help = "The journal callback queue size"
154155
)
155156
private final Counter journalCbQueueSize;
157+
158+
@StatsDoc(
159+
name = JOURNAL_CB_QUEUED_LATENCY,
160+
help = "The journal callback queued latency"
161+
)
162+
private final OpStatsLogger journalCbQueuedLatency;
163+
156164
@StatsDoc(
157165
name = JOURNAL_NUM_FLUSH_MAX_WAIT,
158166
help = "The number of journal flushes triggered by MAX_WAIT time"
@@ -203,6 +211,7 @@ public JournalStats(StatsLogger statsLogger, final long maxJournalMemoryBytes,
203211
journalQueueSize = statsLogger.getCounter(BookKeeperServerStats.JOURNAL_QUEUE_SIZE);
204212
forceWriteQueueSize = statsLogger.getCounter(BookKeeperServerStats.JOURNAL_FORCE_WRITE_QUEUE_SIZE);
205213
journalCbQueueSize = statsLogger.getCounter(BookKeeperServerStats.JOURNAL_CB_QUEUE_SIZE);
214+
journalCbQueuedLatency = statsLogger.getOpStatsLogger(BookKeeperServerStats.JOURNAL_CB_QUEUED_LATENCY);
206215
flushMaxWaitCounter = statsLogger.getCounter(BookKeeperServerStats.JOURNAL_NUM_FLUSH_MAX_WAIT);
207216
flushMaxOutstandingBytesCounter =
208217
statsLogger.getCounter(BookKeeperServerStats.JOURNAL_NUM_FLUSH_MAX_OUTSTANDING_BYTES);

0 commit comments

Comments
 (0)