mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
graal js support
This commit is contained in:
parent
be93ee52ea
commit
aeb9765543
@ -4,6 +4,7 @@ import ch.qos.logback.classic.Level;
|
||||
import io.nosqlbench.engine.api.metrics.IndicatorMode;
|
||||
import io.nosqlbench.engine.api.scenarios.NBCLIScenarioParser;
|
||||
import io.nosqlbench.engine.api.util.Unit;
|
||||
import io.nosqlbench.engine.core.script.Scenario;
|
||||
import io.nosqlbench.nb.api.content.Content;
|
||||
import io.nosqlbench.nb.api.content.NBIO;
|
||||
import org.slf4j.Logger;
|
||||
@ -74,6 +75,10 @@ public class NBCLIOptions {
|
||||
private final static String ENABLE_CHART = "--enable-chart";
|
||||
private final static String DOCKER_METRICS = "--docker-metrics";
|
||||
|
||||
private static final String GRAALVM_ENGINE = "--graalvm";
|
||||
private static final String NASHORN_ENGINE = "--nashorn";
|
||||
|
||||
|
||||
public static final Set<String> RESERVED_WORDS = new HashSet<>() {{
|
||||
addAll(
|
||||
Arrays.asList(
|
||||
@ -119,6 +124,8 @@ public class NBCLIOptions {
|
||||
private String wantsToCopyWorkload = null;
|
||||
private boolean wantsWorkloadsList = false;
|
||||
private final List<String> wantsToIncludePaths = new ArrayList<>();
|
||||
private Scenario.Engine engine = Scenario.Engine.Graalvm;
|
||||
|
||||
|
||||
public NBCLIOptions(String[] args) {
|
||||
parse(args);
|
||||
@ -174,6 +181,14 @@ public class NBCLIOptions {
|
||||
}
|
||||
|
||||
switch (word) {
|
||||
case GRAALVM_ENGINE:
|
||||
engine = Scenario.Engine.Graalvm;
|
||||
arglist.removeFirst();
|
||||
break;
|
||||
case NASHORN_ENGINE:
|
||||
engine = Scenario.Engine.Nashorn;
|
||||
arglist.removeFirst();
|
||||
break;
|
||||
case SHOW_SCRIPT:
|
||||
arglist.removeFirst();
|
||||
showScript = true;
|
||||
@ -402,6 +417,10 @@ public class NBCLIOptions {
|
||||
return levels;
|
||||
}
|
||||
|
||||
public Scenario.Engine getScriptingEngine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
public List<LoggerConfig> getHistoLoggerConfigs() {
|
||||
List<LoggerConfig> configs = histoLoggerConfigs.stream().map(LoggerConfig::new).collect(Collectors.toList());
|
||||
checkLoggerConfigs(configs, LOG_HISTOGRAMS);
|
||||
|
@ -81,6 +81,33 @@
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- graalvm -->
|
||||
<dependency>
|
||||
<groupId>org.graalvm.sdk</groupId>
|
||||
<artifactId>graal-sdk</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.graalvm.js</groupId>
|
||||
<artifactId>js</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.graalvm.js</groupId>
|
||||
<artifactId>js-scriptengine</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.graalvm.tools</groupId>
|
||||
<artifactId>profiler</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.graalvm.tools</groupId>
|
||||
<artifactId>chromeinspector</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- only compile scope -->
|
||||
|
||||
</dependencies>
|
||||
|
@ -105,6 +105,11 @@ public class ScenarioController {
|
||||
public synchronized void run(String activityDefString) {
|
||||
run(Integer.MAX_VALUE, activityDefString);
|
||||
}
|
||||
//
|
||||
// public synchronized void run(Value v) {
|
||||
// logger.debug("run(Value) called with:" + v);
|
||||
// throw new RuntimeException("fix it");
|
||||
// }
|
||||
|
||||
public synchronized void run(ActivityDef activityDef) {
|
||||
run(Integer.MAX_VALUE, activityDef);
|
||||
|
@ -56,6 +56,12 @@ public class Scenario implements Callable<ScenarioResult> {
|
||||
private ScenarioLogger scenarioLogger;
|
||||
private ScriptParams scenarioScriptParams;
|
||||
private boolean areChartsEnabled;
|
||||
private Engine engine = Engine.Graalvm;
|
||||
|
||||
public enum Engine {
|
||||
Nashorn,
|
||||
Graalvm
|
||||
}
|
||||
|
||||
public Scenario(String name, String progressInterval) {
|
||||
this.name = name;
|
||||
@ -68,6 +74,7 @@ public class Scenario implements Callable<ScenarioResult> {
|
||||
|
||||
public Scenario addScriptText(String scriptText) {
|
||||
scripts.add(scriptText);
|
||||
this.engine = engine;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -91,16 +98,35 @@ public class Scenario implements Callable<ScenarioResult> {
|
||||
|
||||
private void init() {
|
||||
|
||||
logger.info("Using engine " + engine.toString());
|
||||
|
||||
MetricRegistry metricRegistry = ActivityMetrics.getMetricRegistry();
|
||||
|
||||
scriptEngine = engineManager.getEngineByName("nashorn");
|
||||
scriptEnv = new ScenarioContext(scenarioController);
|
||||
scriptEngine.setContext(scriptEnv);
|
||||
switch (engine) {
|
||||
case Nashorn:
|
||||
scriptEngine = engineManager.getEngineByName("nashorn");
|
||||
break;
|
||||
case Graalvm:
|
||||
scriptEngine = engineManager.getEngineByName("graal.js");
|
||||
Bindings bindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE);
|
||||
bindings.put("polyglot.js.allowHostAccess", true);
|
||||
bindings.put("polyglot.js.allowNativeAccess", true);
|
||||
bindings.put("polyglot.js.allowCreateThread", true);
|
||||
bindings.put("polyglot.js.allowIO", true);
|
||||
bindings.put("polyglot.js.allowHostClassLookup", true);
|
||||
bindings.put("polyglot.js.allowHostClassLoading", true);
|
||||
bindings.put("polyglot.js.allowAllAccess", true);
|
||||
break;
|
||||
}
|
||||
|
||||
scenarioController = new ScenarioController();
|
||||
if (!progressInterval.equals("disabled")) {
|
||||
progressIndicator = new ProgressIndicator(scenarioController,progressInterval);
|
||||
}
|
||||
|
||||
scriptEnv = new ScenarioContext(scenarioController);
|
||||
scriptEngine.setContext(scriptEnv);
|
||||
|
||||
scriptEngine.put("params", scenarioScriptParams);
|
||||
scriptEngine.put("scenario", scenarioController);
|
||||
scriptEngine.put("activities", new ActivityBindings(scenarioController));
|
||||
|
@ -75,6 +75,7 @@
|
||||
<source.plugin.version>3.0.1</source.plugin.version>
|
||||
<surefire.plugin.version>3.0.0-M4</surefire.plugin.version>
|
||||
<assertj.version>3.15.0</assertj.version>
|
||||
<graalvm.version>20.0.0</graalvm.version>
|
||||
</properties>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
@ -439,6 +440,36 @@
|
||||
<version>${assertj.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- graalvm -->
|
||||
<dependency>
|
||||
<groupId>org.graalvm.sdk</groupId>
|
||||
<artifactId>graal-sdk</artifactId>
|
||||
<version>${graalvm.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.graalvm.js</groupId>
|
||||
<artifactId>js</artifactId>
|
||||
<version>${graalvm.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.graalvm.js</groupId>
|
||||
<artifactId>js-scriptengine</artifactId>
|
||||
<version>${graalvm.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.graalvm.tools</groupId>
|
||||
<artifactId>profiler</artifactId>
|
||||
<version>${graalvm.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.graalvm.tools</groupId>
|
||||
<artifactId>chromeinspector</artifactId>
|
||||
<version>${graalvm.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
@ -20,12 +20,15 @@ package io.nosqlbench.engine.core.script;
|
||||
import io.nosqlbench.engine.core.ScenarioLogger;
|
||||
import io.nosqlbench.engine.core.ScenarioResult;
|
||||
import io.nosqlbench.engine.core.ScenariosResults;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.assertj.core.data.Offset;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
@ -53,7 +56,18 @@ public class AsyncScriptIntegrationTests {
|
||||
ScenariosExecutor e = new ScenariosExecutor(AsyncScriptIntegrationTests.class.getSimpleName() + ":" + scriptname, 1);
|
||||
Scenario s = new Scenario(scenarioName);
|
||||
s.addScenarioScriptParams(paramsMap);
|
||||
s.addScriptText("load('classpath:scripts/async/" + scriptname + ".js');");
|
||||
|
||||
ClassLoader cl = AsyncScriptIntegrationTests.class.getClassLoader();
|
||||
String script;
|
||||
try {
|
||||
InputStream sstream = cl.getResourceAsStream("scripts/async/" + scriptname + ".js");
|
||||
byte[] bytes = IOUtils.toByteArray(sstream);
|
||||
script = new String(bytes, StandardCharsets.UTF_8);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
s.addScriptText(script);
|
||||
// s.addScriptText("load('classpath:scripts/async/" + scriptname + ".js');");
|
||||
ScenarioLogger scenarioLogger = new ScenarioLogger(s).setMaxLogs(0).setLogDir("logs/test").start();
|
||||
e.execute(s, scenarioLogger);
|
||||
ScenariosResults scenariosResults = e.awaitAllResults();
|
||||
|
@ -20,10 +20,14 @@ package io.nosqlbench.engine.core.script;
|
||||
import io.nosqlbench.engine.core.ScenarioLogger;
|
||||
import io.nosqlbench.engine.core.ScenarioResult;
|
||||
import io.nosqlbench.engine.core.ScenariosResults;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.assertj.core.data.Offset;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
@ -47,7 +51,17 @@ public class ScriptIntegrationTests {
|
||||
ScenariosExecutor e = new ScenariosExecutor(ScriptIntegrationTests.class.getSimpleName() + ":" + scriptname, 1);
|
||||
Scenario s = new Scenario(scenarioName);
|
||||
s.addScenarioScriptParams(paramsMap);
|
||||
s.addScriptText("load('classpath:scripts/sync/" + scriptname + ".js');");
|
||||
ClassLoader cl = AsyncScriptIntegrationTests.class.getClassLoader();
|
||||
String script;
|
||||
try {
|
||||
InputStream sstream = cl.getResourceAsStream("scripts/sync/" + scriptname + ".js");
|
||||
byte[] bytes = IOUtils.toByteArray(sstream);
|
||||
script = new String(bytes, StandardCharsets.UTF_8);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
s.addScriptText(script);
|
||||
// s.addScriptText("load('classpath:scripts/sync/" + scriptname + ".js');");
|
||||
ScenarioLogger scenarioLogger = new ScenarioLogger(s).setMaxLogs(0).setLogDir("logs/test").start();
|
||||
e.execute(s, scenarioLogger);
|
||||
ScenariosResults scenariosResults = e.awaitAllResults();
|
||||
|
Loading…
Reference in New Issue
Block a user