mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2024-12-24 16:00:09 -06:00
externalize interpreted script file by default
This commit is contained in:
parent
209641b66b
commit
8cecd4063b
@ -18,7 +18,6 @@ import io.nosqlbench.engine.core.script.MetricsMapper;
|
||||
import io.nosqlbench.engine.core.script.Scenario;
|
||||
import io.nosqlbench.engine.core.script.ScenariosExecutor;
|
||||
import io.nosqlbench.nb.api.markdown.exporter.MarkdownExporter;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
import io.nosqlbench.virtdata.userlibs.apps.VirtDataMainApp;
|
||||
import io.nosqlbench.docsys.core.DocServerApp;
|
||||
import org.slf4j.Logger;
|
||||
@ -254,10 +253,12 @@ public class NBCLI {
|
||||
|
||||
Scenario scenario = new Scenario(
|
||||
sessionName,
|
||||
options.getScriptFile(),
|
||||
options.getScriptingEngine(),
|
||||
options.getProgressSpec(),
|
||||
options.wantsGraaljsCompatMode(),
|
||||
options.wantsStackTraces()
|
||||
options.wantsStackTraces(),
|
||||
options.wantsCompileScript()
|
||||
);
|
||||
ScriptBuffer buffer = new BasicScriptBuffer()
|
||||
.add(options.getCommands().toArray(new Cmd[0]));
|
||||
|
@ -16,8 +16,8 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* No CLI parser lib is useful for command structures, it seems. So we have this instead, which is good enough.
|
||||
* If something better is needed later, this can be replaced.
|
||||
* No CLI parser lib is useful for command structures, it seems. So we have this instead, which is
|
||||
* good enough. If something better is needed later, this can be replaced.
|
||||
*/
|
||||
public class NBCLIOptions {
|
||||
|
||||
@ -40,6 +40,8 @@ public class NBCLIOptions {
|
||||
private static final String VERSION_COORDS = "--version-coords";
|
||||
private static final String VERSION = "--version";
|
||||
private static final String SHOW_SCRIPT = "--show-script";
|
||||
private static final String COMPILE_SCRIPT = "--compile-script";
|
||||
private static final String SCRIPT_FILE = "--script-file";
|
||||
private static final String COPY = "--copy";
|
||||
private static final String SHOW_STACKTRACES = "--show-stacktraces";
|
||||
|
||||
@ -74,16 +76,6 @@ public class NBCLIOptions {
|
||||
private static final String GRAALJS_COMPAT = "--graaljs-compat";
|
||||
private static final String DOCKER_GRAFANA_TAG = "--docker-grafana-tag";
|
||||
|
||||
|
||||
public static final Set<String> RESERVED_WORDS = new HashSet<>() {{
|
||||
addAll(
|
||||
Arrays.asList(
|
||||
SCRIPT, ACTIVITY, SCENARIO, RUN, START,
|
||||
FRAGMENT, STOP, AWAIT, WAIT_MILLIS, LIST_ACTIVITY_TYPES, HELP
|
||||
)
|
||||
);
|
||||
}};
|
||||
|
||||
private static final String DEFAULT_CONSOLE_LOGGING_PATTERN = "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n";
|
||||
|
||||
private final LinkedList<Cmd> cmdList = new LinkedList<>();
|
||||
@ -125,6 +117,8 @@ public class NBCLIOptions {
|
||||
private int hdr_digits = 4;
|
||||
private String docker_grafana_tag = "7.0.1";
|
||||
private boolean showStackTraces = false;
|
||||
private boolean compileScript = false;
|
||||
private String scriptFile = null;
|
||||
|
||||
public NBCLIOptions(String[] args) {
|
||||
parse(args);
|
||||
@ -175,7 +169,7 @@ public class NBCLIOptions {
|
||||
switch (word) {
|
||||
case DOCKER_GRAFANA_TAG:
|
||||
arglist.removeFirst();
|
||||
docker_grafana_tag = readWordOrThrow(arglist,"grafana docker tag");
|
||||
docker_grafana_tag = readWordOrThrow(arglist, "grafana docker tag");
|
||||
break;
|
||||
case GRAALJS_COMPAT:
|
||||
graaljs_compat = true;
|
||||
@ -189,6 +183,10 @@ public class NBCLIOptions {
|
||||
engine = Scenario.Engine.Nashorn;
|
||||
arglist.removeFirst();
|
||||
break;
|
||||
case COMPILE_SCRIPT:
|
||||
arglist.removeFirst();
|
||||
compileScript = true;
|
||||
break;
|
||||
case SHOW_SCRIPT:
|
||||
arglist.removeFirst();
|
||||
showScript = true;
|
||||
@ -200,7 +198,7 @@ public class NBCLIOptions {
|
||||
case LIST_METRICS:
|
||||
arglist.removeFirst();
|
||||
arglist.addFirst("start");
|
||||
Cmd cmd = Cmd.parseArg(arglist,canonicalizer);
|
||||
Cmd cmd = Cmd.parseArg(arglist, canonicalizer);
|
||||
wantsMetricsForActivity = cmd.getArg("driver");
|
||||
break;
|
||||
case SESSION_NAME:
|
||||
@ -331,6 +329,10 @@ public class NBCLIOptions {
|
||||
arglist.removeFirst();
|
||||
wantsWorkloadsList = true;
|
||||
break;
|
||||
case SCRIPT_FILE:
|
||||
arglist.removeFirst();
|
||||
scriptFile = readWordOrThrow(arglist, "script file");
|
||||
break;
|
||||
case COPY:
|
||||
arglist.removeFirst();
|
||||
wantsToCopyWorkload = readWordOrThrow(arglist, "workload to copy");
|
||||
@ -394,6 +396,10 @@ public class NBCLIOptions {
|
||||
return showScript;
|
||||
}
|
||||
|
||||
public boolean wantsCompileScript() {
|
||||
return compileScript;
|
||||
}
|
||||
|
||||
public boolean wantsVersionCoords() {
|
||||
return wantsVersionCoords;
|
||||
}
|
||||
@ -413,6 +419,7 @@ public class NBCLIOptions {
|
||||
public boolean wantsStackTraces() {
|
||||
return showStackTraces;
|
||||
}
|
||||
|
||||
public String wantsTopicalHelpFor() {
|
||||
return wantsActivityHelpFor;
|
||||
}
|
||||
@ -485,7 +492,7 @@ public class NBCLIOptions {
|
||||
configs.stream().map(LoggerConfig::getFilename).forEach(s -> {
|
||||
if (files.contains(s)) {
|
||||
logger.warn(s + " is included in " + configName + " more than once. It will only be included " +
|
||||
"in the first matching config. Reorder your options if you need to control this.");
|
||||
"in the first matching config. Reorder your options if you need to control this.");
|
||||
}
|
||||
files.add(s);
|
||||
});
|
||||
@ -511,6 +518,18 @@ public class NBCLIOptions {
|
||||
return this.wantsInputTypes;
|
||||
}
|
||||
|
||||
public String getScriptFile() {
|
||||
if (scriptFile==null) {
|
||||
return logsDirectory+File.separator+"_SESSIONNAME_"+".js";
|
||||
}
|
||||
|
||||
String expanded = scriptFile;
|
||||
if (!expanded.startsWith(File.separator)) {
|
||||
expanded = getLogsDirectory()+File.separator+expanded;
|
||||
}
|
||||
return expanded;
|
||||
}
|
||||
|
||||
public boolean wantsMarkerTypes() {
|
||||
return wantsMarkerTypes;
|
||||
}
|
||||
@ -584,8 +603,8 @@ public class NBCLIOptions {
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException(
|
||||
LOG_HISTOGRAMS +
|
||||
" options must be in either 'regex:filename:interval' or 'regex:filename' or 'filename' format"
|
||||
LOG_HISTOGRAMS +
|
||||
" options must be in either 'regex:filename:interval' or 'regex:filename' or 'filename' format"
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -610,7 +629,7 @@ public class NBCLIOptions {
|
||||
switch (parts.length) {
|
||||
case 2:
|
||||
Unit.msFor(parts[1]).orElseThrow(
|
||||
() -> new RuntimeException("Unable to parse progress indicator indicatorSpec '" + parts[1] + "'")
|
||||
() -> new RuntimeException("Unable to parse progress indicator indicatorSpec '" + parts[1] + "'")
|
||||
);
|
||||
progressSpec.intervalSpec = parts[1];
|
||||
case 1:
|
||||
|
@ -28,12 +28,15 @@ import org.graalvm.polyglot.*;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.script.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -56,20 +59,31 @@ public class Scenario implements Callable<ScenarioResult> {
|
||||
private String scenarioName;
|
||||
private ScenarioLogger scenarioLogger;
|
||||
private ScriptParams scenarioScriptParams;
|
||||
private String scriptfile;
|
||||
private Engine engine = Engine.Graalvm;
|
||||
private boolean wantsStackTraces=false;
|
||||
private boolean wantsCompiledScript;
|
||||
|
||||
public enum Engine {
|
||||
Nashorn,
|
||||
Graalvm
|
||||
}
|
||||
|
||||
public Scenario(String name, Engine engine, String progressInterval, boolean wantsGraaljsCompatMode, boolean wantsStackTraces) {
|
||||
this.name = name;
|
||||
public Scenario(
|
||||
String scenarioName,
|
||||
String scriptfile,
|
||||
Engine engine,
|
||||
String progressInterval,
|
||||
boolean wantsGraaljsCompatMode,
|
||||
boolean wantsStackTraces,
|
||||
boolean wantsCompiledScript) {
|
||||
this.scenarioName = scenarioName;
|
||||
this.scriptfile = scriptfile;
|
||||
this.engine = engine;
|
||||
this.progressInterval = progressInterval;
|
||||
this.wantsGraaljsCompatMode = wantsGraaljsCompatMode;
|
||||
this.wantsStackTraces = wantsStackTraces;
|
||||
this.wantsCompiledScript = wantsCompiledScript;
|
||||
}
|
||||
|
||||
public Scenario(String name, Engine engine) {
|
||||
@ -198,7 +212,7 @@ public class Scenario implements Callable<ScenarioResult> {
|
||||
for (String script : scripts) {
|
||||
try {
|
||||
Object result = null;
|
||||
if (scriptEngine instanceof Compilable) {
|
||||
if (scriptEngine instanceof Compilable && wantsCompiledScript) {
|
||||
logger.debug("Using direct script compilation");
|
||||
Compilable compilableEngine = (Compilable) scriptEngine;
|
||||
CompiledScript compiled = compilableEngine.compile(script);
|
||||
@ -206,9 +220,26 @@ public class Scenario implements Callable<ScenarioResult> {
|
||||
result = compiled.eval();
|
||||
logger.debug("<- scenario completed (compiled)");
|
||||
} else {
|
||||
logger.debug("-> invoking main scenario script (interpreted)");
|
||||
result = scriptEngine.eval(script);
|
||||
logger.debug("<- scenario completed (interpreted)");
|
||||
if (scriptfile != null && !scriptfile.isEmpty()) {
|
||||
|
||||
String filename = scriptfile.replace("_SESSIONNAME_", scenarioName);
|
||||
logger.debug("-> invoking main scenario script (" +
|
||||
"interpreted from " + filename +")");
|
||||
Path written = Files.write(
|
||||
Path.of(filename),
|
||||
script.getBytes(StandardCharsets.UTF_8),
|
||||
StandardOpenOption.TRUNCATE_EXISTING,
|
||||
StandardOpenOption.CREATE
|
||||
);
|
||||
BufferedReader reader = Files.newBufferedReader(written);
|
||||
scriptEngine.eval(reader);
|
||||
logger.debug("<- scenario completed (interpreted " +
|
||||
"from " + filename + ")");
|
||||
} else {
|
||||
logger.debug("-> invoking main scenario script (interpreted)");
|
||||
result = scriptEngine.eval(script);
|
||||
logger.debug("<- scenario completed (interpreted)");
|
||||
}
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user