mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
Enhancements to Logstash Benchmarking Tool (#10253)
* Adding support for - 1. Custom Data Sets 2. Added heap used statistics to results
This commit is contained in:
parent
056c3e3bb8
commit
3093384705
8 changed files with 117 additions and 7 deletions
|
@ -2,6 +2,7 @@ package org.logstash.benchmark.cli;
|
|||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -12,6 +13,8 @@ public final class BenchmarkMeta {
|
|||
|
||||
private final String testcase;
|
||||
|
||||
private final Path configpath;
|
||||
|
||||
private final String version;
|
||||
|
||||
private final LsVersionType vtype;
|
||||
|
@ -20,15 +23,17 @@ public final class BenchmarkMeta {
|
|||
|
||||
private final int batchsize;
|
||||
|
||||
BenchmarkMeta(final String testcase, final String version, final LsVersionType vtype,
|
||||
final int workers, final int batchsize) {
|
||||
BenchmarkMeta(final String testcase, final Path configpath, final String version, final LsVersionType vtype,
|
||||
final int workers, final int batchsize) {
|
||||
this.testcase = testcase;
|
||||
this.configpath = configpath;
|
||||
this.version = version;
|
||||
this.vtype = vtype;
|
||||
this.workers = workers;
|
||||
this.batchsize = batchsize;
|
||||
}
|
||||
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
@ -37,6 +42,8 @@ public final class BenchmarkMeta {
|
|||
return testcase;
|
||||
}
|
||||
|
||||
public Path getConfigPath() { return configpath; }
|
||||
|
||||
public LsVersionType getVtype() {
|
||||
return vtype;
|
||||
}
|
||||
|
@ -52,6 +59,7 @@ public final class BenchmarkMeta {
|
|||
public Map<String, Object> asMap() {
|
||||
final Map<String, Object> result = new HashMap<>();
|
||||
result.put("test_name", testcase);
|
||||
result.put("test_config_path", configpath);
|
||||
result.put("os_name", SystemUtils.OS_NAME);
|
||||
result.put("os_version", SystemUtils.OS_VERSION);
|
||||
try {
|
||||
|
|
|
@ -40,6 +40,7 @@ public final class LsMetricsMonitor implements Callable<EnumMap<LsMetricStats, L
|
|||
long count = 0L;
|
||||
final ListStatistics counts = new ListStatistics();
|
||||
final ListStatistics cpu = new ListStatistics();
|
||||
final ListStatistics mem = new ListStatistics();
|
||||
long start = System.nanoTime();
|
||||
while (running) {
|
||||
try {
|
||||
|
@ -59,6 +60,7 @@ public final class LsMetricsMonitor implements Callable<EnumMap<LsMetricStats, L
|
|||
count = newcount;
|
||||
counts.addValue((double) count);
|
||||
cpu.addValue(newcounts[1]);
|
||||
mem.addValue(newcounts[2]);
|
||||
} catch (final InterruptedException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
|
@ -67,6 +69,7 @@ public final class LsMetricsMonitor implements Callable<EnumMap<LsMetricStats, L
|
|||
result.put(LsMetricStats.THROUGHPUT, stats);
|
||||
result.put(LsMetricStats.COUNT, counts);
|
||||
result.put(LsMetricStats.CPU_USAGE, cpu);
|
||||
result.put(LsMetricStats.HEAP_USAGE, mem);
|
||||
store.store(result);
|
||||
return result;
|
||||
}
|
||||
|
@ -100,7 +103,13 @@ public final class LsMetricsMonitor implements Callable<EnumMap<LsMetricStats, L
|
|||
} else {
|
||||
cpu = readNestedLong(data, "process", "cpu", "percent");
|
||||
}
|
||||
return new long[]{count, cpu};
|
||||
final long heapUsed;
|
||||
if(count == -1L) {
|
||||
heapUsed = -1L;
|
||||
} else {
|
||||
heapUsed = readNestedLong(data, "jvm", "mem", "heap_used_percent");
|
||||
}
|
||||
return new long[]{count, cpu, heapUsed};
|
||||
} catch (final IOException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import joptsimple.OptionSpec;
|
|||
import joptsimple.OptionSpecBuilder;
|
||||
import org.logstash.benchmark.cli.cases.ApacheLogsComplex;
|
||||
import org.logstash.benchmark.cli.cases.Case;
|
||||
import org.logstash.benchmark.cli.cases.CustomTestCase;
|
||||
import org.logstash.benchmark.cli.cases.GeneratorToStdout;
|
||||
import org.logstash.benchmark.cli.ui.LsMetricStats;
|
||||
import org.logstash.benchmark.cli.ui.LsVersionType;
|
||||
|
@ -67,6 +68,9 @@ public final class Main {
|
|||
final OptionSpec<String> testcase = parser.accepts(
|
||||
UserInput.TEST_CASE_PARAM, UserInput.TEST_CASE_HELP
|
||||
).withRequiredArg().ofType(String.class).defaultsTo(GeneratorToStdout.IDENTIFIER).forHelp();
|
||||
final OptionSpec<File> testcaseconfig = parser.accepts(
|
||||
UserInput.TEST_CASE_CONFIG_PARAM, UserInput.TEST_CASE_CONFIG_HELP
|
||||
).withRequiredArg().ofType(File.class).forHelp();
|
||||
final OptionSpec<File> pwd = parser.accepts(
|
||||
UserInput.WORKING_DIRECTORY_PARAM, UserInput.WORKING_DIRECTORY_HELP
|
||||
).withRequiredArg().ofType(File.class).defaultsTo(UserInput.WORKING_DIRECTORY_DEFAULT)
|
||||
|
@ -108,8 +112,19 @@ public final class Main {
|
|||
settings.setProperty(
|
||||
LsBenchSettings.INPUT_DATA_REPEAT, String.valueOf(options.valueOf(repeats))
|
||||
);
|
||||
|
||||
Path testCaseConfigPath = null;
|
||||
if (options.valueOf(testcase).equals("custom")) {
|
||||
if (options.has(testcaseconfig)) {
|
||||
testCaseConfigPath = options.valueOf(testcaseconfig).toPath();
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Path to Test Case Config must be provided");
|
||||
}
|
||||
}
|
||||
|
||||
final BenchmarkMeta runConfig = new BenchmarkMeta(
|
||||
options.valueOf(testcase), version, type, options.valueOf(workers),
|
||||
options.valueOf(testcase), testCaseConfigPath, version, type, options.valueOf(workers),
|
||||
options.valueOf(batchsize)
|
||||
);
|
||||
execute(
|
||||
|
@ -148,6 +163,12 @@ public final class Main {
|
|||
Integer.parseInt(settings.getProperty(LsBenchSettings.INPUT_DATA_REPEAT))
|
||||
)
|
||||
);
|
||||
if (runConfig.getTestcase().equals("custom")) {
|
||||
output.green(
|
||||
String.format("Test Case Config: %s", runConfig.getConfigPath())
|
||||
);
|
||||
}
|
||||
|
||||
output.printLine();
|
||||
Files.createDirectories(cwd);
|
||||
final LogstashInstallation logstash;
|
||||
|
@ -185,7 +206,10 @@ public final class Main {
|
|||
testcase = new GeneratorToStdout(store, logstash, settings, runConfig);
|
||||
} else if (ApacheLogsComplex.IDENTIFIER.equalsIgnoreCase(test)) {
|
||||
testcase = new ApacheLogsComplex(store, logstash, cwd, settings, output, runConfig);
|
||||
} else {
|
||||
} else if (CustomTestCase.IDENTIFIER.equalsIgnoreCase(test)) {
|
||||
testcase = new CustomTestCase(store, logstash, cwd, settings, output, runConfig);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(String.format("Unknown test case %s", test));
|
||||
}
|
||||
return testcase;
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package org.logstash.benchmark.cli.cases;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.logstash.benchmark.cli.*;
|
||||
import org.logstash.benchmark.cli.ui.LsMetricStats;
|
||||
import org.logstash.benchmark.cli.ui.UserOutput;
|
||||
import org.openjdk.jmh.util.ListStatistics;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class CustomTestCase implements Case {
|
||||
public static final String IDENTIFIER = "custom";
|
||||
|
||||
private final LogstashInstallation logstash;
|
||||
private final DataStore store;
|
||||
private final Path configpath;
|
||||
|
||||
public CustomTestCase(DataStore store, LogstashInstallation logstash, Path cwd, Properties settings, UserOutput output, BenchmarkMeta runConfig) {
|
||||
this.logstash = logstash;
|
||||
logstash.configure(runConfig);
|
||||
this.store = store;
|
||||
this.configpath = runConfig.getConfigPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractMap<LsMetricStats, ListStatistics> run() {
|
||||
try (final LsMetricsMonitor.MonitorExecution monitor =
|
||||
new LsMetricsMonitor.MonitorExecution(logstash.metrics(), store)) {
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
try (final InputStream cfg = Files.newInputStream(configpath)){
|
||||
IOUtils.copy(cfg, baos);
|
||||
}
|
||||
logstash.execute(baos.toString());
|
||||
return monitor.stopAndGet();
|
||||
} catch (final IOException | InterruptedException | ExecutionException | TimeoutException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,5 +15,7 @@ public enum LsMetricStats {
|
|||
/**
|
||||
* Statistics on CPU usage.
|
||||
*/
|
||||
CPU_USAGE
|
||||
CPU_USAGE,
|
||||
|
||||
HEAP_USAGE
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public final class UserInput {
|
|||
public static final String TEST_CASE_PARAM = "testcase";
|
||||
|
||||
public static final String TEST_CASE_HELP =
|
||||
"Currently available test cases are 'baseline' and 'apache'.";
|
||||
"Currently available test cases are 'baseline', 'apache' and 'custom'.";
|
||||
|
||||
public static final String LS_WORKER_THREADS = "ls-workers";
|
||||
|
||||
|
@ -79,6 +79,10 @@ public final class UserInput {
|
|||
public static final String WORKING_DIRECTORY_HELP =
|
||||
"Working directory to store cached files in.";
|
||||
|
||||
public static final String TEST_CASE_CONFIG_PARAM = "config";
|
||||
public static final String TEST_CASE_CONFIG_HELP =
|
||||
"Path to custom logstash config. Required if testcase is set to 'custom'";
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
|
|
|
@ -80,6 +80,11 @@ public final class UserOutput {
|
|||
"Mean CPU Usage: %.2f%%", stats.get(LsMetricStats.CPU_USAGE).getMean()
|
||||
)
|
||||
);
|
||||
green(
|
||||
String.format(
|
||||
"Mean Heap Usage: %.2f%%", stats.get(LsMetricStats.HEAP_USAGE).getMean()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static String colorize(final String line, final String prefix) {
|
||||
|
|
|
@ -97,4 +97,16 @@ public final class MainTest {
|
|||
String.format("--%s=%d", UserInput.REPEAT_PARAM, 2)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception On Failure
|
||||
*/
|
||||
@Test
|
||||
public void runsCustomAgainstLocal() throws Exception {
|
||||
Main.main(
|
||||
String.format("--%s=custom", UserInput.TEST_CASE_PARAM),
|
||||
String.format("--%s=%s", UserInput.TEST_CASE_CONFIG_PARAM, System.getProperty("logstash.benchmark.test.config.path") ),
|
||||
String.format("--%s=%s", UserInput.LOCAL_VERSION_PARAM, System.getProperty("logstash.benchmark.test.local.path"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue