diff --git a/smart-connector-api/src/main/java/eu/knowledge/engine/smartconnector/api/SmartConnectorConfig.java b/smart-connector-api/src/main/java/eu/knowledge/engine/smartconnector/api/SmartConnectorConfig.java index 17f7f7d9..bb660735 100644 --- a/smart-connector-api/src/main/java/eu/knowledge/engine/smartconnector/api/SmartConnectorConfig.java +++ b/smart-connector-api/src/main/java/eu/knowledge/engine/smartconnector/api/SmartConnectorConfig.java @@ -63,29 +63,34 @@ public class SmartConnectorConfig { * Key to configure if a KER should use the EDC functionality or not. */ public static final String CONF_KEY_KE_RUNTIME_USE_EDC = "ke.runtime.use.edc"; - + /** - * Key to configure where a KER can reach the protocol API of its own control plane if using EDC. + * Key to configure where a KER can reach the protocol API of its own control + * plane if using EDC. */ public static final String CONF_KEY_KE_EDC_PROTOCOL_URL = "ke.edc.protocol.url"; - + /** - * Key to configure where a KER can reach the management API of its own control plane if using EDC. + * Key to configure where a KER can reach the management API of its own control + * plane if using EDC. */ public static final String CONF_KEY_KE_EDC_MANAGEMENT_URL = "ke.edc.management.url"; - + /** - * Key to configure where a KER can reach its data plane control API if using EDC. + * Key to configure where a KER can reach its data plane control API if using + * EDC. */ public static final String CONF_KEY_KE_EDC_DATAPLANE_CONTROL_URL = "ke.edc.dataplane.control.url"; - + /** - * Key to configure where a KER can reach its data plane public API if using EDC. + * Key to configure where a KER can reach its data plane public API if using + * EDC. */ public static final String CONF_KEY_KE_EDC_DATAPLANE_PUBLIC_URL = "ke.edc.dataplane.public.url"; - + /** - * Key to configure the URL where a KER can do token validation through the control plane if using EDC. + * Key to configure the URL where a KER can do token validation through the + * control plane if using EDC. */ public static final String CONF_KEY_KE_EDC_TOKEN_VALIDATION_ENDPOINT = "ke.edc.token.validation.endpoint"; @@ -120,6 +125,26 @@ public class SmartConnectorConfig { */ public static final String CONF_KEY_KE_DOMAIN_KNOWLEDGE_PATH = "ke.domain.knowledge.path"; + /** + * Configure the maximum number of entries in the node cache that is being used + * to speed up converting from graph patterns and bindingsets to RDF. See: + * {@code eu.knowledge.engine.smartconnector.impl.Util.nodeCache} + * + */ + public static final String CONF_KEY_KE_CACHE_NODE_SIZE = "ke.cache.node.size"; + + /** + * Configure the number of minutes of being idle (not accessed) after which a + * cache entry can be evicted from cache. + */ + public static final String CONF_KEY_KE_CACHE_NODE_EXPIRYMINUTES = "ke.cache.node.expiryminutes"; + + /** + * The main thread pool of the Knowledge Engine Runtime that is used to, among + * other things, deliver messages. + */ + public static final String CONF_KEY_KE_THREADPOOL_SIZE = "ke.threadpool.size"; + /** * Convert the configuration reasoner levels to matching strategies used in the * reasoner code. diff --git a/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/impl/Util.java b/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/impl/Util.java index 135f3827..19932b21 100644 --- a/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/impl/Util.java +++ b/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/impl/Util.java @@ -22,6 +22,8 @@ import org.apache.jena.sparql.sse.SSE; import org.apache.jena.sparql.syntax.ElementPathBlock; import org.apache.jena.sparql.util.FmtUtils; +import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.ConfigProvider; import org.ehcache.config.builders.CacheConfigurationBuilder; import org.ehcache.config.builders.ExpiryPolicyBuilder; import org.ehcache.config.builders.ResourcePoolsBuilder; @@ -33,6 +35,7 @@ import eu.knowledge.engine.smartconnector.api.Binding; import eu.knowledge.engine.smartconnector.api.BindingSet; import eu.knowledge.engine.smartconnector.api.GraphPattern; +import eu.knowledge.engine.smartconnector.api.SmartConnectorConfig; public class Util { private static final Logger LOG = LoggerFactory.getLogger(Util.class); @@ -41,9 +44,15 @@ public class Util { CachingProvider cachingProvider = Caching.getCachingProvider(); CacheManager cacheManager = cachingProvider.getCacheManager(); + long cacheSize = Long.parseLong( + ConfigProvider.getConfig().getConfigValue(SmartConnectorConfig.CONF_KEY_KE_CACHE_NODE_SIZE).getValue()); + + long timeInMinutes = Long.parseLong(ConfigProvider.getConfig() + .getConfigValue(SmartConnectorConfig.CONF_KEY_KE_CACHE_NODE_EXPIRYMINUTES).getValue()); + CacheConfigurationBuilder ehConfig = CacheConfigurationBuilder - .newCacheConfigurationBuilder(String.class, Node.class, ResourcePoolsBuilder.heap(500_000)) - .withExpiry(ExpiryPolicyBuilder.timeToIdleExpiration(java.time.Duration.ofMinutes(10))); + .newCacheConfigurationBuilder(String.class, Node.class, ResourcePoolsBuilder.heap(cacheSize)) + .withExpiry(ExpiryPolicyBuilder.timeToIdleExpiration(java.time.Duration.ofMinutes(timeInMinutes))); Configuration config = Eh107Configuration.fromEhcacheCacheConfiguration(ehConfig); nodeCache = cacheManager.createCache("nodeCache", config); diff --git a/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/runtime/KeRuntime.java b/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/runtime/KeRuntime.java index d3211aa5..69d72f4e 100644 --- a/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/runtime/KeRuntime.java +++ b/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/runtime/KeRuntime.java @@ -82,7 +82,9 @@ public class KeRuntime { // we want to make sure that this threadpool does not keep the JVM alive. So we // set the daemon to true. - executorService = Executors.newScheduledThreadPool(12, new ThreadFactory() { + int nrOfThreads = Integer.parseInt( + ConfigProvider.getConfig().getConfigValue(SmartConnectorConfig.CONF_KEY_KE_THREADPOOL_SIZE).getValue()); + executorService = Executors.newScheduledThreadPool(nrOfThreads, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = Executors.defaultThreadFactory().newThread(r); @@ -130,11 +132,11 @@ public static MessageDispatcher getMessageDispatcher() { .getConfigValue(SmartConnectorConfig.CONF_KEY_KE_RUNTIME_EXPOSED_URL); URI myExposedUrl = new URI(exposedUrl.getValue()); - ConfigValue useEdc = config - .getConfigValue(SmartConnectorConfig.CONF_KEY_KE_RUNTIME_USE_EDC); + ConfigValue useEdc = config.getConfigValue(SmartConnectorConfig.CONF_KEY_KE_RUNTIME_USE_EDC); var myUseEdc = Boolean.parseBoolean(useEdc.getValue()); - messageDispatcher = new MessageDispatcher(myPort, myExposedUrl, new URI(kdUrl.getValue()), myUseEdc); + messageDispatcher = new MessageDispatcher(myPort, myExposedUrl, new URI(kdUrl.getValue()), + myUseEdc); } } catch (NumberFormatException | URISyntaxException e) { LOG.error("Could not parse configuration properties, cannot start Knowledge Engine", e); diff --git a/smart-connector/src/main/resources/META-INF/microprofile-config.properties b/smart-connector/src/main/resources/META-INF/microprofile-config.properties index bbf90fa7..1f2889f2 100644 --- a/smart-connector/src/main/resources/META-INF/microprofile-config.properties +++ b/smart-connector/src/main/resources/META-INF/microprofile-config.properties @@ -8,6 +8,9 @@ sc.validate.outgoing.bindings.wrt.incoming.bindings = true ke.runtime.hostname = localhost ke.reasoner.level = 2 ke.runtime.use.edc = false +ke.cache.node.size = 500000 +ke.cache.node.expiryminutes = 10 +ke.threadpool.size = 12 ke.edc.protocol.url = ke.edc.management.url =