camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/8] camel git commit: CAMEL-11353: Optimise - JMX Statistic split into specialized classes
Date Sun, 28 May 2017 19:54:11 GMT
CAMEL-11353: Optimise - JMX Statistic split into specialized classes


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8bf8cd1c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8bf8cd1c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8bf8cd1c

Branch: refs/heads/master
Commit: 8bf8cd1c4b059b63101616adee2fbc2407181e57
Parents: 3081eda
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun May 28 18:37:51 2017 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun May 28 19:01:18 2017 +0200

----------------------------------------------------------------------
 .../mbean/ManagedPerformanceCounter.java         | 11 +++++++----
 .../apache/camel/management/mbean/Statistic.java | 12 ++++++++----
 .../camel/management/mbean/StatisticCounter.java |  5 +++--
 .../camel/management/mbean/StatisticDelta.java   |  6 ++++++
 .../camel/management/mbean/StatisticMaximum.java | 19 ++++++++++++-------
 .../camel/management/mbean/StatisticMinimum.java | 19 ++++++++++++-------
 .../camel/management/mbean/StatisticValue.java   |  4 ++--
 7 files changed, 50 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8bf8cd1c/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java
index 2ac6214..d12e6eb 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java
@@ -217,7 +217,7 @@ public abstract class ManagedPerformanceCounter extends ManagedCounter
implement
         deltaProcessingTime.updateValue(time);
 
         long now = new Date().getTime();
-        if (firstExchangeCompletedTimestamp.getUpdateCount() == 0) {
+        if (!firstExchangeCompletedTimestamp.isUpdated()) {
             firstExchangeCompletedTimestamp.updateValue(now);
         }
 
@@ -228,8 +228,11 @@ public abstract class ManagedPerformanceCounter extends ManagedCounter
implement
         lastExchangeCompletedExchangeId = exchange.getExchangeId();
 
         // update mean
-        long count = exchangesCompleted.getUpdateCount();
-        long mean = count > 0 ? totalProcessingTime.getValue() / exchangesCompleted.getValue()
: 0;
+        long mean = 0;
+        long completed = exchangesCompleted.getValue();
+        if (completed > 0) {
+            mean = totalProcessingTime.getValue() / completed;
+        }
         meanProcessingTime.updateValue(mean);
     }
 
@@ -247,7 +250,7 @@ public abstract class ManagedPerformanceCounter extends ManagedCounter
implement
         }
 
         long now = new Date().getTime();
-        if (firstExchangeFailureTimestamp.getUpdateCount() == 0) {
+        if (!firstExchangeFailureTimestamp.isUpdated()) {
             firstExchangeFailureTimestamp.updateValue(now);
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/8bf8cd1c/camel-core/src/main/java/org/apache/camel/management/mbean/Statistic.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/Statistic.java b/camel-core/src/main/java/org/apache/camel/management/mbean/Statistic.java
index 63dc8a5..ba91312 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/Statistic.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/Statistic.java
@@ -33,6 +33,9 @@ package org.apache.camel.management.mbean;
  * <li>MINIMUM - A statistic with this update mode is a value that represents the minimum
value
  * amongst the update values applied to this statistic.</li>
  * <ul>
+ * The MAXIMUM and MINIMUM modes are not 100% thread-safe as there can be a lost-update problem.
+ * This is on purpose because the performance overhead to ensure atomic updates costs to
much
+ * on CPU and memory footprint. The other modes are thread-safe.
  */
 public abstract class Statistic {
 
@@ -48,10 +51,11 @@ public abstract class Statistic {
 
     public abstract long getValue();
 
-    @Deprecated
-    public long getUpdateCount() {
-        return 0;
-    }
+    /**
+     * Whether the statistic has been updated one or more times.
+     * Notice this is only working for value, maximum and minimum modes.
+     */
+    public abstract boolean isUpdated();
 
     public abstract void reset();
 

http://git-wip-us.apache.org/repos/asf/camel/blob/8bf8cd1c/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticCounter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticCounter.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticCounter.java
index d947e6b..814aa51 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticCounter.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticCounter.java
@@ -40,7 +40,8 @@ public class StatisticCounter extends Statistic {
     }
 
     @Override
-    public long getUpdateCount() {
-        return value.get();
+    public boolean isUpdated() {
+        // this is okay
+        return true;
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/8bf8cd1c/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticDelta.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticDelta.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticDelta.java
index b288972..6038106 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticDelta.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticDelta.java
@@ -37,6 +37,12 @@ public class StatisticDelta extends Statistic {
         return "" + value.get();
     }
 
+    @Override
+    public boolean isUpdated() {
+        // this is okay
+        return true;
+    }
+
     public void reset() {
         value.set(0);
         lastValue.set(0);

http://git-wip-us.apache.org/repos/asf/camel/blob/8bf8cd1c/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMaximum.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMaximum.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMaximum.java
index d403370..6649b9a 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMaximum.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMaximum.java
@@ -23,13 +23,13 @@ public class StatisticMaximum extends Statistic {
     private final AtomicLong value = new AtomicLong(-1);
 
     public void updateValue(long newValue) {
-        value.updateAndGet(value -> {
-            if (value == -1 || value < newValue) {
-                return newValue;
-            } else {
-                return value;
-            }
-        });
+        // its okay its not 100% thread safe (these jmx counters are not guaranteed to be
accurate for min/max values)
+        // if we use the atomic operation updateAndGet then the JVM creates a new lambda
per call which creates a new object
+        // in the JVM and causes higher memory footprint
+        long current = value.get();
+        if (current == -1 || current < newValue) {
+            value.set(newValue);
+        }
     }
 
     public long getValue() {
@@ -38,6 +38,11 @@ public class StatisticMaximum extends Statistic {
     }
 
     @Override
+    public boolean isUpdated() {
+        return value.get() != -1;
+    }
+
+    @Override
     public String toString() {
         return "" + value.get();
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/8bf8cd1c/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMinimum.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMinimum.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMinimum.java
index 55b5a54..0beccbc 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMinimum.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMinimum.java
@@ -23,13 +23,13 @@ public class StatisticMinimum extends Statistic {
     private final AtomicLong value = new AtomicLong(-1);
 
     public void updateValue(long newValue) {
-        value.updateAndGet(value -> {
-            if (value == -1 || value > newValue) {
-                return newValue;
-            } else {
-                return value;
-            }
-        });
+        // its okay its not 100% thread safe (these jmx counters are not guaranteed to be
accurate for min/max values)
+        // if we use the atomic operation updateAndGet then the JVM creates a new lambda
per call which creates a new object
+        // in the JVM and causes higher memory footprint
+        long current = value.get();
+        if (current == -1 || current > newValue) {
+            value.set(newValue);
+        }
     }
 
     public long getValue() {
@@ -38,6 +38,11 @@ public class StatisticMinimum extends Statistic {
     }
 
     @Override
+    public boolean isUpdated() {
+        return value.get() != -1;
+    }
+
+    @Override
     public String toString() {
         return "" + value.get();
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/8bf8cd1c/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticValue.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticValue.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticValue.java
index 6391799..9cb7b48 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticValue.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticValue.java
@@ -36,8 +36,8 @@ public class StatisticValue extends Statistic {
     }
 
     @Override
-    public long getUpdateCount() {
-        return value.get() == -1 ? 0 : 1;
+    public boolean isUpdated() {
+        return value.get() != -1;
     }
 
     public void reset() {


Mime
View raw message