You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by yo...@apache.org on 2022/03/16 10:11:10 UTC

[bookkeeper] branch master updated: add stats for throttled-write (#3102)

This is an automated email from the ASF dual-hosted git repository.

yong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 3af688b  add stats for throttled-write (#3102)
3af688b is described below

commit 3af688bad65ff1ac972c9178a856613bd438e411
Author: StevenLuMT <42...@users.noreply.github.com>
AuthorDate: Wed Mar 16 18:10:59 2022 +0800

    add stats for throttled-write (#3102)
    
    Descriptions of the changes in this PR:
    
    
    ### Motivation
    
    method:triggerFlushAndAddEntry costing time is a changing,so add a stats metric focus on this method
    
    ### Changes
    
    1.the previous counter metrics(throttledWriteRequests) are retained
    2.add throttledWriteStats to record cost time and count for the method(triggerFlushAndAddEntry)
---
 .../bookkeeper/bookie/storage/ldb/DbLedgerStorageStats.java    | 10 ++++++++++
 .../bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java     |  3 +++
 2 files changed, 13 insertions(+)

diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/DbLedgerStorageStats.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/DbLedgerStorageStats.java
index 1763a54..d947df5 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/DbLedgerStorageStats.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/DbLedgerStorageStats.java
@@ -59,7 +59,11 @@ class DbLedgerStorageStats {
     private static final String FLUSH_LOCATIONS_INDEX = "flush-locations-index";
     private static final String FLUSH_LEDGER_INDEX = "flush-ledger-index";
     private static final String FLUSH_SIZE = "flush-size";
+
+    @Deprecated
     private static final String THROTTLED_WRITE_REQUESTS = "throttled-write-requests";
+    // throttled-write-requests is deprecated, use new metric: throttled-write
+    private static final String THROTTLED_WRITE = "throttled-write";
     private static final String REJECTED_WRITE_REQUESTS = "rejected-write-requests";
     private static final String WRITE_CACHE_SIZE = "write-cache-size";
     private static final String WRITE_CACHE_COUNT = "write-cache-count";
@@ -160,6 +164,11 @@ class DbLedgerStorageStats {
     )
     private final Counter throttledWriteRequests;
     @StatsDoc(
+            name = THROTTLED_WRITE,
+            help = "The stats of throttled write due to write cache is full"
+    )
+    private final OpStatsLogger throttledWriteStats;
+    @StatsDoc(
         name = REJECTED_WRITE_REQUESTS,
         help = "The number of requests rejected due to write cache is full"
     )
@@ -209,6 +218,7 @@ class DbLedgerStorageStats {
         flushSizeStats = stats.getOpStatsLogger(FLUSH_SIZE);
 
         throttledWriteRequests = stats.getThreadScopedCounter(THROTTLED_WRITE_REQUESTS);
+        throttledWriteStats = stats.getOpStatsLogger(THROTTLED_WRITE);
         rejectedWriteRequests = stats.getThreadScopedCounter(REJECTED_WRITE_REQUESTS);
 
         writeCacheSizeGauge = new Gauge<Long>() {
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java
index d13962f..ffade42 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java
@@ -426,6 +426,7 @@ public class SingleDirectoryDbLedgerStorage implements CompactableLedgerStorage
 
     private void triggerFlushAndAddEntry(long ledgerId, long entryId, ByteBuf entry)
             throws IOException, BookieException {
+        long throttledStartTime = MathUtils.nowInNano();
         dbLedgerStorageStats.getThrottledWriteRequests().inc();
         long absoluteTimeoutNanos = System.nanoTime() + maxThrottleTimeNanos;
 
@@ -452,6 +453,7 @@ public class SingleDirectoryDbLedgerStorage implements CompactableLedgerStorage
             try {
                 if (writeCache.put(ledgerId, entryId, entry)) {
                     // We succeeded in putting the entry in write cache in the
+                    recordSuccessfulEvent(dbLedgerStorageStats.getThrottledWriteStats(), throttledStartTime);
                     return;
                 }
             } finally {
@@ -469,6 +471,7 @@ public class SingleDirectoryDbLedgerStorage implements CompactableLedgerStorage
 
         // Timeout expired and we weren't able to insert in write cache
         dbLedgerStorageStats.getRejectedWriteRequests().inc();
+        recordFailedEvent(dbLedgerStorageStats.getThrottledWriteStats(), throttledStartTime);
         throw new OperationRejectedException();
     }