bookkeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From si...@apache.org
Subject bookkeeper git commit: BOOKKEEPER-849: Collect stats with sub-milliseconds precision (Matteo Merli via sijie)
Date Tue, 21 Apr 2015 07:18:03 GMT
Repository: bookkeeper
Updated Branches:
  refs/heads/master 638b33256 -> 6622b46d4


BOOKKEEPER-849: Collect stats with sub-milliseconds precision (Matteo Merli via sijie)


Project: http://git-wip-us.apache.org/repos/asf/bookkeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/bookkeeper/commit/6622b46d
Tree: http://git-wip-us.apache.org/repos/asf/bookkeeper/tree/6622b46d
Diff: http://git-wip-us.apache.org/repos/asf/bookkeeper/diff/6622b46d

Branch: refs/heads/master
Commit: 6622b46d4979c92cd9c3f450e3832d63513c6a22
Parents: 638b332
Author: Sijie Guo <sijie@apache.org>
Authored: Tue Apr 21 00:17:45 2015 -0700
Committer: Sijie Guo <sijie@apache.org>
Committed: Tue Apr 21 00:17:45 2015 -0700

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 ++
 .../bookie/BookKeeperServerStats.java           |  1 +
 .../org/apache/bookkeeper/bookie/Bookie.java    | 34 +++++++++++---------
 .../apache/bookkeeper/bookie/EntryMemTable.java | 18 +++++------
 .../bookie/InterleavedLedgerStorage.java        | 11 ++++---
 .../org/apache/bookkeeper/bookie/Journal.java   | 13 ++++----
 .../bookkeeper/client/LedgerCreateOp.java       |  5 +--
 .../bookkeeper/client/LedgerDeleteOp.java       |  6 ++--
 .../apache/bookkeeper/client/LedgerOpenOp.java  |  6 ++--
 .../apache/bookkeeper/client/PendingAddOp.java  | 11 ++++---
 .../apache/bookkeeper/client/PendingReadOp.java | 10 +++---
 .../bookkeeper/proto/PacketProcessorBase.java   |  6 ++--
 .../bookkeeper/proto/PacketProcessorBaseV3.java |  6 ++--
 .../proto/PerChannelBookieClient.java           | 23 ++++++-------
 .../bookkeeper/proto/ReadEntryProcessor.java    |  6 ++--
 .../bookkeeper/proto/ReadEntryProcessorV3.java  |  6 ++--
 .../bookkeeper/proto/WriteEntryProcessor.java   | 10 ++++--
 .../bookkeeper/proto/WriteEntryProcessorV3.java |  7 ++--
 .../replication/ReplicationWorker.java          |  6 ++--
 .../org/apache/bookkeeper/util/MathUtils.java   | 11 +++++++
 .../bookkeeper/stats/CodahaleOpStatsLogger.java | 19 ++++++++---
 .../bookkeeper/stats/CodahaleOpStatsTest.java   |  2 +-
 .../twitter/ostrich/OpStatsLoggerImpl.java      | 22 ++++++++++---
 .../twitter/science/OpStatsLoggerImpl.java      | 16 ++++++---
 .../bookkeeper/stats/NullStatsLogger.java       | 16 +++++++--
 .../apache/bookkeeper/stats/OpStatsLogger.java  | 27 ++++++++++++----
 26 files changed, 200 insertions(+), 100 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 08c2705..308a0a4 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -67,6 +67,8 @@ Trunk (unreleased changes)
 
       BOOKKEEPER-844: Add more metrics about latency and bytes characteristics on bookie operations (Tong Yu via sijie)
 
+      BOOKKEEPER-849: Collect stats with sub-milliseconds precision (Matteo Merli via sijie)
+
       bookkeeper-client:
 
         BOOKKEEPER-810: Allow to configure TCP connect timeout (Charles Xie via sijie)

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookKeeperServerStats.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookKeeperServerStats.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookKeeperServerStats.java
index 9036182..c7919f7 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookKeeperServerStats.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookKeeperServerStats.java
@@ -44,6 +44,7 @@ public interface BookKeeperServerStats {
     public final static String BOOKIE_READ_ENTRY = "BOOKIE_READ_ENTRY";
 
     // Journal Stats
+    public final static String JOURNAL_SCOPE = "journal";
     public final static String JOURNAL_ADD_ENTRY = "JOURNAL_ADD_ENTRY";
     public final static String JOURNAL_MEM_ADD_ENTRY = "JOURNAL_MEM_ADD_ENTRY";
     public final static String JOURNAL_PREALLOCATION = "JOURNAL_PREALLOCATION";

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
index 8b40853..3078ff1 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
@@ -88,6 +88,7 @@ import static org.apache.bookkeeper.bookie.BookKeeperServerStats.LD_INDEX_SCOPE;
 import static org.apache.bookkeeper.bookie.BookKeeperServerStats.READ_BYTES;
 import static org.apache.bookkeeper.bookie.BookKeeperServerStats.SERVER_STATUS;
 import static org.apache.bookkeeper.bookie.BookKeeperServerStats.WRITE_BYTES;
+import static org.apache.bookkeeper.bookie.BookKeeperServerStats.JOURNAL_SCOPE;
 
 /**
  * Implements a bookie.
@@ -486,7 +487,8 @@ public class Bookie extends BookieCriticalThread {
         // directories are full, would throws exception and fail bookie startup.
         this.ledgerDirsManager.init();
         // instantiate the journal
-        journal = new Journal(conf, ledgerDirsManager);
+        journal = new Journal(conf, ledgerDirsManager, statsLogger.scope(JOURNAL_SCOPE));
+
         // Check the type of storage.
         if (conf.getSortedLedgerStorageEnabled()) {
             ledgerStorage = new SortedLedgerStorage(conf, ledgerManager,
@@ -1123,13 +1125,13 @@ public class Bookie extends BookieCriticalThread {
             transitionToReadOnlyMode();
             throw new IOException(e);
         } finally {
-            long elapsedMSec = MathUtils.elapsedMSec(requestNanos);
+            long elapsedNanos = MathUtils.elapsedNanos(requestNanos);
             if (success) {
-                recoveryAddEntryStats.registerSuccessfulEvent(elapsedMSec);
-                addBytesStats.registerSuccessfulEvent(entrySize);
+                recoveryAddEntryStats.registerSuccessfulEvent(elapsedNanos, TimeUnit.NANOSECONDS);
+                addBytesStats.registerSuccessfulValue(entrySize);
             } else {
-                recoveryAddEntryStats.registerFailedEvent(elapsedMSec);
-                addBytesStats.registerFailedEvent(entrySize);
+                recoveryAddEntryStats.registerFailedEvent(elapsedNanos, TimeUnit.NANOSECONDS);
+                addBytesStats.registerFailedValue(entrySize);
             }
         }
     }
@@ -1158,13 +1160,13 @@ public class Bookie extends BookieCriticalThread {
             transitionToReadOnlyMode();
             throw new IOException(e);
         } finally {
-            long elapsedMSec = MathUtils.elapsedMSec(requestNanos);
+            long elapsedNanos = MathUtils.elapsedNanos(requestNanos);
             if (success) {
-                addEntryStats.registerSuccessfulEvent(elapsedMSec);
-                addBytesStats.registerSuccessfulEvent(entrySize);
+                addEntryStats.registerSuccessfulEvent(elapsedNanos, TimeUnit.NANOSECONDS);
+                addBytesStats.registerSuccessfulValue(entrySize);
             } else {
-                addEntryStats.registerFailedEvent(elapsedMSec);
-                addBytesStats.registerFailedEvent(entrySize);
+                addEntryStats.registerFailedEvent(elapsedNanos, TimeUnit.NANOSECONDS);
+                addBytesStats.registerFailedValue(entrySize);
             }
         }
     }
@@ -1213,13 +1215,13 @@ public class Bookie extends BookieCriticalThread {
             success = true;
             return entry;
         } finally {
-            long elapsedMSec = MathUtils.elapsedMSec(requestNanos);
+            long elapsedNanos = MathUtils.elapsedNanos(requestNanos);
             if (success) {
-                readEntryStats.registerSuccessfulEvent(elapsedMSec);
-                readBytesStats.registerSuccessfulEvent(entrySize);
+                readEntryStats.registerSuccessfulEvent(elapsedNanos, TimeUnit.NANOSECONDS);
+                readBytesStats.registerSuccessfulValue(entrySize);
             } else {
-                readEntryStats.registerFailedEvent(elapsedMSec);
-                readBytesStats.registerFailedEvent(entrySize);
+                readEntryStats.registerFailedEvent(elapsedNanos, TimeUnit.NANOSECONDS);
+                readBytesStats.registerFailedValue(entrySize);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryMemTable.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryMemTable.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryMemTable.java
index 9fbe866..60da560 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryMemTable.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryMemTable.java
@@ -26,6 +26,7 @@ import java.nio.ByteBuffer;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import java.util.concurrent.ConcurrentSkipListMap;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.bookkeeper.stats.Counter;
 import org.apache.bookkeeper.stats.OpStatsLogger;
@@ -33,7 +34,6 @@ import org.apache.bookkeeper.stats.StatsLogger;
 import org.apache.bookkeeper.util.MathUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
 import org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint;
 import org.apache.bookkeeper.conf.ServerConfiguration;
 
@@ -187,9 +187,9 @@ public class EntryMemTable {
             }
 
             if (null != cp) {
-                snapshotStats.registerSuccessfulEvent(MathUtils.elapsedMSec(startTimeNanos));
+                snapshotStats.registerSuccessfulEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
             } else {
-                snapshotStats.registerFailedEvent(MathUtils.elapsedMSec(startTimeNanos));
+                snapshotStats.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
             }
         }
         return cp;
@@ -309,9 +309,9 @@ public class EntryMemTable {
             return size;
         } finally {
             if (success) {
-                putEntryStats.registerSuccessfulEvent(MathUtils.elapsedMSec(startTimeNanos));
+                putEntryStats.registerSuccessfulEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
             } else {
-                putEntryStats.registerFailedEvent(MathUtils.elapsedMSec(startTimeNanos));
+                putEntryStats.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
             }
         }
     }
@@ -382,9 +382,9 @@ public class EntryMemTable {
         } finally {
             this.lock.readLock().unlock();
             if (success) {
-                getEntryStats.registerSuccessfulEvent(MathUtils.elapsedMSec(startTimeNanos));
+                getEntryStats.registerSuccessfulEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
             } else {
-                getEntryStats.registerFailedEvent(MathUtils.elapsedMSec(startTimeNanos));
+                getEntryStats.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
             }
         }
 
@@ -411,9 +411,9 @@ public class EntryMemTable {
         } finally {
             this.lock.readLock().unlock();
             if (success) {
-                getEntryStats.registerSuccessfulEvent(MathUtils.elapsedMSec(startTimeNanos));
+                getEntryStats.registerSuccessfulEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
             } else {
-                getEntryStats.registerFailedEvent(MathUtils.elapsedMSec(startTimeNanos));
+                getEntryStats.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/InterleavedLedgerStorage.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/InterleavedLedgerStorage.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/InterleavedLedgerStorage.java
index 1a69692..5ee9ab0 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/InterleavedLedgerStorage.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/InterleavedLedgerStorage.java
@@ -28,6 +28,9 @@ import java.nio.ByteBuffer;
 import org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint;
 import org.apache.bookkeeper.bookie.EntryLogger.EntryLogListener;
 import org.apache.bookkeeper.bookie.LedgerDirsManager.LedgerDirsListener;
+
+import java.util.concurrent.TimeUnit;
+
 import org.apache.bookkeeper.conf.ServerConfiguration;
 import org.apache.bookkeeper.jmx.BKMBeanInfo;
 import org.apache.bookkeeper.meta.LedgerManager;
@@ -232,9 +235,9 @@ class InterleavedLedgerStorage implements LedgerStorage, EntryLogListener {
             success = true;
         } finally {
             if (success) {
-                getOffsetStats.registerSuccessfulEvent(MathUtils.elapsedMSec(startTimeNanos));
+                getOffsetStats.registerSuccessfulEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
             } else {
-                getOffsetStats.registerFailedEvent(MathUtils.elapsedMSec(startTimeNanos));
+                getOffsetStats.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
             }
         }
         // Get Entry
@@ -246,9 +249,9 @@ class InterleavedLedgerStorage implements LedgerStorage, EntryLogListener {
             return ByteBuffer.wrap(retBytes);
         } finally {
             if (success) {
-                getEntryStats.registerSuccessfulEvent(MathUtils.elapsedMSec(startTimeNanos));
+                getEntryStats.registerSuccessfulEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
             } else {
-                getEntryStats.registerFailedEvent(MathUtils.elapsedMSec(startTimeNanos));
+                getEntryStats.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java
index 7384330..cc61aa5 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java
@@ -342,7 +342,8 @@ class Journal extends BookieCriticalThread implements CheckpointSource {
         @Override
         public void run() {
             for (QueueEntry e : this.forceWriteWaiters) {
-                journalAddEntryStats.registerSuccessfulEvent(MathUtils.elapsedMSec(e.enqueueTime));
+                journalAddEntryStats.registerSuccessfulEvent(MathUtils.elapsedNanos(e.enqueueTime),
+                        TimeUnit.NANOSECONDS);
                 e.callback();    // Process cbs inline
             }
         }
@@ -406,7 +407,7 @@ class Journal extends BookieCriticalThread implements CheckpointSource {
                             // the last force write and then reset the counter so we can accumulate
                             // requests in the write we are about to issue
                             if (numReqInLastForceWrite > 0) {
-                                forceWriteGroupingCountStats.registerSuccessfulEvent(numReqInLastForceWrite);
+                                forceWriteGroupingCountStats.registerSuccessfulValue(numReqInLastForceWrite);
                                 numReqInLastForceWrite = 0;
                             }
                         }
@@ -810,7 +811,7 @@ class Journal extends BookieCriticalThread implements CheckpointSource {
                                         removePagesFromCache,
                                         conf.getJournalFormatVersionToWrite());
                     journalCreationStats.registerSuccessfulEvent(
-                            journalCreationWatcher.stop().elapsedTime(TimeUnit.MILLISECONDS));
+                            journalCreationWatcher.stop().elapsedTime(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);
 
                     bc = logFile.getBufferedChannel();
 
@@ -864,7 +865,7 @@ class Journal extends BookieCriticalThread implements CheckpointSource {
                             bc.flush(false);
                             lastFlushPosition = bc.position();
                             journalFlushStats.registerSuccessfulEvent(
-                                    journalFlushWatcher.stop().elapsedTime(TimeUnit.MILLISECONDS));
+                                    journalFlushWatcher.stop().elapsedTime(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);
 
                             // Trace the lifetime of entries through persistence
                             if (LOG.isDebugEnabled()) {
@@ -873,8 +874,8 @@ class Journal extends BookieCriticalThread implements CheckpointSource {
                                 }
                             }
 
-                            forceWriteBatchEntriesStats.registerSuccessfulEvent(toFlush.size());
-                            forceWriteBatchBytesStats.registerSuccessfulEvent(batchSize);
+                            forceWriteBatchEntriesStats.registerSuccessfulValue(toFlush.size());
+                            forceWriteBatchBytesStats.registerSuccessfulValue(batchSize);
 
                             forceWriteRequests.put(new ForceWriteRequest(logFile, logId, lastFlushPosition, toFlush, (lastFlushPosition > maxJournalSize), false));
                             toFlush = new LinkedList<QueueEntry>();

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerCreateOp.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerCreateOp.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerCreateOp.java
index fe223af..9cda8ca 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerCreateOp.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerCreateOp.java
@@ -23,6 +23,7 @@ package org.apache.bookkeeper.client;
 
 import java.security.GeneralSecurityException;
 import java.util.ArrayList;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.bookkeeper.client.AsyncCallback.CreateCallback;
 import org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException;
@@ -142,9 +143,9 @@ class LedgerCreateOp implements GenericCallback<Long> {
     private void createComplete(int rc, LedgerHandle lh) {
         // Opened a new ledger
         if (BKException.Code.OK != rc) {
-            createOpLogger.registerFailedEvent(MathUtils.elapsedMSec(startTime));
+            createOpLogger.registerFailedEvent(MathUtils.elapsedNanos(startTime), TimeUnit.NANOSECONDS);
         } else {
-            createOpLogger.registerSuccessfulEvent(MathUtils.elapsedMSec(startTime));
+            createOpLogger.registerSuccessfulEvent(MathUtils.elapsedNanos(startTime), TimeUnit.NANOSECONDS);
         }
         cb.createComplete(rc, lh, ctx);
     }

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerDeleteOp.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerDeleteOp.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerDeleteOp.java
index b41d15a..13ce1fd 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerDeleteOp.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerDeleteOp.java
@@ -21,6 +21,8 @@
 
 package org.apache.bookkeeper.client;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.bookkeeper.client.AsyncCallback.DeleteCallback;
 import org.apache.bookkeeper.stats.OpStatsLogger;
 import org.apache.bookkeeper.util.MathUtils;
@@ -81,9 +83,9 @@ class LedgerDeleteOp extends OrderedSafeGenericCallback<Void> {
     @Override
     public void safeOperationComplete(int rc, Void result) {
         if (BKException.Code.OK != rc) {
-            deleteOpLogger.registerFailedEvent(MathUtils.elapsedMSec(startTime));
+            deleteOpLogger.registerFailedEvent(MathUtils.elapsedNanos(startTime), TimeUnit.NANOSECONDS);
         } else {
-            deleteOpLogger.registerSuccessfulEvent(MathUtils.elapsedMSec(startTime));
+            deleteOpLogger.registerSuccessfulEvent(MathUtils.elapsedNanos(startTime), TimeUnit.NANOSECONDS);
         }
         cb.deleteComplete(rc, this.ctx);
     }

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerOpenOp.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerOpenOp.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerOpenOp.java
index eb145bd..69a09e9 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerOpenOp.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerOpenOp.java
@@ -22,6 +22,7 @@
 package org.apache.bookkeeper.client;
 
 import java.util.Arrays;
+import java.util.concurrent.TimeUnit;
 import java.security.GeneralSecurityException;
 
 import org.apache.bookkeeper.client.AsyncCallback.OpenCallback;
@@ -31,7 +32,6 @@ import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback;
 import org.apache.bookkeeper.stats.OpStatsLogger;
 import org.apache.bookkeeper.util.MathUtils;
 import org.apache.bookkeeper.util.OrderedSafeExecutor.OrderedSafeGenericCallback;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -196,9 +196,9 @@ class LedgerOpenOp implements GenericCallback<LedgerMetadata> {
 
     void openComplete(int rc, LedgerHandle lh) {
         if (BKException.Code.OK != rc) {
-            openOpLogger.registerFailedEvent(MathUtils.elapsedMSec(startTime));
+            openOpLogger.registerFailedEvent(MathUtils.elapsedNanos(startTime), TimeUnit.NANOSECONDS);
         } else {
-            openOpLogger.registerSuccessfulEvent(MathUtils.elapsedMSec(startTime));
+            openOpLogger.registerSuccessfulEvent(MathUtils.elapsedNanos(startTime), TimeUnit.NANOSECONDS);
         }
         cb.openComplete(rc, lh, ctx);
     }

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingAddOp.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingAddOp.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingAddOp.java
index 1b92d09..fb87677 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingAddOp.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingAddOp.java
@@ -19,6 +19,7 @@ package org.apache.bookkeeper.client;
 
 import java.util.HashSet;
 import java.util.Set;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.bookkeeper.client.AsyncCallback.AddCallback;
 import org.apache.bookkeeper.net.BookieSocketAddress;
@@ -54,7 +55,7 @@ class PendingAddOp implements WriteCallback {
 
     LedgerHandle lh;
     boolean isRecoveryAdd = false;
-    long requestTimeMillis;
+    long requestTimeNanos;
     OpStatsLogger addOpLogger;
 
     PendingAddOp(LedgerHandle lh, AddCallback cb, Object ctx) {
@@ -130,7 +131,7 @@ class PendingAddOp implements WriteCallback {
     }
 
     void initiate(ChannelBuffer toSend, int entryLength) {
-        requestTimeMillis = MathUtils.now();
+        requestTimeNanos = MathUtils.nowInNano();
         this.toSend = toSend;
         this.entryLength = entryLength;
         for (int bookieIndex : writeSet) {
@@ -189,13 +190,13 @@ class PendingAddOp implements WriteCallback {
     }
 
     void submitCallback(final int rc) {
-        long latencyMillis = MathUtils.now() - requestTimeMillis;
+        long latencyNanos = MathUtils.elapsedNanos(requestTimeNanos);
         if (rc != BKException.Code.OK) {
-            addOpLogger.registerFailedEvent(latencyMillis);
+            addOpLogger.registerFailedEvent(latencyNanos, TimeUnit.NANOSECONDS);
             LOG.error("Write of ledger entry to quorum failed: L{} E{}",
                       lh.getId(), entryId);
         } else {
-            addOpLogger.registerSuccessfulEvent(latencyMillis);
+            addOpLogger.registerSuccessfulEvent(latencyNanos, TimeUnit.NANOSECONDS);
         }
         cb.addComplete(rc, lh, entryId, ctx);
     }

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingReadOp.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingReadOp.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingReadOp.java
index e548f3d..102d38e 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingReadOp.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingReadOp.java
@@ -67,7 +67,7 @@ class PendingReadOp implements Enumeration<LedgerEntry>, ReadEntryCallback {
     long numPendingEntries;
     long startEntryId;
     long endEntryId;
-    long requestTimeMillis;
+    long requestTimeNanos;
     OpStatsLogger readOpLogger;
 
     final int maxMissedReadsAllowed;
@@ -285,7 +285,7 @@ class PendingReadOp implements Enumeration<LedgerEntry>, ReadEntryCallback {
 
     public void initiate() throws InterruptedException {
         long nextEnsembleChange = startEntryId, i = startEntryId;
-        this.requestTimeMillis = MathUtils.now();
+        this.requestTimeNanos = MathUtils.nowInNano();
         ArrayList<BookieSocketAddress> ensemble = null;
 
         if (speculativeReadTimeout > 0) {
@@ -373,7 +373,7 @@ class PendingReadOp implements Enumeration<LedgerEntry>, ReadEntryCallback {
     }
 
     private void submitCallback(int code) {
-        long latencyMillis = MathUtils.now() - requestTimeMillis;
+        long latencyNanos = MathUtils.elapsedNanos(requestTimeNanos);
         if (code != BKException.Code.OK) {
             long firstUnread = LedgerHandle.INVALID_ENTRY_ID;
             for (LedgerEntryRequest req : seq) {
@@ -384,9 +384,9 @@ class PendingReadOp implements Enumeration<LedgerEntry>, ReadEntryCallback {
             }
             LOG.error("Read of ledger entry failed: L{} E{}-E{}, Heard from {}. First unread entry is {}",
                     new Object[] { lh.getId(), startEntryId, endEntryId, heardFromHosts, firstUnread });
-            readOpLogger.registerFailedEvent(latencyMillis);
+            readOpLogger.registerFailedEvent(latencyNanos, TimeUnit.NANOSECONDS);
         } else {
-            readOpLogger.registerSuccessfulEvent(latencyMillis);
+            readOpLogger.registerSuccessfulEvent(latencyNanos, TimeUnit.NANOSECONDS);
         }
         cancelSpeculativeTask(true);
         cb.readComplete(code, lh, PendingReadOp.this, PendingReadOp.this.ctx);

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PacketProcessorBase.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PacketProcessorBase.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PacketProcessorBase.java
index b247616..a2dc4d8 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PacketProcessorBase.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PacketProcessorBase.java
@@ -17,6 +17,8 @@
  */
 package org.apache.bookkeeper.proto;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.bookkeeper.client.BKException;
 import org.apache.bookkeeper.proto.BookieProtocol.Request;
 import org.apache.bookkeeper.stats.OpStatsLogger;
@@ -55,9 +57,9 @@ abstract class PacketProcessorBase implements Runnable {
     protected void sendResponse(int rc, Object response, OpStatsLogger statsLogger) {
         channel.write(response);
         if (BookieProtocol.EOK == rc) {
-            statsLogger.registerSuccessfulEvent(MathUtils.elapsedMSec(enqueueNanos));
+            statsLogger.registerSuccessfulEvent(MathUtils.elapsedNanos(enqueueNanos), TimeUnit.NANOSECONDS);
         } else {
-            statsLogger.registerFailedEvent(MathUtils.elapsedMSec(enqueueNanos));
+            statsLogger.registerFailedEvent(MathUtils.elapsedNanos(enqueueNanos), TimeUnit.NANOSECONDS);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PacketProcessorBaseV3.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PacketProcessorBaseV3.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PacketProcessorBaseV3.java
index ebff526..0d7bbee 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PacketProcessorBaseV3.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PacketProcessorBaseV3.java
@@ -20,6 +20,8 @@
  */
 package org.apache.bookkeeper.proto;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.bookkeeper.proto.BookkeeperProtocol.BKPacketHeader;
 import org.apache.bookkeeper.proto.BookkeeperProtocol.ProtocolVersion;
 import org.apache.bookkeeper.proto.BookkeeperProtocol.Request;
@@ -46,9 +48,9 @@ public abstract class PacketProcessorBaseV3 {
     protected void sendResponse(StatusCode code, Object response, OpStatsLogger statsLogger) {
         channel.write(response);
         if (StatusCode.EOK == code) {
-            statsLogger.registerSuccessfulEvent(MathUtils.elapsedMSec(enqueueNanos));
+            statsLogger.registerSuccessfulEvent(MathUtils.elapsedNanos(enqueueNanos), TimeUnit.NANOSECONDS);
         } else {
-            statsLogger.registerFailedEvent(MathUtils.elapsedMSec(enqueueNanos));
+            statsLogger.registerFailedEvent(MathUtils.elapsedNanos(enqueueNanos), TimeUnit.NANOSECONDS);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java
index 1dbc850..34b0362 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java
@@ -825,16 +825,16 @@ public class PerChannelBookieClient extends SimpleChannelHandler implements Chan
                               final Object originalCtx, final long ledgerId, final long entryId,
                               final Timeout timeout) {
             super(originalCtx, ledgerId, entryId, timeout);
-            final long requestTimeMillis = MathUtils.now();
+            final long startTime = MathUtils.nowInNano();
             this.cb = null == readEntryOpLogger ? originalCallback : new ReadEntryCallback() {
                 @Override
                 public void readEntryComplete(int rc, long ledgerId, long entryId, ChannelBuffer buffer, Object ctx) {
                     cancelTimeout();
-                    long latencyMillis = MathUtils.now() - requestTimeMillis;
+                    long latency = MathUtils.elapsedNanos(startTime);
                     if (rc != BKException.Code.OK) {
-                        readEntryOpLogger.registerFailedEvent(latencyMillis);
+                        readEntryOpLogger.registerFailedEvent(latency, TimeUnit.NANOSECONDS);
                     } else {
-                        readEntryOpLogger.registerSuccessfulEvent(latencyMillis);
+                        readEntryOpLogger.registerSuccessfulEvent(latency, TimeUnit.NANOSECONDS);
                     }
                     originalCallback.readEntryComplete(rc, ledgerId, entryId, buffer, originalCtx);
                 }
@@ -856,16 +856,16 @@ public class PerChannelBookieClient extends SimpleChannelHandler implements Chan
                              final Object originalCtx, final long ledgerId, final long entryId,
                              final Timeout timeout) {
             super(originalCtx, ledgerId, entryId, timeout);
-            final long requestTimeMillis = MathUtils.now();
+            final long startTime = MathUtils.nowInNano();
             this.cb = null == addEntryOpLogger ? originalCallback : new WriteCallback() {
                 @Override
                 public void writeComplete(int rc, long ledgerId, long entryId, BookieSocketAddress addr, Object ctx) {
                     cancelTimeout();
-                    long latencyMillis = MathUtils.now() - requestTimeMillis;
+                    long latency = MathUtils.elapsedNanos(startTime);
                     if (rc != BKException.Code.OK) {
-                        addEntryOpLogger.registerFailedEvent(latencyMillis);
+                        addEntryOpLogger.registerFailedEvent(latency, TimeUnit.NANOSECONDS);
                     } else {
-                        addEntryOpLogger.registerSuccessfulEvent(latencyMillis);
+                        addEntryOpLogger.registerSuccessfulEvent(latency, TimeUnit.NANOSECONDS);
                     }
                     originalCallback.writeComplete(rc, ledgerId, entryId, addr, originalCtx);
                 }
@@ -917,7 +917,7 @@ public class PerChannelBookieClient extends SimpleChannelHandler implements Chan
         }
 
         private long elapsedTime() {
-            return MathUtils.elapsedMSec(requestAt);
+            return MathUtils.elapsedNanos(requestAt);
         }
 
         @Override
@@ -927,14 +927,15 @@ public class PerChannelBookieClient extends SimpleChannelHandler implements Chan
             }
             if (OperationType.ADD_ENTRY == operationType) {
                 errorOutAddKey(this);
-                addTimeoutOpLogger.registerSuccessfulEvent(elapsedTime());
+                addTimeoutOpLogger.registerSuccessfulEvent(elapsedTime(), TimeUnit.NANOSECONDS);
             } else {
                 errorOutReadKey(this);
-                readTimeoutOpLogger.registerSuccessfulEvent(elapsedTime());
+                readTimeoutOpLogger.registerSuccessfulEvent(elapsedTime(), TimeUnit.NANOSECONDS);
             }
         }
     }
 
+
     /**
      * Note : Helper functions follow
      */

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/ReadEntryProcessor.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/ReadEntryProcessor.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/ReadEntryProcessor.java
index 385cf02..7c17bb1 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/ReadEntryProcessor.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/ReadEntryProcessor.java
@@ -120,12 +120,14 @@ class ReadEntryProcessor extends PacketProcessorBase {
         LOG.trace("Read entry rc = {} for {}",
                 new Object[] { errorCode, read });
         if (errorCode == BookieProtocol.EOK) {
-            requestProcessor.readEntryStats.registerSuccessfulEvent(MathUtils.elapsedMSec(startTimeNanos));
+            requestProcessor.readEntryStats.registerSuccessfulEvent(MathUtils.elapsedNanos(startTimeNanos),
+                    TimeUnit.NANOSECONDS);
             sendResponse(errorCode, ResponseBuilder.buildReadResponse(data, read),
                          requestProcessor.readRequestStats);
 
         } else {
-            requestProcessor.readEntryStats.registerFailedEvent(MathUtils.elapsedMSec(startTimeNanos));
+            requestProcessor.readEntryStats.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos),
+                    TimeUnit.NANOSECONDS);
             sendResponse(errorCode, ResponseBuilder.buildErrorResponse(errorCode, read),
                          requestProcessor.readRequestStats);
         }

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/ReadEntryProcessorV3.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/ReadEntryProcessorV3.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/ReadEntryProcessorV3.java
index 0351778..4073d41 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/ReadEntryProcessorV3.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/ReadEntryProcessorV3.java
@@ -134,9 +134,11 @@ class ReadEntryProcessorV3 extends PacketProcessorBaseV3 implements Runnable {
         }
 
         if (status == StatusCode.EOK) {
-            requestProcessor.readEntryStats.registerSuccessfulEvent(MathUtils.elapsedMSec(startTimeNanos));
+            requestProcessor.readEntryStats.registerSuccessfulEvent(MathUtils.elapsedNanos(startTimeNanos),
+                    TimeUnit.NANOSECONDS);
         } else {
-            requestProcessor.readEntryStats.registerFailedEvent(MathUtils.elapsedMSec(startTimeNanos));
+            requestProcessor.readEntryStats.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos),
+                    TimeUnit.NANOSECONDS);
         }
 
         // Finally set status and return. The body would have been updated if

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/WriteEntryProcessor.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/WriteEntryProcessor.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/WriteEntryProcessor.java
index 719c937..f493d73 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/WriteEntryProcessor.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/WriteEntryProcessor.java
@@ -18,6 +18,7 @@
 package org.apache.bookkeeper.proto;
 
 import java.io.IOException;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.bookkeeper.bookie.BookieException;
 import org.apache.bookkeeper.net.BookieSocketAddress;
@@ -77,7 +78,8 @@ class WriteEntryProcessor extends PacketProcessorBase implements WriteCallback {
             rc = BookieProtocol.EUA;
         }
         if (rc != BookieProtocol.EOK) {
-            requestProcessor.addEntryStats.registerFailedEvent(MathUtils.elapsedMSec(startTimeNanos));
+            requestProcessor.addEntryStats.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos),
+                    TimeUnit.NANOSECONDS);
             sendResponse(rc,
                          ResponseBuilder.buildErrorResponse(rc, add),
                          requestProcessor.addRequestStats);
@@ -88,9 +90,11 @@ class WriteEntryProcessor extends PacketProcessorBase implements WriteCallback {
     public void writeComplete(int rc, long ledgerId, long entryId,
                               BookieSocketAddress addr, Object ctx) {
         if (BookieProtocol.EOK == rc) {
-            requestProcessor.addEntryStats.registerSuccessfulEvent(MathUtils.elapsedMSec(startTimeNanos));
+            requestProcessor.addEntryStats.registerSuccessfulEvent(MathUtils.elapsedNanos(startTimeNanos),
+                    TimeUnit.NANOSECONDS);
         } else {
-            requestProcessor.addEntryStats.registerFailedEvent(MathUtils.elapsedMSec(startTimeNanos));
+            requestProcessor.addEntryStats.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos),
+                    TimeUnit.NANOSECONDS);
         }
         sendResponse(rc,
                      ResponseBuilder.buildAddResponse(request),

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/WriteEntryProcessorV3.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/WriteEntryProcessorV3.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/WriteEntryProcessorV3.java
index ebb9ebe..6517d8f 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/WriteEntryProcessorV3.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/WriteEntryProcessorV3.java
@@ -22,6 +22,7 @@ package org.apache.bookkeeper.proto;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.bookkeeper.bookie.BookieException;
 import org.apache.bookkeeper.net.BookieSocketAddress;
@@ -70,9 +71,11 @@ class WriteEntryProcessorV3 extends PacketProcessorBaseV3 implements Runnable {
             public void writeComplete(int rc, long ledgerId, long entryId,
                                       BookieSocketAddress addr, Object ctx) {
                 if (BookieProtocol.EOK == rc) {
-                    requestProcessor.addEntryStats.registerSuccessfulEvent(MathUtils.elapsedMSec(startTimeNanos));
+                    requestProcessor.addEntryStats.registerSuccessfulEvent(MathUtils.elapsedNanos(startTimeNanos),
+                            TimeUnit.NANOSECONDS);
                 } else {
-                    requestProcessor.addEntryStats.registerFailedEvent(MathUtils.elapsedMSec(startTimeNanos));
+                    requestProcessor.addEntryStats.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos),
+                            TimeUnit.NANOSECONDS);
                 }
 
                 StatusCode status;

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/ReplicationWorker.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/ReplicationWorker.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/ReplicationWorker.java
index 02154e5..4239b6a 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/ReplicationWorker.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/ReplicationWorker.java
@@ -28,8 +28,10 @@ import java.util.SortedMap;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 import com.google.common.base.Stopwatch;
+
 import org.apache.bookkeeper.bookie.BookieThread;
 import org.apache.bookkeeper.client.BKException;
 import org.apache.bookkeeper.client.BKException.BKBookieHandleNotAvailableException;
@@ -189,9 +191,9 @@ public class ReplicationWorker implements Runnable {
         } finally {
             long latencyMillis = stopwatch.stop().elapsedMillis();
             if (success) {
-                rereplicateOpStats.registerSuccessfulEvent(latencyMillis);
+                rereplicateOpStats.registerSuccessfulEvent(latencyMillis, TimeUnit.MILLISECONDS);
             } else {
-                rereplicateOpStats.registerFailedEvent(latencyMillis);
+                rereplicateOpStats.registerFailedEvent(latencyMillis, TimeUnit.MILLISECONDS);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/MathUtils.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/MathUtils.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/MathUtils.java
index 32571fa..4cff2bb 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/MathUtils.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/MathUtils.java
@@ -73,4 +73,15 @@ public class MathUtils {
     public static long elapsedMSec (long startNanoTime) {
        return (System.nanoTime() - startNanoTime)/ NANOSECONDS_PER_MILLISECOND;
     }
+
+    /**
+     * Nanoseconds elapsed since the time specified, the input is nanoTime
+     * the only conversion happens when computing the elapsed time
+     *
+     * @param startNanoTime the start of the interval that we are measuring
+     * @return elapsed time in milliseconds.
+     */
+    public static long elapsedNanos(long startNanoTime) {
+       return System.nanoTime() - startNanoTime;
+    }
 }

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-stats-providers/codahale-metrics-provider/src/main/java/org/apache/bookkeeper/stats/CodahaleOpStatsLogger.java
----------------------------------------------------------------------
diff --git a/bookkeeper-stats-providers/codahale-metrics-provider/src/main/java/org/apache/bookkeeper/stats/CodahaleOpStatsLogger.java b/bookkeeper-stats-providers/codahale-metrics-provider/src/main/java/org/apache/bookkeeper/stats/CodahaleOpStatsLogger.java
index 29308a8..fa25059 100644
--- a/bookkeeper-stats-providers/codahale-metrics-provider/src/main/java/org/apache/bookkeeper/stats/CodahaleOpStatsLogger.java
+++ b/bookkeeper-stats-providers/codahale-metrics-provider/src/main/java/org/apache/bookkeeper/stats/CodahaleOpStatsLogger.java
@@ -23,7 +23,6 @@ import com.codahale.metrics.Timer;
 import com.codahale.metrics.Snapshot;
 
 import java.util.Arrays;
-import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
 class CodahaleOpStatsLogger implements OpStatsLogger {
@@ -36,12 +35,22 @@ class CodahaleOpStatsLogger implements OpStatsLogger {
     }
 
     // OpStatsLogger functions
-    public void registerFailedEvent(long eventLatencyMillis) {
-        fail.update(eventLatencyMillis, TimeUnit.MILLISECONDS);
+    public void registerFailedEvent(long eventLatency, TimeUnit unit) {
+        fail.update(eventLatency, unit);
     }
 
-    public void registerSuccessfulEvent(long eventLatencyMillis) {
-        success.update(eventLatencyMillis, TimeUnit.MILLISECONDS);
+    public void registerSuccessfulEvent(long eventLatency, TimeUnit unit) {
+        success.update(eventLatency, unit);
+    }
+
+    public void registerSuccessfulValue(long value) {
+        // Values are inserted as millis, which is the unit they will be presented, to maintain 1:1 scale
+        success.update(value, TimeUnit.MILLISECONDS);
+    }
+
+    public void registerFailedValue(long value) {
+        // Values are inserted as millis, which is the unit they will be presented, to maintain 1:1 scale
+        fail.update(value, TimeUnit.MILLISECONDS);
     }
 
     public synchronized void clear() {

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-stats-providers/codahale-metrics-provider/src/test/java/org/apache/bookkeeper/stats/CodahaleOpStatsTest.java
----------------------------------------------------------------------
diff --git a/bookkeeper-stats-providers/codahale-metrics-provider/src/test/java/org/apache/bookkeeper/stats/CodahaleOpStatsTest.java b/bookkeeper-stats-providers/codahale-metrics-provider/src/test/java/org/apache/bookkeeper/stats/CodahaleOpStatsTest.java
index d7f64e9..4cc22fa 100644
--- a/bookkeeper-stats-providers/codahale-metrics-provider/src/test/java/org/apache/bookkeeper/stats/CodahaleOpStatsTest.java
+++ b/bookkeeper-stats-providers/codahale-metrics-provider/src/test/java/org/apache/bookkeeper/stats/CodahaleOpStatsTest.java
@@ -23,7 +23,7 @@ public class CodahaleOpStatsTest {
     @org.junit.Test
     public void testToOpStatsData() {
         OpStatsLogger logger = new CodahaleMetricsProvider().getStatsLogger("test").getOpStatsLogger("testLogger");
-        logger.registerSuccessfulEvent(1);
+        logger.registerSuccessfulValue(1);
         // the following should not throw any exception
         OpStatsData statsData = logger.toOpStatsData();
         assertEquals(1, statsData.getNumSuccessfulEvents());

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-stats-providers/twitter-ostrich-provider/src/main/java/org/apache/bookkeeper/stats/twitter/ostrich/OpStatsLoggerImpl.java
----------------------------------------------------------------------
diff --git a/bookkeeper-stats-providers/twitter-ostrich-provider/src/main/java/org/apache/bookkeeper/stats/twitter/ostrich/OpStatsLoggerImpl.java b/bookkeeper-stats-providers/twitter-ostrich-provider/src/main/java/org/apache/bookkeeper/stats/twitter/ostrich/OpStatsLoggerImpl.java
index ba969ba..3e8eeb9 100644
--- a/bookkeeper-stats-providers/twitter-ostrich-provider/src/main/java/org/apache/bookkeeper/stats/twitter/ostrich/OpStatsLoggerImpl.java
+++ b/bookkeeper-stats-providers/twitter-ostrich-provider/src/main/java/org/apache/bookkeeper/stats/twitter/ostrich/OpStatsLoggerImpl.java
@@ -16,6 +16,8 @@
  */
 package org.apache.bookkeeper.stats.twitter.ostrich;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.bookkeeper.stats.OpStatsData;
 import org.apache.bookkeeper.stats.OpStatsLogger;
 
@@ -44,18 +46,30 @@ class OpStatsLoggerImpl implements OpStatsLogger {
     }
 
     @Override
-    public void registerFailedEvent(long eventLatencyMillis) {
-        failureMetric.add((int)eventLatencyMillis);
+    public void registerFailedEvent(long eventLatency, TimeUnit unit) {
+        failureMetric.add((int) unit.toMillis(eventLatency));
         failureCounter.incr();
     }
 
     @Override
-    public void registerSuccessfulEvent(long eventLatencyMillis) {
-        successMetric.add((int)eventLatencyMillis);
+    public void registerSuccessfulEvent(long eventLatency, TimeUnit unit) {
+        successMetric.add((int) unit.toMillis(eventLatency));
+        successCounter.incr();
+    }
+
+    @Override
+    public void registerSuccessfulValue(long value) {
+        successMetric.add((int) value);
         successCounter.incr();
     }
 
     @Override
+    public void registerFailedValue(long value) {
+        failureMetric.add((int) value);
+        failureCounter.incr();
+    }
+
+    @Override
     public OpStatsData toOpStatsData() {
         long numSuccess = successCounter.apply();
         long numFailures = failureCounter.apply();

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-stats-providers/twitter-science-provider/src/main/java/org/apache/bookkeeper/stats/twitter/science/OpStatsLoggerImpl.java
----------------------------------------------------------------------
diff --git a/bookkeeper-stats-providers/twitter-science-provider/src/main/java/org/apache/bookkeeper/stats/twitter/science/OpStatsLoggerImpl.java b/bookkeeper-stats-providers/twitter-science-provider/src/main/java/org/apache/bookkeeper/stats/twitter/science/OpStatsLoggerImpl.java
index ac236f6..77c4bff 100644
--- a/bookkeeper-stats-providers/twitter-science-provider/src/main/java/org/apache/bookkeeper/stats/twitter/science/OpStatsLoggerImpl.java
+++ b/bookkeeper-stats-providers/twitter-science-provider/src/main/java/org/apache/bookkeeper/stats/twitter/science/OpStatsLoggerImpl.java
@@ -36,12 +36,20 @@ public class OpStatsLoggerImpl implements OpStatsLogger {
     }
 
     // OpStatsLogger functions
-    public void registerFailedEvent(long eventLatencyMillis) {
-        this.events.incErrors(TimeUnit.MILLISECONDS.toMicros(eventLatencyMillis));
+    public void registerFailedEvent(long eventLatency, TimeUnit unit) {
+        this.events.incErrors(unit.toMicros(eventLatency));
     }
 
-    public void registerSuccessfulEvent(long eventLatencyMillis) {
-        this.events.requestComplete(TimeUnit.MILLISECONDS.toMicros(eventLatencyMillis));
+    public void registerSuccessfulEvent(long eventLatency, TimeUnit unit) {
+        this.events.requestComplete(unit.toMicros(eventLatency));
+    }
+
+    public void registerSuccessfulValue(long value) {
+        this.events.requestComplete(TimeUnit.MILLISECONDS.toMicros(value));
+    }
+
+    public void registerFailedValue(long value) {
+        this.events.incErrors(TimeUnit.MILLISECONDS.toMicros(value));
     }
 
     public synchronized void clear() {

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/NullStatsLogger.java
----------------------------------------------------------------------
diff --git a/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/NullStatsLogger.java b/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/NullStatsLogger.java
index 21a103d..3fc1049 100644
--- a/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/NullStatsLogger.java
+++ b/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/NullStatsLogger.java
@@ -16,6 +16,8 @@
  */
 package org.apache.bookkeeper.stats;
 
+import java.util.concurrent.TimeUnit;
+
 public class NullStatsLogger implements StatsLogger {
 
     public static final NullStatsLogger INSTANCE = new NullStatsLogger();
@@ -24,12 +26,22 @@ public class NullStatsLogger implements StatsLogger {
         final OpStatsData nullOpStats = new OpStatsData(0, 0, 0, new long[6]);
 
         @Override
-        public void registerFailedEvent(long eventLatencyMillis) {
+        public void registerFailedEvent(long eventLatency, TimeUnit unit) {
+            // nop
+        }
+
+        @Override
+        public void registerSuccessfulEvent(long eventLatency, TimeUnit unit) {
+            // nop
+        }
+
+        @Override
+        public void registerSuccessfulValue(long value) {
             // nop
         }
 
         @Override
-        public void registerSuccessfulEvent(long eventLatencyMillis) {
+        public void registerFailedValue(long value) {
             // nop
         }
 

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/6622b46d/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/OpStatsLogger.java
----------------------------------------------------------------------
diff --git a/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/OpStatsLogger.java b/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/OpStatsLogger.java
index ca0477f..bbd6992 100644
--- a/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/OpStatsLogger.java
+++ b/bookkeeper-stats/src/main/java/org/apache/bookkeeper/stats/OpStatsLogger.java
@@ -16,6 +16,8 @@
  */
 package org.apache.bookkeeper.stats;
 
+import java.util.concurrent.TimeUnit;
+
 /**
  * This interface handles logging of statistics related to each operation (PUBLISH,
  * CONSUME etc.)
@@ -23,17 +25,30 @@ package org.apache.bookkeeper.stats;
 public interface OpStatsLogger {
 
     /**
-     * Increment the failed op counter with the given eventLatencyMillis.
-     * @param eventLatencyMillis The event latency in milliseconds.
+     * Increment the failed op counter with the given eventLatency.
+     * @param eventLatencyMillis The event latency
+     * @param unit
      */
-    public void registerFailedEvent(long eventLatencyMillis);
+    public void registerFailedEvent(long eventLatency, TimeUnit unit);
 
     /**
-     * An operation succeeded with the given eventLatencyMillis. Update
+     * An operation succeeded with the given eventLatency. Update
      * stats to reflect the same
-     * @param eventLatencyMillis The event latency in milliseconds.
+     * @param eventLatencyMillis The event latency
+     * @param unit
+     */
+    public void registerSuccessfulEvent(long eventLatency, TimeUnit unit);
+
+    /**
+     * An operation with the given value succeeded
+     * @param value
+     */
+    public void registerSuccessfulValue(long value);
+
+    /**
+     * An operation with the given value failed
      */
-    public void registerSuccessfulEvent(long eventLatencyMillis);
+    public void registerFailedValue(long value);
 
     /**
      * @return Returns an OpStatsData object with necessary values. We need this function


Mime
View raw message