You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2014/02/12 18:10:40 UTC
git commit: make cache mode configurable in triplestore and platform
for clustered operation
Updated Branches:
refs/heads/develop 99254fe81 -> 964b28ccd
make cache mode configurable in triplestore and platform for clustered operation
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/964b28cc
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/964b28cc
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/964b28cc
Branch: refs/heads/develop
Commit: 964b28ccdf21853c5af89eb9b1afb2a6e8244ea3
Parents: 99254fe
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Wed Feb 12 18:10:33 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Wed Feb 12 18:10:33 2014 +0100
----------------------------------------------------------------------
.../marmotta/kiwi/caching/KiWiCacheManager.java | 59 ++++++++++++------
.../apache/marmotta/kiwi/config/CacheMode.java | 45 ++++++++++++++
.../marmotta/kiwi/config/KiWiConfiguration.java | 46 ++++++++++++++
.../core/services/cache/CachingServiceImpl.java | 65 +++++++++++++-------
4 files changed, 172 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/964b28cc/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/KiWiCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/KiWiCacheManager.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/KiWiCacheManager.java
index be9538e..9760a66 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/KiWiCacheManager.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/KiWiCacheManager.java
@@ -41,6 +41,9 @@ import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.TimeUnit;
+import static org.apache.marmotta.kiwi.config.CacheMode.DISTRIBUTED;
+import static org.apache.marmotta.kiwi.config.CacheMode.REPLICATED;
+
/**
* A class for managing the different caches that are used by the triple store.
* <p/>
@@ -85,7 +88,7 @@ public class KiWiCacheManager {
this.clustered = config.isClustered();
this.kiWiConfiguration = config;
- if(clustered) {
+ if(clustered && (config.getCacheMode() == DISTRIBUTED || config.getCacheMode() == REPLICATED)) {
try {
String jgroupsXml = IOUtils.toString(KiWiCacheManager.class.getResourceAsStream("/jgroups-kiwi.xml"));
@@ -126,27 +129,43 @@ public class KiWiCacheManager {
}
-
- defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.DIST_ASYNC)
- .async()
- .asyncMarshalling()
- .l1()
- .lifespan(5, TimeUnit.MINUTES)
- .hash()
- .numOwners(2)
- .numSegments(40)
- .consistentHashFactory(new SyncConsistentHashFactory())
+ if(config.getCacheMode() == DISTRIBUTED) {
+ defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.DIST_ASYNC)
+ .async()
+ .asyncMarshalling()
+ .l1()
+ .lifespan(5, TimeUnit.MINUTES)
+ .hash()
+ .numOwners(2)
+ .numSegments(40)
+ .consistentHashFactory(new SyncConsistentHashFactory())
+ .stateTransfer()
+ .fetchInMemoryState(false)
+ .eviction()
+ .strategy(EvictionStrategy.LIRS)
+ .maxEntries(100000)
+ .expiration()
+ .lifespan(30, TimeUnit.MINUTES)
+ .maxIdle(10, TimeUnit.MINUTES)
+ .build();
+ } else {
+ defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.REPL_ASYNC)
+ .async()
+ .asyncMarshalling()
.stateTransfer()
.fetchInMemoryState(false)
- .eviction()
- .strategy(EvictionStrategy.LIRS)
- .maxEntries(100000)
- .expiration()
- .lifespan(30, TimeUnit.MINUTES)
- .maxIdle(10, TimeUnit.MINUTES)
- .build();
+ .eviction()
+ .strategy(EvictionStrategy.LIRS)
+ .maxEntries(100000)
+ .expiration()
+ .lifespan(30, TimeUnit.MINUTES)
+ .maxIdle(10, TimeUnit.MINUTES)
+ .build();
+ }
} else {
globalConfiguration = new GlobalConfigurationBuilder()
.classLoader(KiWiCacheManager.class.getClassLoader())
http://git-wip-us.apache.org/repos/asf/marmotta/blob/964b28cc/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/CacheMode.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/CacheMode.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/CacheMode.java
new file mode 100644
index 0000000..94964b4
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/CacheMode.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.config;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public enum CacheMode {
+ /**
+ * In local cache mode, the cache is not shared among the servers in a cluster. Each machine keeps a local cache.
+ * This allows quick startups and eliminates network traffic in the cluster, but subsequent requests to different
+ * cluster members cannot benefit from the cached data.
+ */
+ LOCAL,
+
+ /**
+ * In distributed cache mode, the cluster forms a big hash table used as a cache. This allows to make efficient
+ * use of the large amount of memory available, but requires cache rebalancing and a lot of network transfers,
+ * especially in case cluster members are restarted often.
+ */
+ DISTRIBUTED,
+
+ /**
+ * In replicated cache mode, each node in the cluster has an identical copy of all cache data. This allows
+ * very efficient cache lookups and reduces the rebalancing effort, but requires more memory.
+ */
+ REPLICATED
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/964b28cc/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
index 8be3c76..21e740e 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
@@ -106,6 +106,9 @@ public class KiWiConfiguration {
private RegistryStrategy registryStrategy = RegistryStrategy.CACHE;
+
+ private CacheMode cacheMode = CacheMode.DISTRIBUTED;
+
/**
* Enable to turn on cluster mode (e.g. for cache replication)
*/
@@ -413,6 +416,49 @@ public class KiWiConfiguration {
/**
+ * Get the cache mode for this KiWi triple store. The following cluster modes are available:
+ * <ul>
+ * <li>LOCAL: In local cache mode, the cache is not shared among the servers in a cluster. Each machine keeps a local cache.
+ * This allows quick startups and eliminates network traffic in the cluster, but subsequent requests to different
+ * cluster members cannot benefit from the cached data.</li>
+ * <li>DISTRIBUTED: In distributed cache mode, the cluster forms a big hash table used as a cache. This allows to make efficient
+ * use of the large amount of memory available, but requires cache rebalancing and a lot of network transfers,
+ * especially in case cluster members are restarted often.</li>
+ * <li>REPLICATED: In replicated cache mode, each node in the cluster has an identical copy of all cache data. This allows
+ * very efficient cache lookups and reduces the rebalancing effort, but requires more memory.</li>
+ * </ul>
+ *
+ * This setting is only relevant if clustered = true . If the configuration is not clustered, the triple store will always
+ * use LOCAL mode.
+ *
+ */
+ public CacheMode getCacheMode() {
+ return cacheMode;
+ }
+
+ /**
+ * Set the cache mode for this KiWi triple store. The following cluster modes are available:
+ * <ul>
+ * <li>LOCAL: In local cache mode, the cache is not shared among the servers in a cluster. Each machine keeps a local cache.
+ * This allows quick startups and eliminates network traffic in the cluster, but subsequent requests to different
+ * cluster members cannot benefit from the cached data.</li>
+ * <li>DISTRIBUTED: In distributed cache mode, the cluster forms a big hash table used as a cache. This allows to make efficient
+ * use of the large amount of memory available, but requires cache rebalancing and a lot of network transfers,
+ * especially in case cluster members are restarted often.</li>
+ * <li>REPLICATED: In replicated cache mode, each node in the cluster has an identical copy of all cache data. This allows
+ * very efficient cache lookups and reduces the rebalancing effort, but requires more memory.</li>
+ * </ul>
+ *
+ * This setting is only relevant if clustered = true . If the configuration is not clustered, the triple store will always
+ * use LOCAL mode.
+ *
+ * @param cacheMode
+ */
+ public void setCacheMode(CacheMode cacheMode) {
+ this.cacheMode = cacheMode;
+ }
+
+ /**
* Return the name of the cluster. This name is e.g. used by the Infinispan cache to identify other cache members
* in the same cluster,
*
http://git-wip-us.apache.org/repos/asf/marmotta/blob/964b28cc/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/cache/CachingServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/cache/CachingServiceImpl.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/cache/CachingServiceImpl.java
index 2ac763d..f53cdc6 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/cache/CachingServiceImpl.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/cache/CachingServiceImpl.java
@@ -18,6 +18,7 @@
package org.apache.marmotta.platform.core.services.cache;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.marmotta.platform.core.api.cache.CachingService;
import org.apache.marmotta.platform.core.api.config.ConfigurationService;
import org.apache.marmotta.platform.core.events.SystemRestartingEvent;
@@ -58,6 +59,7 @@ public class CachingServiceImpl implements CachingService {
public static final String CLUSTERING_PORT = "clustering.port";
public static final String CLUSTERING_ADDRESS = "clustering.address";
public static final String CLUSTERING_ENABLED = "clustering.enabled";
+ public static final String CLUSTERING_MODE = "clustering.mode";
/**
* Get the seam logger for issuing logging statements.
@@ -83,9 +85,11 @@ public class CachingServiceImpl implements CachingService {
@PostConstruct
public void initialize() {
boolean clustered = configurationService.getBooleanConfiguration(CLUSTERING_ENABLED, false);
+ String cacheMode = configurationService.getStringConfiguration(CLUSTERING_MODE,"replicated");
+
log.info("Apache Marmotta Caching Service starting up ({}) ...", clustered ? "cluster name: " + configurationService.getStringConfiguration("clustering.name", "Marmotta") : "single host" );
- if(clustered) {
+ if(clustered && (StringUtils.equalsIgnoreCase(cacheMode,"replicated") || StringUtils.equalsIgnoreCase(cacheMode, "distributed"))) {
try {
String jgroupsXml = IOUtils.toString(CachingService.class.getResourceAsStream("/jgroups-marmotta.xml"));
@@ -120,28 +124,43 @@ public class CachingServiceImpl implements CachingService {
}
-
-
- defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.DIST_ASYNC)
- .async()
+ if(StringUtils.equalsIgnoreCase(cacheMode, "distributed")) {
+ defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.DIST_ASYNC)
+ .async()
+ .asyncMarshalling()
+ .l1()
+ .lifespan(5, TimeUnit.MINUTES)
+ .hash()
+ .numOwners(2)
+ .numSegments(40)
+ .consistentHashFactory(new SyncConsistentHashFactory())
+ .stateTransfer()
+ .fetchInMemoryState(false)
+ .eviction()
+ .strategy(EvictionStrategy.LIRS)
+ .maxEntries(100000)
+ .expiration()
+ .lifespan(30, TimeUnit.MINUTES)
+ .maxIdle(10, TimeUnit.MINUTES)
+ .build();
+ } else {
+ defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.REPL_ASYNC)
+ .async()
.asyncMarshalling()
- .l1()
- .lifespan(5, TimeUnit.MINUTES)
- .hash()
- .numOwners(2)
- .numSegments(40)
- .consistentHashFactory(new SyncConsistentHashFactory())
- .stateTransfer()
- .fetchInMemoryState(false)
- .eviction()
- .strategy(EvictionStrategy.LIRS)
- .maxEntries(10000)
- .expiration()
- .lifespan(30, TimeUnit.MINUTES)
- .maxIdle(10, TimeUnit.MINUTES)
- .build();
+ .stateTransfer()
+ .fetchInMemoryState(false)
+ .eviction()
+ .strategy(EvictionStrategy.LIRS)
+ .maxEntries(100000)
+ .expiration()
+ .lifespan(30, TimeUnit.MINUTES)
+ .maxIdle(10, TimeUnit.MINUTES)
+ .build();
+ }
} else {
globalConfiguration = new GlobalConfigurationBuilder()
.globalJmxStatistics()
@@ -154,7 +173,7 @@ public class CachingServiceImpl implements CachingService {
.cacheMode(CacheMode.LOCAL)
.eviction()
.strategy(EvictionStrategy.LIRS)
- .maxEntries(1000)
+ .maxEntries(100000)
.expiration()
.lifespan(5, TimeUnit.MINUTES)
.maxIdle(1, TimeUnit.MINUTES)