You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/06/03 17:06:41 UTC
[40/42] incubator-ignite git commit: ignite-861 AveragePutTime not
updating for local atomic cache
ignite-861 AveragePutTime not updating for local atomic cache
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/97d0bc18
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/97d0bc18
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/97d0bc18
Branch: refs/heads/ignite-883_1
Commit: 97d0bc18401fbb9ede57010acbc6b58ff3f108ca
Parents: 71efd27
Author: agura <ag...@gridgain.com>
Authored: Tue May 12 15:37:54 2015 +0300
Committer: agura <ag...@gridgain.com>
Committed: Wed Jun 3 02:30:14 2015 +0300
----------------------------------------------------------------------
.../local/atomic/GridLocalAtomicCache.java | 25 +++++++++-
.../cache/GridCacheAbstractMetricsSelfTest.java | 48 +++++++-------------
2 files changed, 39 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/97d0bc18/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
index c0dc360..bcbdec4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
@@ -119,7 +119,11 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
@Override public boolean put(K key, V val, CacheEntryPredicate[] filter) throws IgniteCheckedException {
A.notNull(key, "key", val, "val");
- return (Boolean)updateAllInternal(UPDATE,
+ boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+ long start = statsEnabled ? System.nanoTime() : 0L;
+
+ boolean res = (Boolean)updateAllInternal(UPDATE,
Collections.singleton(key),
Collections.singleton(val),
null,
@@ -129,6 +133,11 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
filter,
ctx.writeThrough(),
ctx.readThrough());
+
+ if (statsEnabled)
+ metrics0().addPutTimeNanos(System.nanoTime() - start);
+
+ return res;
}
/** {@inheritDoc} */
@@ -268,6 +277,10 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
/** {@inheritDoc} */
@Override public void putAll(Map<? extends K, ? extends V> m) throws IgniteCheckedException {
+ boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+ long start = statsEnabled ? System.nanoTime() : 0L;
+
updateAllInternal(UPDATE,
m.keySet(),
m.values(),
@@ -278,6 +291,9 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
CU.empty0(),
ctx.writeThrough(),
ctx.readThrough());
+
+ if (statsEnabled)
+ metrics0().addPutTimeNanos(System.nanoTime() - start);
}
/** {@inheritDoc} */
@@ -727,7 +743,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
final ExpiryPolicy expiry = expiryPerCall();
- return asyncOp(new Callable<Object>() {
+ IgniteInternalFuture fut = asyncOp(new Callable<Object>() {
@Override public Object call() throws Exception {
return updateAllInternal(op,
keys,
@@ -741,6 +757,11 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
readThrough);
}
});
+
+ if (ctx.config().isStatisticsEnabled())
+ fut.listen(new UpdatePutTimeStatClosure(metrics0(), System.nanoTime()));
+
+ return fut;
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/97d0bc18/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java
index 1821e12..bb1732e 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java
@@ -38,7 +38,7 @@ import static java.util.concurrent.TimeUnit.*;
*/
public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstractSelfTest {
/** */
- private static final int KEY_CNT = 50;
+ private static final int KEY_CNT = 500;
/** {@inheritDoc} */
@Override protected boolean swapEnabled() {
@@ -163,24 +163,18 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
IgniteCache<Object, Object> cacheAsync = cache.withAsync();
- cache.put(1, 1);
- cache.put(2, 2);
+ for (int i = 0; i < KEY_CNT; i++)
+ cache.put(i, i);
assertEquals(cache.metrics().getAverageRemoveTime(), 0.0, 0.0);
- cacheAsync.getAndRemove(1);
-
- IgniteFuture<Object> fut = cacheAsync.future();
-
- assertEquals(1, (int)fut.get());
-
- assert cache.metrics().getAverageRemoveTime() > 0;
-
- cacheAsync.getAndRemove(2);
+ for (int i = 0; i < KEY_CNT; i++) {
+ cacheAsync.getAndRemove(i);
- fut = cacheAsync.future();
+ IgniteFuture<Object> fut = cacheAsync.future();
- assertEquals(2, (int)fut.get());
+ fut.get();
+ }
assert cache.metrics().getAverageRemoveTime() > 0;
}
@@ -221,18 +215,13 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
public void testRemoveAvgTime() throws Exception {
IgniteCache<Integer, Integer> cache = grid(0).cache(null);
- cache.put(1, 1);
- cache.put(2, 2);
+ for (int i = 0; i < KEY_CNT; i++)
+ cache.put(i, i);
assertEquals(cache.metrics().getAverageRemoveTime(), 0.0, 0.0);
- cache.remove(1);
-
- float avgRmvTime = cache.metrics().getAverageRemoveTime();
-
- assert avgRmvTime > 0;
-
- cache.remove(2);
+ for (int i = 0; i < KEY_CNT; i++)
+ cache.remove(i);
assert cache.metrics().getAverageRemoveTime() > 0;
}
@@ -378,17 +367,12 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
assertEquals(0.0, cache.metrics().getAveragePutTime(), 0.0);
assertEquals(0, cache.metrics().getCachePuts());
- cache.put(1, 1);
-
- float avgPutTime = cache.metrics().getAveragePutTime();
-
- assert avgPutTime >= 0;
-
- assertEquals(1, cache.metrics().getCachePuts());
+ for (int i = 0; i < KEY_CNT; i++)
+ cache.put(i, i);
- cache.put(2, 2);
+ assert cache.metrics().getAveragePutTime() > 0;
- assert cache.metrics().getAveragePutTime() >= 0;
+ assertEquals(KEY_CNT, cache.metrics().getCachePuts());
}
/**