Commit 3b256d6d authored by Ard Schrijvers's avatar Ard Schrijvers

HSTTWO-4326 [Backport 11.2] Actively preload all Hst Configuration jcr nodes without http request

Before, the first http request triggers the loading of all hst configuration
jcr nodes after which the hst model is constructed. The latter part is really
fast because all in memory. The first part, loading all jcr nodes requires
many database calls and can be slow in case when there are very many hst config

Triggering now the loading of all hst configuration nodes when the HST
spring component manager has just been initialized. Since we postpone the
hst spring componenent mngr initialization after the repository is available,
we can now always load the hst configuration nodes right after the mngr
has become available

To suppress this initial loading without http request of the hst
configuration nodes, you can set a context param in the web.xml
with hst-lazy-configuration-loading = true. By default, the lazy
loading is false

(cherry picked from commit 0dee51d9)
parent b59cabcb
* Copyright 2008-2015 Hippo B.V. (
* Copyright 2008-2017 Hippo B.V. (
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory;
public class HstServices {
private static final Logger log = LoggerFactory.getLogger(HstServices.class);
private static boolean available;
private static boolean hstConfigurationNodesLoaded;
private static ComponentManager componentManager;
private static String HST_VERSION;
......@@ -55,7 +56,18 @@ public class HstServices {
public static boolean isAvailable() {
return HstServices.available;
* @return {@code true} when the hst configuration JCR nodes have been loaded from the database into memory already
public static boolean isHstConfigurationNodesLoaded() {
return hstConfigurationNodesLoaded;
public static void setHstConfigurationNodesLoaded(final boolean hstConfigurationNodesLoaded) {
HstServices.hstConfigurationNodesLoaded = hstConfigurationNodesLoaded;
* @return Returns the {@link HstRequestProcessor} component to serve requests.
* @deprecated since CMS 10.0 (hst 2.30). If needed, use
......@@ -36,6 +36,7 @@ import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.hippoecm.hst.configuration.cache.HstNodeLoadingCache;
import org.hippoecm.hst.container.event.ComponentManagerBeforeReplacedEvent;
import org.hippoecm.hst.core.container.ComponentManager;
import org.hippoecm.hst.core.container.ContainerException;
......@@ -148,6 +149,8 @@ public class DefaultHstSiteConfigurer implements HstSiteConfigurer {
private boolean hstSystemPropertiesOverride = true;
private boolean lazyHstConfigurationLoading = false;
private String hstConfigEnvProperties = HST_CONFIG_ENV_PROPERTIES;
// -------------------------------------------------------------------
......@@ -230,6 +233,8 @@ public class DefaultHstSiteConfigurer implements HstSiteConfigurer {
lazyHstConfigurationLoading = BooleanUtils.toBoolean(getConfigOrContextInitParameter(HST_LAZY_HST_CONFIGURATION_LOADING_PARAM, "false"));
hstSystemPropertiesOverride = BooleanUtils.toBoolean(getConfigOrContextInitParameter(HST_SYSTEM_PROPERTIES_OVERRIDE_PARAM, "true"));
hstConfigEnvProperties = getConfigOrContextInitParameter(HST_CONFIG_ENV_PROPERTIES_PARAM, HST_CONFIG_ENV_PROPERTIES);
......@@ -321,8 +326,18 @@ public class DefaultHstSiteConfigurer implements HstSiteConfigurer {
this.initialized = true;
if (!HstServices.isHstConfigurationNodesLoaded() && !lazyHstConfigurationLoading) {"Trigger HST Configuration nodes to be loaded");
final long start = System.currentTimeMillis();
final HstNodeLoadingCache hstNodeLoadingCache = componentManager.getComponent(HstNodeLoadingCache.class);
// triggers the loading of all the hst configuration nodes
HstServices.setHstConfigurationNodesLoaded(true);"Loaded all HST Configuraion JCR nodes in {} ms.", (System.currentTimeMillis() - start));
this.initialized = true;
} catch (Exception e) {
log.error("HstSiteConfigServlet: ComponentManager initialization failed.", e);
* Copyright 2008-2015 Hippo B.V. (
* Copyright 2008-2017 Hippo B.V. (
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -49,6 +49,14 @@ public interface HstSiteConfigurer extends Serializable {
String HST_CONFIG_ENV_PROPERTIES_PARAM = "hst-env-config-properties";
* Flag to make the initial loading of all hst configuration jcr nodes lazy (waiting for the first request) instead
* of all the config nodes being actively fetched directly after the HST Spring Component Manager creation
* Either "true" or "false". lazyHstConfigurationLoading
String HST_LAZY_HST_CONFIGURATION_LOADING_PARAM = "hst-lazy-configuration-loading";
* Loads configuration and initialize HST Container.
* @throws ContainerException if fails to load and initialize
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment