ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [2/2] incubator-ignite git commit: IGNITE-49 Added time statistics for async operations.
Date Tue, 20 Jan 2015 15:24:18 GMT
IGNITE-49 Added time statistics for async operations.


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

Branch: refs/heads/ignite-49
Commit: 31c2251bc4c7537dc302b3c2e79e0601a641450a
Parents: 3ed9f04
Author: nikolay_tikhonov <ntikhonov@gridgain.com>
Authored: Tue Jan 20 18:23:51 2015 +0300
Committer: nikolay_tikhonov <ntikhonov@gridgain.com>
Committed: Tue Jan 20 18:23:51 2015 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheAdapter.java      | 300 ++++++++++++++++++-
 .../cache/GridCacheMetricsAdapter.java          |  15 +
 .../dht/atomic/GridDhtAtomicCache.java          |  22 ++
 .../local/atomic/GridLocalAtomicCache.java      |  42 ++-
 .../cache/GridCacheAbstractMetricsSelfTest.java | 223 +++++++++++++-
 5 files changed, 575 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/31c2251b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheAdapter.java
b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheAdapter.java
index 5534f3f..03c4111 100644
--- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheAdapter.java
@@ -1684,15 +1684,35 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
 
     /** {@inheritDoc} */
     @Override public IgniteFuture<V> getAsync(final K key) {
+        final boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+        final long start = statsEnabled ? System.nanoTime() : 0L;
+
         IgniteFuture<V> fut = getAsync(key, true, null);
 
         if (ctx.config().getInterceptor() != null)
-            return fut.chain(new CX1<IgniteFuture<V>, V>() {
+            fut =  fut.chain(new CX1<IgniteFuture<V>, V>() {
                 @Override public V applyx(IgniteFuture<V> f) throws IgniteCheckedException
{
                     return (V)ctx.config().getInterceptor().onGet(key, f.get());
                 }
             });
 
+        if (statsEnabled)
+            fut.listenAsync(new CI1<IgniteFuture<V>>() {
+                @Override public void apply(IgniteFuture<V> fut) {
+                    try {
+                        if (!fut.isCancelled()) {
+                            fut.get();
+
+                            ctx.cache().metrics0().addGetTimeNanos(System.nanoTime() - start);
+                        }
+                    }
+                    catch (IgniteCheckedException ignore){
+                        //No-op.
+                    }
+                }
+            });
+
         return fut;
     }
 
@@ -1715,6 +1735,10 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
 
     /** {@inheritDoc} */
     @Override public IgniteFuture<Map<K, V>> getAllAsync(@Nullable final Collection<?
extends K> keys) {
+        final boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+        final long start = statsEnabled ? System.nanoTime() : 0L;
+
         IgniteFuture<Map<K, V>> fut = getAllAsync(keys, true, null);
 
         if (ctx.config().getInterceptor() != null)
@@ -1724,6 +1748,21 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
                 }
             });
 
+        if (statsEnabled)
+            fut.listenAsync(new CI1<IgniteFuture<Map<K, V>>>() {
+                @Override public void apply(IgniteFuture<Map<K, V>> fut) {
+                    try {
+                        if (!fut.isCancelled()) {
+                            fut.get();
+
+                            ctx.cache().metrics0().addGetTimeNanos(System.nanoTime() - start);
+                        }
+                    } catch (IgniteCheckedException ignore) {
+                        //No-op.
+                    }
+                }
+            });
+
         return fut;
     }
 
@@ -2147,7 +2186,28 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
     /** {@inheritDoc} */
     @Override public IgniteFuture<V> putAsync(K key, V val,
         @Nullable IgnitePredicate<GridCacheEntry<K, V>>[] filter) {
-        return putAsync(key, val, null, -1, filter);
+        final boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+        final long start = statsEnabled ? System.nanoTime() : 0L;
+
+        IgniteFuture<V> fut = putAsync(key, val, null, -1, filter);
+
+        if (statsEnabled)
+            fut.listenAsync(new CI1<IgniteFuture<V>>() {
+                @Override public void apply(IgniteFuture<V> fut) {
+                    try {
+                        if (!fut.isCancelled()) {
+                            fut.get();
+
+                            ctx.cache().metrics0().addPutAndGetTimeNanos(System.nanoTime()
- start);
+                        }
+                    } catch (IgniteCheckedException ignore) {
+                        //No-op.
+                    }
+                }
+            });
+
+        return fut;
     }
 
     /** {@inheritDoc} */
@@ -2463,7 +2523,29 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
     /** {@inheritDoc} */
     @Override public IgniteFuture<Boolean> putxAsync(K key, V val,
         @Nullable IgnitePredicate<GridCacheEntry<K, V>>... filter) {
-        return putxAsync(key, val, null, -1, filter);
+        final boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+        final long start = statsEnabled ? System.nanoTime() : 0L;
+
+        IgniteFuture<Boolean> fut = putxAsync(key, val, null, -1, filter);
+
+        if (statsEnabled)
+            fut.listenAsync(new CI1<IgniteFuture<Boolean>>() {
+                @Override public void apply(IgniteFuture<Boolean> fut) {
+                    try {
+                        if (!fut.isCancelled()) {
+                            fut.get();
+
+                            ctx.cache().metrics0().addPutTimeNanos(System.nanoTime() - start);
+                        }
+                    }
+                    catch (IgniteCheckedException ignore) {
+                        //No-op.
+                    }
+                }
+            });
+
+        return fut;
     }
 
     /** {@inheritDoc} */
@@ -2515,6 +2597,10 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
 
     /** {@inheritDoc} */
     @Override public IgniteFuture<V> putIfAbsentAsync(final K key, final V val) {
+        final boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+        final long start = statsEnabled ? System.nanoTime() : 0L;
+
         A.notNull(key, "key", val, "val");
 
         if (keyCheck)
@@ -2524,7 +2610,7 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
 
         ctx.denyOnLocalRead();
 
-        return ctx.wrapClone(asyncOp(new AsyncOp<V>(key) {
+        IgniteFuture<V> fut = ctx.wrapClone(asyncOp(new AsyncOp<V>(key) {
             @Override public IgniteFuture<V> op(IgniteTxLocalAdapter<K, V> tx)
{
                 return tx.putAllAsync(ctx, F.t(key, val), true, null, -1, ctx.noPeekArray())
                     .chain((IgniteClosure<IgniteFuture<GridCacheReturn<V>>,
V>)RET2VAL);
@@ -2534,6 +2620,24 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
                 return "putIfAbsentAsync [key=" + key + ", val=" + val + ']';
             }
         }));
+
+        if(statsEnabled)
+            fut.listenAsync(new CI1<IgniteFuture<V>>() {
+                @Override public void apply(IgniteFuture<V> fut) {
+                    try {
+                        if (!fut.isCancelled()) {
+                            fut.get();
+
+                            ctx.cache().metrics0().addPutTimeNanos(System.nanoTime() - start);
+                        }
+                    }
+                    catch (IgniteCheckedException ignore) {
+                        //No-op.
+                    }
+                }
+            });
+
+        return fut;
     }
 
     /** {@inheritDoc} */
@@ -2571,6 +2675,10 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
 
     /** {@inheritDoc} */
     @Override public IgniteFuture<Boolean> putxIfAbsentAsync(final K key, final V val)
{
+        final boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+        final long start = statsEnabled ? System.nanoTime() : 0L;
+
         A.notNull(key, "key", val, "val");
 
         if (keyCheck)
@@ -2580,7 +2688,7 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
 
         ctx.denyOnLocalRead();
 
-        return asyncOp(new AsyncOp<Boolean>(key) {
+        IgniteFuture<Boolean> fut = asyncOp(new AsyncOp<Boolean>(key) {
             @Override public IgniteFuture<Boolean> op(IgniteTxLocalAdapter<K, V>
tx) {
                 return tx.putAllAsync(ctx, F.t(key, val), false, null, -1, ctx.noPeekArray()).chain(
                     (IgniteClosure<IgniteFuture<GridCacheReturn<V>>, Boolean>)RET2FLAG);
@@ -2590,6 +2698,23 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
                 return "putxIfAbsentAsync [key=" + key + ", val=" + val + ']';
             }
         });
+
+        if (statsEnabled)
+            fut.listenAsync(new CI1<IgniteFuture<Boolean>>() {
+                @Override public void apply(IgniteFuture<Boolean> fut) {
+                    try {
+                        if (!fut.isCancelled()) {
+                            fut.get();
+
+                            ctx.cache().metrics0().addPutTimeNanos(System.nanoTime() - start);
+                        }
+                    } catch (IgniteCheckedException ignore) {
+                        //No-op.
+                    }
+                }
+            });
+
+        return fut;
     }
 
     /** {@inheritDoc} */
@@ -2617,6 +2742,10 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
 
     /** {@inheritDoc} */
     @Override public IgniteFuture<V> replaceAsync(final K key, final V val) {
+        final boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+        final long start = statsEnabled ? System.nanoTime() : 0L;
+
         A.notNull(key, "key", val, "val");
 
         if (keyCheck)
@@ -2626,7 +2755,7 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
 
         ctx.denyOnLocalRead();
 
-        return ctx.wrapClone(asyncOp(new AsyncOp<V>(key) {
+        IgniteFuture<V> fut = ctx.wrapClone(asyncOp(new AsyncOp<V>(key) {
             @Override public IgniteFuture<V> op(IgniteTxLocalAdapter<K, V> tx)
{
                 return tx.putAllAsync(ctx, F.t(key, val), true, null, -1, ctx.hasPeekArray()).chain(
                     (IgniteClosure<IgniteFuture<GridCacheReturn<V>>, V>)RET2VAL);
@@ -2636,6 +2765,24 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
                 return "replaceAsync [key=" + key + ", val=" + val + ']';
             }
         }));
+
+        if (statsEnabled)
+            fut.listenAsync(new CI1<IgniteFuture<V>>() {
+                @Override public void apply(IgniteFuture<V> fut) {
+                    try {
+                        if (!fut.isCancelled()) {
+                            fut.get();
+
+                            ctx.cache().metrics0().addPutAndGetTimeNanos(System.nanoTime()
- start);
+                        }
+                    }
+                    catch (IgniteCheckedException ignore) {
+                        //No-op.
+                    }
+                }
+            });
+
+        return fut;
     }
 
     /** {@inheritDoc} */
@@ -2714,6 +2861,10 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
 
     /** {@inheritDoc} */
     @Override public IgniteFuture<Boolean> replaceAsync(final K key, final V oldVal,
final V newVal) {
+        final boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+        final long start = statsEnabled ? System.nanoTime() : 0L;
+
         A.notNull(key, "key", oldVal, "oldVal", newVal, "newVal");
 
         if (keyCheck)
@@ -2725,7 +2876,7 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
 
         ctx.denyOnLocalRead();
 
-        return asyncOp(new AsyncOp<Boolean>(key) {
+        IgniteFuture<Boolean> fut = asyncOp(new AsyncOp<Boolean>(key) {
             @Override public IgniteFuture<Boolean> op(IgniteTxLocalAdapter<K, V>
tx) {
                 // Register before hiding in the filter.
                 if (ctx.deploymentEnabled()) {
@@ -2745,6 +2896,24 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
                 return "replaceAsync [key=" + key + ", oldVal=" + oldVal + ", newVal=" +
newVal + ']';
             }
         });
+
+        if (statsEnabled)
+            fut.listenAsync(new CI1<IgniteFuture<Boolean>>() {
+                @Override public void apply(IgniteFuture<Boolean> fut) {
+                    try {
+                        if (!fut.isCancelled()) {
+                            fut.get();
+
+                            ctx.cache().metrics0().addPutAndGetTimeNanos(System.nanoTime()
- start);
+                        }
+                    }
+                    catch (IgniteCheckedException ignore) {
+                        //No-op.
+                    }
+                }
+            });
+
+        return fut;
     }
 
     /** {@inheritDoc} */
@@ -2845,13 +3014,27 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
 
     /** {@inheritDoc} */
     @Override public IgniteFuture<V> removeAsync(K key, IgnitePredicate<GridCacheEntry<K,
V>>... filter) {
+        final boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+        final long start = statsEnabled ? System.nanoTime() : 0L;
+
         IgniteFuture<V> fut = removeAsync(key, null, filter);
 
-        if (ctx.cache().configuration().isStatisticsEnabled())
+        if (statsEnabled)
             fut.listenAsync(new CI1<IgniteFuture<V>>() {
                 /** {@inheritDoc} */
                 @Override public void apply(IgniteFuture<V> fut) {
-                    ctx.cache().metrics0().addRemoveTimeNanos(fut.duration());
+                    try {
+                        if (!fut.isCancelled()) {
+                            fut.get();
+
+                            ctx.cache().metrics0().addRemoveTimeNanos(System.nanoTime() -
start);
+                        }
+                    }
+                    catch (IgniteCheckedException ignore) {
+                        //No-op.
+                    }
+
                 }
             });
 
@@ -2861,6 +3044,10 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
     /** {@inheritDoc} */
     @Override public IgniteFuture<V> removeAsync(final K key, @Nullable final GridCacheEntryEx<K,
V> entry,
         @Nullable final IgnitePredicate<GridCacheEntry<K, V>>... filter) {
+        final boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+        final long start = statsEnabled ? System.nanoTime() : 0L;
+
         ctx.denyOnLocalRead();
 
         A.notNull(key, "key");
@@ -2868,7 +3055,7 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
         if (keyCheck)
             validateCacheKey(key);
 
-        return ctx.wrapClone(asyncOp(new AsyncOp<V>(key) {
+        IgniteFuture<V> fut = ctx.wrapClone(asyncOp(new AsyncOp<V>(key) {
             @Override public IgniteFuture<V> op(IgniteTxLocalAdapter<K, V> tx)
{
                 // TODO should we invoke interceptor here?
                 return tx.removeAllAsync(ctx, Collections.singletonList(key), null, true,
filter)
@@ -2879,6 +3066,26 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
                 return "removeAsync [key=" + key + ", filter=" + Arrays.toString(filter)
+ ']';
             }
         }));
+
+        if (statsEnabled)
+            fut.listenAsync(new CI1<IgniteFuture<V>>() {
+                /** {@inheritDoc} */
+                @Override public void apply(IgniteFuture<V> fut) {
+                    try {
+                        if (!fut.isCancelled()) {
+                            fut.get();
+
+                            ctx.cache().metrics0().addRemoveTimeNanos(System.nanoTime() -
start);
+                        }
+                    }
+                    catch (IgniteCheckedException ignore) {
+                        //No-op.
+                    }
+
+                }
+            });
+
+        return fut;
     }
 
     /** {@inheritDoc} */
@@ -2924,6 +3131,10 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
     /** {@inheritDoc} */
     @Override public IgniteFuture<?> removeAllAsync(@Nullable final Collection<?
extends K> keys,
         final IgnitePredicate<GridCacheEntry<K, V>>... filter) {
+        final boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+        final long start = statsEnabled ? System.nanoTime() : 0L;
+
         if (F.isEmpty(keys))
             return new GridFinishedFuture<Object>(ctx.kernalContext());
 
@@ -2932,7 +3143,7 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
 
         ctx.denyOnLocalRead();
 
-        return asyncOp(new AsyncInOp(keys) {
+        IgniteFuture<Object> fut = asyncOp(new AsyncInOp(keys) {
             @Override public IgniteFuture<?> inOp(IgniteTxLocalAdapter<K, V>
tx) {
                 return tx.removeAllAsync(ctx, keys, null, false, filter);
             }
@@ -2941,6 +3152,25 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
                 return "removeAllAsync [keys=" + keys + ", filter=" + Arrays.toString(filter)
+ ']';
             }
         });
+
+        if (statsEnabled)
+            fut.listenAsync(new CI1<IgniteFuture<Object>>() {
+                /** {@inheritDoc} */
+                @Override
+                public void apply(IgniteFuture<Object> fut) {
+                    try {
+                        if (!fut.isCancelled()) {
+                            fut.get();
+
+                            ctx.cache().metrics0().addRemoveTimeNanos(System.nanoTime() -
start);
+                        }
+                    } catch (IgniteCheckedException ignore) {
+                        //No-op.
+                    }
+                }
+            });
+
+        return fut;
     }
 
     /** {@inheritDoc} */
@@ -2998,6 +3228,10 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
     /** {@inheritDoc} */
     @Override public IgniteFuture<Boolean> removexAsync(final K key, @Nullable final
GridCacheEntryEx<K, V> entry,
         @Nullable final IgnitePredicate<GridCacheEntry<K, V>>... filter) {
+        final boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+        final long start = statsEnabled ? System.nanoTime() : 0L;
+
         ctx.denyOnLocalRead();
 
         A.notNull(key, "key");
@@ -3005,7 +3239,7 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
         if (keyCheck)
             validateCacheKey(key);
 
-        return asyncOp(new AsyncOp<Boolean>(key) {
+        IgniteFuture<Boolean> fut = asyncOp(new AsyncOp<Boolean>(key) {
             @Override public IgniteFuture<Boolean> op(IgniteTxLocalAdapter<K, V>
tx) {
                 return tx.removeAllAsync(ctx, Collections.singletonList(key), entry, false,
filter).chain(
                     (IgniteClosure<IgniteFuture<GridCacheReturn<V>>, Boolean>)RET2FLAG);
@@ -3015,6 +3249,23 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
                 return "removeAsync [key=" + key + ", filter=" + Arrays.toString(filter)
+ ']';
             }
         });
+
+        if (statsEnabled)
+            fut.listenAsync(new CI1<IgniteFuture<Boolean>>() {
+                @Override public void apply(IgniteFuture<Boolean> fut) {
+                    try {
+                        if (!fut.isCancelled()) {
+                            fut.get();
+
+                            ctx.cache().metrics0().addRemoveTimeNanos(System.nanoTime() -
start);
+                        }
+                    } catch (IgniteCheckedException ignore) {
+                        //No-op.
+                    }
+                }
+            });
+
+        return fut;
     }
 
     /** {@inheritDoc} */
@@ -3209,6 +3460,10 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
 
     /** {@inheritDoc} */
     @Override public IgniteFuture<Boolean> removeAsync(final K key, final V val) {
+        final boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+        final long start = statsEnabled ? System.nanoTime() : 0L;
+
         ctx.denyOnLocalRead();
 
         A.notNull(key, "key", val, "val");
@@ -3218,7 +3473,7 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
 
         validateCacheValue(val);
 
-        return asyncOp(new AsyncOp<Boolean>(key) {
+        IgniteFuture<Boolean> fut = asyncOp(new AsyncOp<Boolean>(key) {
             @Override public IgniteFuture<Boolean> op(IgniteTxLocalAdapter<K, V>
tx) {
                 // Register before hiding in the filter.
                 if (ctx.deploymentEnabled()) {
@@ -3250,6 +3505,25 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
                 return "removeAsync [key=" + key + ", val=" + val + ']';
             }
         });
+
+        if (statsEnabled)
+            fut.listenAsync(new CI1<IgniteFuture<Boolean>>() {
+                /** {@inheritDoc} */
+                @Override public void apply(IgniteFuture<Boolean> fut) {
+                    try {
+                        if (!fut.isCancelled()) {
+                            fut.get();
+
+                            ctx.cache().metrics0().addRemoveTimeNanos(System.nanoTime() -
start);
+                        }
+                    }
+                    catch (IgniteCheckedException ignore) {
+                        //No-op.
+                    }
+                }
+            });
+
+        return fut;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/31c2251b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheMetricsAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheMetricsAdapter.java
b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheMetricsAdapter.java
index 2c22aee..793b1c3 100644
--- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheMetricsAdapter.java
+++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheMetricsAdapter.java
@@ -249,6 +249,9 @@ public class GridCacheMetricsAdapter implements GridCacheMetrics, Externalizable
      */
     public void addGetTimeNanos(long duration) {
         getTimeNanos += duration;
+
+        if (delegate != null)
+            delegate.addGetTimeNanos(duration);
     }
 
     /**
@@ -258,6 +261,9 @@ public class GridCacheMetricsAdapter implements GridCacheMetrics, Externalizable
      */
     public void addPutTimeNanos(long duration) {
         putTimeNanos += duration;
+
+        if (delegate != null)
+            delegate.addPutTimeNanos(duration);
     }
 
     /**
@@ -267,6 +273,9 @@ public class GridCacheMetricsAdapter implements GridCacheMetrics, Externalizable
      */
     public void addRemoveTimeNanos(long duration) {
         removeTimeNanos += duration;
+
+        if (delegate != null)
+            delegate.addRemoveTimeNanos(duration);
     }
 
     /**
@@ -277,6 +286,9 @@ public class GridCacheMetricsAdapter implements GridCacheMetrics, Externalizable
     public void addRemoveAndGetTimeNanos(long duration) {
         removeTimeNanos += duration;
         getTimeNanos += duration;
+
+        if (delegate != null)
+            delegate.addRemoveAndGetTimeNanos(duration);
     }
 
     /**
@@ -287,6 +299,9 @@ public class GridCacheMetricsAdapter implements GridCacheMetrics, Externalizable
     public void addPutAndGetTimeNanos(long duration) {
         putTimeNanos += duration;
         getTimeNanos += duration;
+
+        if (delegate != null)
+            delegate.addPutAndGetTimeNanos(duration);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/31c2251b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
index d27323b..87e43ca 100644
--- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
+++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
@@ -790,6 +790,10 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K,
V> {
         boolean rawRetval,
         @Nullable final IgnitePredicate<GridCacheEntry<K, V>>[] filter
     ) {
+        final boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+        final long start = statsEnabled ? System.nanoTime() : 0L;
+
         assert keys != null || drMap != null;
 
         if (keyCheck)
@@ -821,6 +825,24 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K,
V> {
             subjId,
             taskNameHash);
 
+        if (statsEnabled) {
+            updateFut.listenAsync(new CI1<IgniteFuture<Object>>() {
+                /** {@inheritDoc} */
+                @Override public void apply(IgniteFuture<Object> fut) {
+                    try {
+                        if (!fut.isCancelled()) {
+                            fut.get();
+
+                            ctx.cache().metrics0().addRemoveTimeNanos(System.nanoTime() -
start);
+                        }
+                    }
+                    catch (IgniteCheckedException ignore){
+                        //No-op.
+                    }
+                }
+            });
+        }
+
         return asyncOp(new CO<IgniteFuture<Object>>() {
             @Override public IgniteFuture<Object> apply() {
                 updateFut.map();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/31c2251b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/local/atomic/GridLocalAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/local/atomic/GridLocalAtomicCache.java
b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/local/atomic/GridLocalAtomicCache.java
index 7f495ce..9a10e89 100644
--- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/local/atomic/GridLocalAtomicCache.java
+++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/local/atomic/GridLocalAtomicCache.java
@@ -817,23 +817,47 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K,
V> {
         final boolean rawRetval,
         @Nullable final IgnitePredicate<GridCacheEntry<K, V>>[] filter
     ) {
+        final boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+        final long start = statsEnabled ? System.nanoTime() : 0L;
+
         final boolean storeEnabled = ctx.isStoreEnabled();
 
         final ExpiryPolicy expiryPlc = expiryPerCall();
 
-        return asyncOp(new Callable<Object>() {
+        IgniteFuture fut = asyncOp(new Callable<Object>() {
             @Override public Object call() throws Exception {
                 return updateAllInternal(DELETE,
-                    keys,
-                    null,
-                    null,
-                    expiryPlc,
-                    retval,
-                    rawRetval,
-                    filter,
-                    storeEnabled);
+                        keys,
+                        null,
+                        null,
+                        expiryPlc,
+                        retval,
+                        rawRetval,
+                        filter,
+                        storeEnabled);
             }
         });
+
+        if (statsEnabled) {
+            fut.listenAsync(new CI1<IgniteFuture<Boolean>>() {
+                /** {@inheritDoc} */
+                @Override public void apply(IgniteFuture<Boolean> fut) {
+                    try {
+                        if (!fut.isCancelled()) {
+                            fut.get();
+
+                            ctx.cache().metrics0().addRemoveTimeNanos(System.nanoTime() -
start);
+                        }
+                    }
+                    catch (IgniteCheckedException ignore) {
+                        //No-op.
+                    }
+                }
+            });
+        }
+
+        return fut;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/31c2251b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractMetricsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractMetricsSelfTest.java
b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractMetricsSelfTest.java
index 5c57338..6041915 100644
--- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractMetricsSelfTest.java
+++ b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractMetricsSelfTest.java
@@ -104,8 +104,8 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
     public void testRemoveAsyncAvgTime() throws Exception {
         GridCache<Object, Object> cache = grid(0).cache(null);
 
-        cache.put(1, 1);
-        cache.put(2, 2);
+        cache.putx(1, 1);
+        cache.putx(2, 2);
 
         assertEquals(cache.metrics().getAverageRemoveTime(), 0.0, 0.0);
 
@@ -125,6 +125,33 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
     /**
      * @throws Exception If failed.
      */
+    public void testRemoveAsyncValAvgTime() throws Exception {
+        GridCache<Object, Object> cache = grid(0).cache(null);
+
+        Integer key = 0;
+
+        for (int i = 0; i < 1000; i++) {
+            if (cache.affinity().isPrimary(grid(0).localNode(), i)) {
+                key = i;
+
+                break;
+            }
+        }
+
+        assertEquals(cache.metrics().getAverageRemoveTime(), 0.0, 0.0);
+
+        cache.put(key, key);
+
+        IgniteFuture<Boolean> fut = cache.removeAsync(key, key);
+
+        assertTrue(fut.get());
+
+        assert cache.metrics().getAverageRemoveTime() > 0;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testRemoveAvgTime() throws Exception {
         IgniteCache<Integer, Integer> jcache = grid(0).jcache(null);
         GridCache<Object, Object> cache = grid(0).cache(null);
@@ -173,6 +200,35 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
     /**
      * @throws Exception If failed.
      */
+    public void testRemoveAllAsyncAvgTime() throws Exception {
+        GridCache<Object, Object> cache = grid(0).cache(null);
+
+        Set<Integer> keys = new LinkedHashSet<>();
+
+        for (int i = 0; i < 1000; i++) {
+            if (cache.affinity().isPrimary(grid(0).localNode(), i)) {
+                keys.add(i);
+
+                cache.put(i, i);
+
+                if(keys.size() == 3)
+                    break;
+            }
+        }
+
+        assertEquals(cache.metrics().getAverageRemoveTime(), 0.0, 0.0);
+
+        IgniteFuture<?> fut = cache.removeAllAsync(keys);
+
+        fut.get();
+
+        assert cache.metrics().getAverageRemoveTime() >= 0;
+    }
+
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testGetAvgTime() throws Exception {
         IgniteCache<Integer, Integer> jcache = grid(0).jcache(null);
         GridCache<Object, Object> cache = grid(0).cache(null);
@@ -207,7 +263,7 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
 
         assertEquals(0.0, cache.metrics().getAverageGetTime(), 0.0);
 
-        Set<Integer> keys = new HashSet<>();
+        Set<Integer> keys = new TreeSet<>();
         keys.add(1);
         keys.add(2);
         keys.add(3);
@@ -220,6 +276,34 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
     /**
      * @throws Exception If failed.
      */
+    public void testGetAllAsyncAvgTime() throws Exception {
+        GridCache<Object, Object> cache = grid(0).cache(null);
+
+        assertEquals(0.0, cache.metrics().getAverageGetTime(), 0.0);
+
+        cache.putx(1, 1);
+        cache.putx(2, 2);
+        cache.putx(3, 3);
+
+        assertEquals(0.0, cache.metrics().getAverageGetTime(), 0.0);
+
+        Set<Integer> keys = new TreeSet<>();
+        keys.add(1);
+        keys.add(2);
+        keys.add(3);
+
+        IgniteFuture<Map<Object, Object>> fut = cache.getAllAsync(keys);
+
+        fut.get();
+
+        TimeUnit.MILLISECONDS.sleep(100L);
+
+        assert cache.metrics().getAverageGetTime() > 0;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testPutAvgTime() throws Exception {
         IgniteCache<Integer, Integer> jcache = grid(0).jcache(null);
         GridCache<Object, Object> cache = grid(0).cache(null);
@@ -227,8 +311,6 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
         assertEquals(0.0, cache.metrics().getAveragePutTime(), 0.0);
         assertEquals(0, cache.metrics().writes());
 
-        long start = System.nanoTime();
-
         jcache.put(1, 1);
 
         float avgPutTime = cache.metrics().getAveragePutTime();
@@ -245,6 +327,137 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
     /**
      * @throws Exception If failed.
      */
+    public void testPutxAsyncAvgTime() throws Exception {
+        GridCache<Object, Object> cache = grid(0).cache(null);
+
+        assertEquals(0.0, cache.metrics().getAveragePutTime(), 0.0);
+        assertEquals(0, cache.metrics().getCachePuts());
+
+        IgniteFuture<Boolean> fut = cache.putxAsync(1, 1);
+
+        fut.get();
+
+        TimeUnit.MILLISECONDS.sleep(100L);
+
+        assert cache.metrics().getAveragePutTime() > 0;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPutAsyncAvgTime() throws Exception {
+        GridCache<Object, Object> cache = grid(0).cache(null);
+
+        Integer key = null;
+
+        for (int i = 0; i < 1000; i++) {
+            if (cache.affinity().isPrimary(grid(0).localNode(), i)) {
+                key = i;
+
+                break;
+            }
+        }
+
+        assertEquals(0.0, cache.metrics().getAveragePutTime(), 0.0);
+        assertEquals(0.0, cache.metrics().getAverageGetTime(), 0.0);
+
+        IgniteFuture<?> fut = cache.putAsync(key, key);
+
+        fut.get();
+
+        TimeUnit.MILLISECONDS.sleep(100L);
+
+        assert cache.metrics().getAveragePutTime() > 0;
+        assert cache.metrics().getAverageGetTime() > 0;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPutxIfAbsentAsyncAvgTime() throws Exception {
+        GridCache<Object, Object> cache = grid(0).cache(null);
+
+        Integer key = null;
+
+        for (int i = 0; i < 1000; i++) {
+            if (cache.affinity().isPrimary(grid(0).localNode(), i)) {
+                key = i;
+
+                break;
+            }
+        }
+
+        assertEquals(0.0f, cache.metrics().getAveragePutTime());
+
+        IgniteFuture<Boolean> fut = cache.putxIfAbsentAsync(key, key);
+
+        fut.get();
+
+        TimeUnit.MILLISECONDS.sleep(100L);
+
+        assert cache.metrics().getAveragePutTime() > 0;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPutIfAbsentAsyncAvgTime() throws Exception {
+        GridCache<Object, Object> cache = grid(0).cache(null);
+
+        Integer key = null;
+
+        for (int i = 0; i < 1000; i++) {
+            if (cache.affinity().isPrimary(grid(0).localNode(), i)) {
+                key = i;
+
+                break;
+            }
+        }
+
+        assertEquals(0.0f, cache.metrics().getAveragePutTime());
+
+        IgniteFuture<?> fut = cache.putIfAbsentAsync(key, key);
+
+        fut.get();
+
+        TimeUnit.MILLISECONDS.sleep(100L);
+
+        assert cache.metrics().getAveragePutTime() > 0;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReplaceValAsyncAvgTime() throws Exception {
+        GridCache<Object, Object> cache = grid(0).cache(null);
+
+        Integer key = null;
+
+        for (int i = 0; i < 1000; i++) {
+            if (cache.affinity().isPrimary(grid(0).localNode(), i)) {
+                key = i;
+
+                break;
+            }
+        }
+
+        assertEquals(0.0f, cache.metrics().getAveragePutTime());
+        assertEquals(0.0f, cache.metrics().getAverageGetTime());
+
+        IgniteFuture<?> fut = cache.replaceAsync(key, key, key + 1);
+
+        fut.get();
+
+        TimeUnit.MILLISECONDS.sleep(100L);
+
+        assert cache.metrics().getAveragePutTime() > 0;
+        assert cache.metrics().getAverageGetTime() > 0;
+    }
+
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testPutAllAvgTime() throws Exception {
         IgniteCache<Integer, Integer> jcache = grid(0).jcache(null);
         GridCache<Object, Object> cache = grid(0).cache(null);


Mime
View raw message