You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by mr...@apache.org on 2016/08/19 17:26:53 UTC
usergrid git commit: Reduce the cache size for graph shards.
Repository: usergrid
Updated Branches:
refs/heads/hotfix-20160819 [created] 6a54d0db0
Reduce the cache size for graph shards.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/6a54d0db
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/6a54d0db
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/6a54d0db
Branch: refs/heads/hotfix-20160819
Commit: 6a54d0db03b4a990a44d3afe6255e4b7d2ce716e
Parents: f9196037
Author: Michael Russo <mr...@apigee.com>
Authored: Fri Aug 19 10:26:31 2016 -0700
Committer: Michael Russo <mr...@apigee.com>
Committed: Fri Aug 19 10:26:31 2016 -0700
----------------------------------------------------------------------
.../usergrid/persistence/graph/GraphFig.java | 2 +-
.../impl/shard/impl/NodeShardCacheImpl.java | 46 +++++---------------
2 files changed, 13 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/6a54d0db/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphFig.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphFig.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphFig.java
index efd94ed..46f6f0c 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphFig.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/GraphFig.java
@@ -134,7 +134,7 @@ public interface GraphFig extends GuicyFig {
long getShardMinDelta();
- @Default("250000")
+ @Default("100000")
@Key(SHARD_CACHE_SIZE)
long getShardCacheSize();
http://git-wip-us.apache.org/repos/asf/usergrid/blob/6a54d0db/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/impl/NodeShardCacheImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/impl/NodeShardCacheImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/impl/NodeShardCacheImpl.java
index 545ac37..0a259f0 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/impl/NodeShardCacheImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/shard/impl/NodeShardCacheImpl.java
@@ -72,18 +72,8 @@ import com.google.inject.Inject;
@Singleton
public class NodeShardCacheImpl implements NodeShardCache {
- /**
- * Only cache shards that have < 10k groups. This is an arbitrary amount, and may change with profiling and
- * testing
- */
- private static final int MAX_WEIGHT_PER_ELEMENT = 10000;
-
-
private final NodeShardAllocation nodeShardAllocation;
private final GraphFig graphFig;
-
-
-
private ListeningScheduledExecutorService refreshExecutors;
private LoadingCache<CacheKey, CacheEntry> graphs;
@@ -111,8 +101,8 @@ public class NodeShardCacheImpl implements NodeShardCache {
final String propertyName = evt.getPropertyName();
if ( propertyName.equals( GraphFig.SHARD_CACHE_SIZE ) || propertyName
- .equals( GraphFig.SHARD_CACHE_TIMEOUT ) || propertyName
- .equals( GraphFig.SHARD_CACHE_REFRESH_WORKERS ) ) {
+ .equals( GraphFig.SHARD_CACHE_TIMEOUT ) || propertyName
+ .equals( GraphFig.SHARD_CACHE_REFRESH_WORKERS ) ) {
updateCache();
@@ -206,20 +196,20 @@ public class NodeShardCacheImpl implements NodeShardCache {
}
this.refreshExecutors = MoreExecutors
- .listeningDecorator( Executors.newScheduledThreadPool( graphFig.getShardCacheRefreshWorkerCount() ) );
+ .listeningDecorator( Executors.newScheduledThreadPool( graphFig.getShardCacheRefreshWorkerCount() ) );
this.graphs = CacheBuilder.newBuilder()
- //we want to asynchronously load new values for existing ones, that way we wont' have to
- //wait for a trip to cassandra
- .refreshAfterWrite( graphFig.getShardCacheTimeout(), TimeUnit.MILLISECONDS )
+ //we want to asynchronously load new values for existing ones, that way we wont' have to
+ //wait for a trip to cassandra
+ .refreshAfterWrite( graphFig.getShardCacheTimeout(), TimeUnit.MILLISECONDS )
- //set our weight function, since not all shards are equal
- .maximumWeight(MAX_WEIGHT_PER_ELEMENT * graphFig.getShardCacheSize() ).weigher( new ShardWeigher() )
+ //set a static cache entry size here
+ .maximumSize(graphFig.getShardCacheSize())
- //set our shard loader
- .build( new ShardCacheLoader() );
+ //set our shard loader
+ .build( new ShardCacheLoader() );
}
@@ -282,7 +272,7 @@ public class NodeShardCacheImpl implements NodeShardCache {
private CacheEntry( final Iterator<ShardEntryGroup> shards ) {
Preconditions.checkArgument( shards.hasNext(),
- "More than 1 entry must be present in the shard to load into cache" );
+ "More than 1 entry must be present in the shard to load into cache" );
this.shards = new TreeMap<>();
/**
@@ -340,7 +330,7 @@ public class NodeShardCacheImpl implements NodeShardCache {
final Iterator<ShardEntryGroup> edges =
- nodeShardAllocation.getShards( key.scope, Optional.<Shard>absent(), key.directedEdgeMeta );
+ nodeShardAllocation.getShards( key.scope, Optional.<Shard>absent(), key.directedEdgeMeta );
final CacheEntry cacheEntry = new CacheEntry( edges );
@@ -363,16 +353,4 @@ public class NodeShardCacheImpl implements NodeShardCache {
//TODO, use RX for sliding window buffering and duplicate removal
}
-
-
- /**
- * Calculates the weight of the entry by geting the size of the cache
- */
- final class ShardWeigher implements Weigher<CacheKey, CacheEntry> {
-
- @Override
- public int weigh( final CacheKey key, final CacheEntry value ) {
- return value.getCacheSize();
- }
- }
}