Skip to content

Commit

Permalink
LDEV-4962 - add warmup function support
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Jun 29, 2024
1 parent 2e8b277 commit 19d337d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
41 changes: 28 additions & 13 deletions core/src/main/java/lucee/runtime/engine/CFMLEngineImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1676,15 +1676,27 @@ public Controler getControler() {

public void onStart(ConfigPro config, boolean reload) {
boolean isWeb = config instanceof ConfigWeb;
String context = isWeb ? "Web" : "Server";

if ((isWeb || config.getAdminMode() == ConfigImpl.ADMINMODE_SINGLE) && Caster.toBooleanValue(SystemUtil.getSystemPropOrEnvVar("lucee.enable.warmup", ""), false)) {
String msg = "Lucee warmup completed. Shutting down.";
CONSOLE_ERR.println(msg);
LogUtil.log(config, Log.LEVEL_ERROR, "application", msg);
shutdownFelix();
System.exit(0);
Boolean build = Caster.toBoolean(SystemUtil.getSystemPropOrEnvVar("lucee.enable.warmup", ""), null);
if (build == null) build = Caster.toBoolean(SystemUtil.getSystemPropOrEnvVar("lucee.build", ""), null);
boolean warmup = Boolean.TRUE.equals(build);
if (warmup) {
if (!isWeb) {
onStartCall(config, reload, true);

String msg = "Lucee warmup completed. Shutting down.";
// CONSOLE_OUT.println(msg);
LogUtil.logGlobal(config, Log.LEVEL_INFO, "config", msg);
LogUtil.log(config, Log.LEVEL_INFO, "application", msg);
shutdownFelix();
System.exit(0);
}
}
else onStartCall(config, reload, false);
}

private void onStartCall(ConfigPro config, boolean reload, boolean warmup) {
boolean isWeb = config instanceof ConfigWeb;
String context = isWeb ? "Web" : "Server";

if (!ThreadLocalPageContext.callOnStart.get()) return;

Expand Down Expand Up @@ -1713,7 +1725,7 @@ else if (listenerTemplateCFML.isFile()) {
if (!StringUtil.emptyIfNull(Thread.currentThread().getName()).startsWith("on-start-")) {
long timeout = config.getRequestTimeout().getMillis();
if (timeout <= 0) timeout = 50000L;
OnStart thread = new OnStart(config, context, reload, inWebRoot);
OnStart thread = new OnStart(config, context, reload, inWebRoot, warmup);
thread.setName("on-start-" + CreateUniqueId.invoke());
long start = System.currentTimeMillis();
thread.start();
Expand All @@ -1724,10 +1736,10 @@ else if (listenerTemplateCFML.isFile()) {
LogUtil.log(config, "on-start", e);
}
if (thread.isAlive()) {
LogUtil.log(config, Log.LEVEL_ERROR, "on-start", "killing on-start");
LogUtil.log(config, Log.LEVEL_INFO, "on-start", "killing on-start");
SystemUtil.stop(thread);
}
LogUtil.log(config, Log.LEVEL_INFO, "on-start", "on-start executed in " + (System.currentTimeMillis() - start) + "ms");
LogUtil.log(config, Log.LEVEL_INFO, "on-start", "on-" + (warmup ? "warmup" : "start") + " executed in " + (System.currentTimeMillis() - start) + "ms");
}
}

Expand All @@ -1740,12 +1752,14 @@ private class OnStart extends Thread {
private boolean reload;
private String context;
private boolean inWebRoot;
private boolean warmup;

public OnStart(ConfigPro config, String context, boolean reload, boolean inWebRoot) {
public OnStart(ConfigPro config, String context, boolean reload, boolean inWebRoot, boolean warmup) {
this.config = config;
this.context = context;
this.reload = reload;
this.inWebRoot = inWebRoot;
this.warmup = warmup;
}

@Override
Expand All @@ -1766,7 +1780,8 @@ public void run() {
catch (IOException e) {
throw Caster.toPageException(e);
}
String queryString = "method=on" + context + "Start&reload=" + reload + "&" + ComponentPageImpl.REMOTE_PERSISTENT_ID + "=" + remotePersisId;
String methodName = warmup ? "onBuild" : ("on" + context + "Start");
String queryString = "method=" + methodName + "&reload=" + reload + "&" + ComponentPageImpl.REMOTE_PERSISTENT_ID + "=" + remotePersisId;
if (config instanceof ConfigWeb) {
Pair[] headers = new Pair[] { new Pair<String, Object>("AMF-Forward", "true") };
Struct attrs = new StructImpl();
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.1.1.10-SNAPSHOT"/>
<property name="version" value="6.1.1.11-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.1.1.10-SNAPSHOT</version>
<version>6.1.1.11-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit 19d337d

Please sign in to comment.