incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject git commit: Fixing rate counter.
Date Tue, 13 Jan 2015 01:56:32 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/master 521632e8f -> e5c8a34cd


Fixing rate counter.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/e5c8a34c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/e5c8a34c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/e5c8a34c

Branch: refs/heads/master
Commit: e5c8a34cd87a132726c8edf2b9e3ab6834d99b5b
Parents: 521632e
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Mon Jan 12 20:54:57 2015 -0500
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Mon Jan 12 20:54:57 2015 -0500

----------------------------------------------------------------------
 .../java/org/apache/blur/mapreduce/lib/RateCounter.java  | 11 +++--------
 .../java/org/apache/blur/mapreduce/lib/RateCounter.java  | 11 +++--------
 2 files changed, 6 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/e5c8a34c/blur-mapred-hadoop1/src/main/java/org/apache/blur/mapreduce/lib/RateCounter.java
----------------------------------------------------------------------
diff --git a/blur-mapred-hadoop1/src/main/java/org/apache/blur/mapreduce/lib/RateCounter.java
b/blur-mapred-hadoop1/src/main/java/org/apache/blur/mapreduce/lib/RateCounter.java
index 694759e..777cb14 100644
--- a/blur-mapred-hadoop1/src/main/java/org/apache/blur/mapreduce/lib/RateCounter.java
+++ b/blur-mapred-hadoop1/src/main/java/org/apache/blur/mapreduce/lib/RateCounter.java
@@ -27,19 +27,13 @@ public class RateCounter {
 
   private final Counter _counter;
   private final long _reportTime;
-  private final long _rateTime;
   private long _lastReport;
   private long _count = 0;
 
   public RateCounter(Counter counter) {
-    this(counter, TimeUnit.SECONDS, 1);
-  }
-
-  public RateCounter(Counter counter, TimeUnit unit, long reportTime) {
     _counter = counter;
     _lastReport = System.nanoTime();
-    _reportTime = unit.toNanos(reportTime);
-    _rateTime = unit.toSeconds(reportTime);
+    _reportTime = TimeUnit.SECONDS.toNanos(5);
   }
 
   public void mark() {
@@ -49,7 +43,8 @@ public class RateCounter {
   public void mark(long n) {
     long now = System.nanoTime();
     if (_lastReport + _reportTime < now) {
-      long rate = _count / _rateTime;
+      long seconds = TimeUnit.NANOSECONDS.toSeconds(now - _lastReport);
+      long rate = _count / seconds;
       _counter.setValue(rate);
       _lastReport = System.nanoTime();
       _count = 0;

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/e5c8a34c/blur-mapred-hadoop2/src/main/java/org/apache/blur/mapreduce/lib/RateCounter.java
----------------------------------------------------------------------
diff --git a/blur-mapred-hadoop2/src/main/java/org/apache/blur/mapreduce/lib/RateCounter.java
b/blur-mapred-hadoop2/src/main/java/org/apache/blur/mapreduce/lib/RateCounter.java
index 694759e..777cb14 100644
--- a/blur-mapred-hadoop2/src/main/java/org/apache/blur/mapreduce/lib/RateCounter.java
+++ b/blur-mapred-hadoop2/src/main/java/org/apache/blur/mapreduce/lib/RateCounter.java
@@ -27,19 +27,13 @@ public class RateCounter {
 
   private final Counter _counter;
   private final long _reportTime;
-  private final long _rateTime;
   private long _lastReport;
   private long _count = 0;
 
   public RateCounter(Counter counter) {
-    this(counter, TimeUnit.SECONDS, 1);
-  }
-
-  public RateCounter(Counter counter, TimeUnit unit, long reportTime) {
     _counter = counter;
     _lastReport = System.nanoTime();
-    _reportTime = unit.toNanos(reportTime);
-    _rateTime = unit.toSeconds(reportTime);
+    _reportTime = TimeUnit.SECONDS.toNanos(5);
   }
 
   public void mark() {
@@ -49,7 +43,8 @@ public class RateCounter {
   public void mark(long n) {
     long now = System.nanoTime();
     if (_lastReport + _reportTime < now) {
-      long rate = _count / _rateTime;
+      long seconds = TimeUnit.NANOSECONDS.toSeconds(now - _lastReport);
+      long rate = _count / seconds;
       _counter.setValue(rate);
       _lastReport = System.nanoTime();
       _count = 0;


Mime
View raw message