You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/12/21 10:13:51 UTC

[2/2] camel git commit: CAMEL-8113: Added noop stats to type converter registry to capture attempts that didnt need a conversion. Then attempt is actual conversion attempts, so we have a more precise stats of the usage.

CAMEL-8113: Added noop stats to type converter registry to capture attempts that didnt need a conversion. Then attempt is actual conversion attempts, so we have a more precise stats of the usage.


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

Branch: refs/heads/master
Commit: fe80773ee03f604935a93e4122498d089d89af27
Parents: 3550cbb
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Dec 21 10:13:39 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Dec 21 10:13:39 2014 +0100

----------------------------------------------------------------------
 .../ManagedTypeConverterRegistryMBean.java      |  3 ++
 .../converter/BaseTypeConverterRegistry.java    | 51 +++++++++++++-------
 .../mbean/ManagedTypeConverterRegistry.java     |  4 ++
 .../apache/camel/spi/TypeConverterRegistry.java |  7 ++-
 ...peConverterRegistryStatsPerformanceTest.java |  3 ++
 .../commands/AbstractLocalCamelController.java  |  1 +
 .../camel/commands/ContextInfoCommand.java      |  3 +-
 7 files changed, 52 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/fe80773e/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTypeConverterRegistryMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTypeConverterRegistryMBean.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTypeConverterRegistryMBean.java
index 650b62c..d88e61e 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTypeConverterRegistryMBean.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTypeConverterRegistryMBean.java
@@ -23,6 +23,9 @@ import org.apache.camel.api.management.ManagedOperation;
 
 public interface ManagedTypeConverterRegistryMBean extends ManagedServiceMBean {
 
+    @ManagedAttribute(description = "Number of noop attempts (no type conversion was needed)")
+    long getNoopCounter();
+
     @ManagedAttribute(description = "Number of type conversion attempts")
     long getAttemptCounter();
 

http://git-wip-us.apache.org/repos/asf/camel/blob/fe80773e/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java b/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
index 8c46a9d..82a0982 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
@@ -65,6 +65,7 @@ public abstract class BaseTypeConverterRegistry extends ServiceSupport implement
     protected Injector injector;
     protected final FactoryFinder factoryFinder;
     protected final Statistics statistics = new UtilizationStatistics();
+    protected final AtomicLong noopCounter = new AtomicLong();
     protected final AtomicLong attemptCounter = new AtomicLong();
     protected final AtomicLong missCounter = new AtomicLong();
     protected final AtomicLong hitCounter = new AtomicLong();
@@ -108,9 +109,6 @@ public abstract class BaseTypeConverterRegistry extends ServiceSupport implement
 
         Object answer;
         try {
-            if (statistics.isStatisticsEnabled()) {
-                attemptCounter.incrementAndGet();
-            }
             answer = doConvertTo(type, exchange, value, false);
         } catch (Exception e) {
             if (statistics.isStatisticsEnabled()) {
@@ -159,9 +157,6 @@ public abstract class BaseTypeConverterRegistry extends ServiceSupport implement
 
         Object answer;
         try {
-            if (statistics.isStatisticsEnabled()) {
-                attemptCounter.incrementAndGet();
-            }
             answer = doConvertTo(type, exchange, value, false);
         } catch (Exception e) {
             if (statistics.isStatisticsEnabled()) {
@@ -202,9 +197,6 @@ public abstract class BaseTypeConverterRegistry extends ServiceSupport implement
 
         Object answer;
         try {
-            if (statistics.isStatisticsEnabled()) {
-                attemptCounter.incrementAndGet();
-            }
             answer = doConvertTo(type, exchange, value, true);
         } catch (Exception e) {
             if (statistics.isStatisticsEnabled()) {
@@ -238,23 +230,28 @@ public abstract class BaseTypeConverterRegistry extends ServiceSupport implement
             if (boolean.class.isAssignableFrom(type)) {
                 return Boolean.FALSE;
             }
+            // no type conversion was needed
+            if (statistics.isStatisticsEnabled()) {
+                noopCounter.incrementAndGet();
+            }
             return null;
         }
 
         // same instance type
         if (type.isInstance(value)) {
+            // no type conversion was needed
+            if (statistics.isStatisticsEnabled()) {
+                noopCounter.incrementAndGet();
+            }
             return type.cast(value);
         }
 
-        // check if we have tried it before and if its a miss
-        TypeMapping key = new TypeMapping(type, value.getClass());
-        if (misses.containsKey(key)) {
-            // we have tried before but we cannot convert this one
-            return Void.TYPE;
-        }
-        
         // special for NaN numbers, which we can only convert for floating numbers
         if (ObjectHelper.isNaN(value)) {
+            // no type conversion was needed
+            if (statistics.isStatisticsEnabled()) {
+                noopCounter.incrementAndGet();
+            }
             if (Float.class.isAssignableFrom(type)) {
                 return Float.NaN;
             } else if (Double.class.isAssignableFrom(type)) {
@@ -265,6 +262,18 @@ public abstract class BaseTypeConverterRegistry extends ServiceSupport implement
             }
         }
 
+        // okay we need to attempt to convert
+        if (statistics.isStatisticsEnabled()) {
+            attemptCounter.incrementAndGet();
+        }
+
+        // check if we have tried it before and if its a miss
+        TypeMapping key = new TypeMapping(type, value.getClass());
+        if (misses.containsKey(key)) {
+            // we have tried before but we cannot convert this one
+            return Void.TYPE;
+        }
+        
         // try to find a suitable type converter
         TypeConverter converter = getOrFindTypeConverter(key);
         if (converter != null) {
@@ -599,6 +608,11 @@ public abstract class BaseTypeConverterRegistry extends ServiceSupport implement
         private boolean statisticsEnabled;
 
         @Override
+        public long getNoopCounter() {
+            return noopCounter.get();
+        }
+
+        @Override
         public long getAttemptCounter() {
             return attemptCounter.get();
         }
@@ -620,6 +634,7 @@ public abstract class BaseTypeConverterRegistry extends ServiceSupport implement
 
         @Override
         public void reset() {
+            noopCounter.set(0);
             attemptCounter.set(0);
             hitCounter.set(0);
             missCounter.set(0);
@@ -638,8 +653,8 @@ public abstract class BaseTypeConverterRegistry extends ServiceSupport implement
 
         @Override
         public String toString() {
-            return String.format("TypeConverterRegistry utilization[attempts=%s, hits=%s, misses=%s, failures=%s]",
-                    getAttemptCounter(), getHitCounter(), getMissCounter(), getFailedCounter());
+            return String.format("TypeConverterRegistry utilization[noop=%s, attempts=%s, hits=%s, misses=%s, failures=%s]",
+                    getNoopCounter(), getAttemptCounter(), getHitCounter(), getMissCounter(), getFailedCounter());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/fe80773e/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTypeConverterRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTypeConverterRegistry.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTypeConverterRegistry.java
index 7a1e183..625206e 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTypeConverterRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTypeConverterRegistry.java
@@ -47,6 +47,10 @@ public class ManagedTypeConverterRegistry extends ManagedService implements Mana
         return registry;
     }
 
+    public long getNoopCounter() {
+        return registry.getStatistics().getNoopCounter();
+    }
+
     public long getAttemptCounter() {
         return registry.getStatistics().getAttemptCounter();
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/fe80773e/camel-core/src/main/java/org/apache/camel/spi/TypeConverterRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/TypeConverterRegistry.java b/camel-core/src/main/java/org/apache/camel/spi/TypeConverterRegistry.java
index d529bfd..ca381d5 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/TypeConverterRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/TypeConverterRegistry.java
@@ -37,7 +37,12 @@ public interface TypeConverterRegistry extends StaticService {
     interface Statistics {
 
         /**
-         * Number of attempts
+         * Number of noop attempts (no type conversion was needed)
+         */
+        long getNoopCounter();
+
+        /**
+         * Number of type conversion attempts
          */
         long getAttemptCounter();
 

http://git-wip-us.apache.org/repos/asf/camel/blob/fe80773e/camel-core/src/test/java/org/apache/camel/processor/TypeConverterRegistryStatsPerformanceTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/TypeConverterRegistryStatsPerformanceTest.java b/camel-core/src/test/java/org/apache/camel/processor/TypeConverterRegistryStatsPerformanceTest.java
index ab3d170..387b17b 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/TypeConverterRegistryStatsPerformanceTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/TypeConverterRegistryStatsPerformanceTest.java
@@ -35,6 +35,7 @@ public class TypeConverterRegistryStatsPerformanceTest extends ContextTestSuppor
     }
 
     public void testTransform() throws Exception {
+        long noop = context.getTypeConverterRegistry().getStatistics().getNoopCounter();
         long attempt = context.getTypeConverterRegistry().getStatistics().getAttemptCounter();
         long failed = context.getTypeConverterRegistry().getStatistics().getFailedCounter();
         long hit = context.getTypeConverterRegistry().getStatistics().getHitCounter();
@@ -48,11 +49,13 @@ public class TypeConverterRegistryStatsPerformanceTest extends ContextTestSuppor
 
         assertMockEndpointsSatisfied();
 
+        long noop2 = context.getTypeConverterRegistry().getStatistics().getNoopCounter();
         long attempt2 = context.getTypeConverterRegistry().getStatistics().getAttemptCounter();
         long failed2 = context.getTypeConverterRegistry().getStatistics().getFailedCounter();
         long hit2 = context.getTypeConverterRegistry().getStatistics().getHitCounter();
         long miss2 = context.getTypeConverterRegistry().getStatistics().getMissCounter();
 
+        log.info("Noop: before={}, after={}, delta={}", new Object[]{noop, noop2, noop2 - noop});
         log.info("Attempt: before={}, after={}, delta={}", new Object[]{attempt, attempt2, attempt2 - attempt});
         log.info("Failed: before={}, after={}, delta={}", new Object[]{failed, failed2, failed2 - failed});
         log.info("Hit: before={}, after={}, delta={}", new Object[]{hit, hit2, hit2 - hit});

http://git-wip-us.apache.org/repos/asf/camel/blob/fe80773e/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractLocalCamelController.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractLocalCamelController.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractLocalCamelController.java
index 8a547a2..53c3a5f 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractLocalCamelController.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractLocalCamelController.java
@@ -96,6 +96,7 @@ public abstract class AbstractLocalCamelController extends AbstractCamelControll
             // add type converter details
             answer.put("typeConverter.numberOfTypeConverters", context.getTypeConverterRegistry().size());
             answer.put("typeConverter.statisticsEnabled", context.getTypeConverterRegistry().getStatistics().isStatisticsEnabled());
+            answer.put("typeConverter.noopCounter", context.getTypeConverterRegistry().getStatistics().getNoopCounter());
             answer.put("typeConverter.attemptCounter", context.getTypeConverterRegistry().getStatistics().getAttemptCounter());
             answer.put("typeConverter.hitCounter", context.getTypeConverterRegistry().getStatistics().getHitCounter());
             answer.put("typeConverter.missCounter", context.getTypeConverterRegistry().getStatistics().getMissCounter());

http://git-wip-us.apache.org/repos/asf/camel/blob/fe80773e/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextInfoCommand.java
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextInfoCommand.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextInfoCommand.java
index 6b12e18..cd2f373 100644
--- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextInfoCommand.java
+++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/ContextInfoCommand.java
@@ -104,11 +104,12 @@ public class ContextInfoCommand extends AbstractCamelCommand {
                 enabled = (boolean) row.get("typeConverter.statisticsEnabled");
             }
             if (enabled) {
+                long noop = (long) row.get("typeConverter.noopCounter");
                 long attempt = (long) row.get("typeConverter.attemptCounter");
                 long hit = (long) row.get("typeConverter.hitCounter");
                 long miss = (long) row.get("typeConverter.missCounter");
                 long failed = (long) row.get("typeConverter.failedCounter");
-                out.println(stringEscape.unescapeJava(String.format("\tType converter usage: [attempts=%s, hits=%s, misses=%s, failures=%s]", attempt, hit, miss, failed)));
+                out.println(stringEscape.unescapeJava(String.format("\tType converter usage: [noop=%s, attempts=%s, hits=%s, misses=%s, failures=%s]", noop, attempt, hit, miss, failed)));
             }
 
             // add stream caching details if enabled