Search in sources :

Example 1 with ActivityTypeLoader

use of io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader in project nosqlbench by nosqlbench.

the class MetricsMapper method metricsDetail.

public static String metricsDetail(String activitySpec) {
    // StringBuilder metricsDetail = new StringBuilder();
    List<String> metricsDetails = new ArrayList<>();
    ActivityDef activityDef = ActivityDef.parseActivityDef(activitySpec);
    logger.info("introspecting metric names for " + activitySpec);
    Optional<ActivityType> activityType = new ActivityTypeLoader().load(activityDef);
    if (!activityType.isPresent()) {
        throw new RuntimeException("Activity type '" + activityDef.getActivityType() + "' does not exist in this runtime.");
    }
    Activity activity = activityType.get().getAssembledActivity(activityDef, new HashMap<>());
    PolyglotMetricRegistryBindings nashornMetricRegistryBindings = new PolyglotMetricRegistryBindings(ActivityMetrics.getMetricRegistry());
    activity.initActivity();
    activity.getInputDispenserDelegate().getInput(0);
    activity.getActionDispenserDelegate().getAction(0);
    activity.getMotorDispenserDelegate().getMotor(activityDef, 0);
    Map<String, Metric> metricMap = nashornMetricRegistryBindings.getMetrics();
    for (Map.Entry<String, Metric> metricEntry : metricMap.entrySet()) {
        String metricName = metricEntry.getKey();
        Metric metricValue = metricEntry.getValue();
        Map<String, String> getterSummary = getGetterSummary(metricValue);
        // details.put(metricName,getterSummary);
        List<String> methodDetails = getterSummary.entrySet().stream().map(es -> metricName + es.getKey() + "  " + es.getValue()).collect(Collectors.toList());
        methodDetails.sort(String::compareTo);
        String getterText = methodDetails.stream().collect(Collectors.joining("\n"));
        metricsDetails.add(metricName + "\n" + getterText);
    }
    return metricsDetails.stream().collect(Collectors.joining("\n"));
}
Also used : java.util(java.util) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef) Predicate(java.util.function.Predicate) Timer(java.util.Timer) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ActivityMetrics(io.nosqlbench.engine.api.metrics.ActivityMetrics) ActivityTypeLoader(io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader) Logger(org.apache.logging.log4j.Logger) com.codahale.metrics(com.codahale.metrics) Activity(io.nosqlbench.engine.api.activityapi.core.Activity) PolyglotMetricRegistryBindings(io.nosqlbench.engine.core.metrics.PolyglotMetricRegistryBindings) LogManager(org.apache.logging.log4j.LogManager) Method(java.lang.reflect.Method) ActivityType(io.nosqlbench.engine.api.activityapi.core.ActivityType) ActivityType(io.nosqlbench.engine.api.activityapi.core.ActivityType) Activity(io.nosqlbench.engine.api.activityapi.core.Activity) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef) PolyglotMetricRegistryBindings(io.nosqlbench.engine.core.metrics.PolyglotMetricRegistryBindings) ActivityTypeLoader(io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader)

Example 2 with ActivityTypeLoader

use of io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader in project nosqlbench by nosqlbench.

the class ActivityExecutorTest method testNewActivityExecutor.

@Test
public void testNewActivityExecutor() {
    ActivityDef ad = ActivityDef.parseActivityDef("driver=diag;alias=test;cycles=1000;");
    Optional<ActivityType> activityType = new ActivityTypeLoader().load(ad);
    Input longSupplier = new AtomicInput(ad);
    MotorDispenser<?> cmf = getActivityMotorFactory(ad, motorActionDelay(999), longSupplier);
    Activity a = new SimpleActivity(ad);
    InputDispenser idisp = new CoreInputDispenser(a);
    ActionDispenser adisp = new CoreActionDispenser(a);
    OutputDispenser tdisp = CoreServices.getOutputDispenser(a).orElse(null);
    MotorDispenser<?> mdisp = new CoreMotorDispenser(a, idisp, adisp, tdisp);
    a.setActionDispenserDelegate(adisp);
    a.setInputDispenserDelegate(idisp);
    a.setMotorDispenserDelegate(mdisp);
    ActivityExecutor ae = new ActivityExecutor(a, "test-new-executor");
    ad.setThreads(5);
    ae.startActivity();
    int[] speeds = new int[] { 1, 2000, 5, 2000, 2, 2000 };
    for (int offset = 0; offset < speeds.length; offset += 2) {
        int threadTarget = speeds[offset];
        int threadTime = speeds[offset + 1];
        logger.info("Setting thread level to " + threadTarget + " for " + threadTime + " seconds.");
        ad.setThreads(threadTarget);
        try {
            Thread.sleep(threadTime);
        } catch (InterruptedException ignored) {
        }
    }
    ad.setThreads(0);
}
Also used : AtomicInput(io.nosqlbench.engine.api.activityimpl.input.AtomicInput) SimpleActivity(io.nosqlbench.engine.api.activityimpl.SimpleActivity) CoreInputDispenser(io.nosqlbench.engine.api.activityimpl.input.CoreInputDispenser) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef) CoreMotorDispenser(io.nosqlbench.engine.api.activityimpl.motor.CoreMotorDispenser) InputDispenser(io.nosqlbench.engine.api.activityapi.input.InputDispenser) CoreInputDispenser(io.nosqlbench.engine.api.activityimpl.input.CoreInputDispenser) CoreActionDispenser(io.nosqlbench.engine.api.activityimpl.action.CoreActionDispenser) AtomicInput(io.nosqlbench.engine.api.activityimpl.input.AtomicInput) Input(io.nosqlbench.engine.api.activityapi.input.Input) ActivityExecutor(io.nosqlbench.engine.core.lifecycle.ActivityExecutor) SimpleActivity(io.nosqlbench.engine.api.activityimpl.SimpleActivity) CoreActionDispenser(io.nosqlbench.engine.api.activityimpl.action.CoreActionDispenser) OutputDispenser(io.nosqlbench.engine.api.activityapi.output.OutputDispenser) ActivityTypeLoader(io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader) Test(org.junit.jupiter.api.Test)

Example 3 with ActivityTypeLoader

use of io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader in project nosqlbench by nosqlbench.

the class ActivityExecutorTest method testDelayedStartSanity.

@Test
public void testDelayedStartSanity() {
    ActivityDef ad = ActivityDef.parseActivityDef("driver=diag;alias=test;cycles=1000;initdelay=5000;");
    Optional<ActivityType> activityType = new ActivityTypeLoader().load(ad);
    Activity a = new DelayedInitActivity(ad);
    InputDispenser idisp = new CoreInputDispenser(a);
    ActionDispenser adisp = new CoreActionDispenser(a);
    OutputDispenser tdisp = CoreServices.getOutputDispenser(a).orElse(null);
    MotorDispenser<?> mdisp = new CoreMotorDispenser(a, idisp, adisp, tdisp);
    a.setActionDispenserDelegate(adisp);
    a.setOutputDispenserDelegate(tdisp);
    a.setInputDispenserDelegate(idisp);
    a.setMotorDispenserDelegate(mdisp);
    ActivityExecutor ae = new ActivityExecutor(a, "test-delayed-start");
    ad.setThreads(1);
    ae.startActivity();
    ae.awaitCompletion(15000);
    assertThat(idisp.getInput(10).getInputSegment(3)).isNull();
}
Also used : SimpleActivity(io.nosqlbench.engine.api.activityimpl.SimpleActivity) CoreInputDispenser(io.nosqlbench.engine.api.activityimpl.input.CoreInputDispenser) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef) CoreMotorDispenser(io.nosqlbench.engine.api.activityimpl.motor.CoreMotorDispenser) InputDispenser(io.nosqlbench.engine.api.activityapi.input.InputDispenser) CoreInputDispenser(io.nosqlbench.engine.api.activityimpl.input.CoreInputDispenser) CoreActionDispenser(io.nosqlbench.engine.api.activityimpl.action.CoreActionDispenser) ActivityExecutor(io.nosqlbench.engine.core.lifecycle.ActivityExecutor) CoreActionDispenser(io.nosqlbench.engine.api.activityimpl.action.CoreActionDispenser) OutputDispenser(io.nosqlbench.engine.api.activityapi.output.OutputDispenser) ActivityTypeLoader(io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader) Test(org.junit.jupiter.api.Test)

Example 4 with ActivityTypeLoader

use of io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader in project nosqlbench by nosqlbench.

the class ActivityExecutorTest method testRestart.

@Test
public void testRestart() {
    ActivityDef ad = ActivityDef.parseActivityDef("driver=diag;alias=test;cycles=1000;initdelay=5000;");
    Optional<ActivityType> activityType = new ActivityTypeLoader().load(ad);
    Activity a = new DelayedInitActivity(ad);
    InputDispenser idisp = new CoreInputDispenser(a);
    ActionDispenser adisp = new CoreActionDispenser(a);
    OutputDispenser tdisp = CoreServices.getOutputDispenser(a).orElse(null);
    MotorDispenser<?> mdisp = new CoreMotorDispenser(a, idisp, adisp, tdisp);
    a.setActionDispenserDelegate(adisp);
    a.setOutputDispenserDelegate(tdisp);
    a.setInputDispenserDelegate(idisp);
    a.setMotorDispenserDelegate(mdisp);
    ActivityExecutor ae = new ActivityExecutor(a, "test-restart");
    ad.setThreads(1);
    ae.startActivity();
    ae.stopActivity();
    ae.startActivity();
    ae.awaitCompletion(15000);
    assertThat(idisp.getInput(10).getInputSegment(3)).isNull();
}
Also used : SimpleActivity(io.nosqlbench.engine.api.activityimpl.SimpleActivity) CoreInputDispenser(io.nosqlbench.engine.api.activityimpl.input.CoreInputDispenser) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef) CoreMotorDispenser(io.nosqlbench.engine.api.activityimpl.motor.CoreMotorDispenser) InputDispenser(io.nosqlbench.engine.api.activityapi.input.InputDispenser) CoreInputDispenser(io.nosqlbench.engine.api.activityimpl.input.CoreInputDispenser) CoreActionDispenser(io.nosqlbench.engine.api.activityimpl.action.CoreActionDispenser) ActivityExecutor(io.nosqlbench.engine.core.lifecycle.ActivityExecutor) CoreActionDispenser(io.nosqlbench.engine.api.activityimpl.action.CoreActionDispenser) OutputDispenser(io.nosqlbench.engine.api.activityapi.output.OutputDispenser) ActivityTypeLoader(io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader) Test(org.junit.jupiter.api.Test)

Aggregations

ActivityDef (io.nosqlbench.engine.api.activityimpl.ActivityDef)4 ActivityTypeLoader (io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader)4 InputDispenser (io.nosqlbench.engine.api.activityapi.input.InputDispenser)3 OutputDispenser (io.nosqlbench.engine.api.activityapi.output.OutputDispenser)3 SimpleActivity (io.nosqlbench.engine.api.activityimpl.SimpleActivity)3 CoreActionDispenser (io.nosqlbench.engine.api.activityimpl.action.CoreActionDispenser)3 CoreInputDispenser (io.nosqlbench.engine.api.activityimpl.input.CoreInputDispenser)3 CoreMotorDispenser (io.nosqlbench.engine.api.activityimpl.motor.CoreMotorDispenser)3 ActivityExecutor (io.nosqlbench.engine.core.lifecycle.ActivityExecutor)3 Test (org.junit.jupiter.api.Test)3 com.codahale.metrics (com.codahale.metrics)1 Activity (io.nosqlbench.engine.api.activityapi.core.Activity)1 ActivityType (io.nosqlbench.engine.api.activityapi.core.ActivityType)1 Input (io.nosqlbench.engine.api.activityapi.input.Input)1 AtomicInput (io.nosqlbench.engine.api.activityimpl.input.AtomicInput)1 ActivityMetrics (io.nosqlbench.engine.api.metrics.ActivityMetrics)1 PolyglotMetricRegistryBindings (io.nosqlbench.engine.core.metrics.PolyglotMetricRegistryBindings)1 Method (java.lang.reflect.Method)1 java.util (java.util)1 Timer (java.util.Timer)1