use of io.openmessaging.benchmark.worker.LocalWorker in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class OMB method runWorkload.
public OMBWorkloadResult runWorkload(File testDir, OMBDriver driver, List<String> workers, OMBWorkload workload) throws Exception {
File driverFile = new File(testDir, "driver.yaml");
File resultFile = new File(testDir, String.format("result_%s.json", workload.getName().replaceAll(" ", "_")));
Files.writeString(driverFile.toPath(), MAPPER.writeValueAsString(driver));
LOGGER.info("Wrote driver to {}", driverFile.getAbsolutePath());
workload.validate();
try (Worker worker = workers.isEmpty() ? new LocalWorker() : new DistributedWorkersEnsemble(workers);
WorkloadGenerator generator = new WorkloadGenerator(driver.name, workload, worker)) {
LOGGER.info("--------------- WORKLOAD: {} --- DRIVER: {} ---------------", workload.name, driver.name);
worker.initializeDriver(driverFile);
TestResult result = generator.run();
try {
worker.stopAll();
} catch (IOException e) {
}
LOGGER.info("Writing test result into {}", resultFile.getAbsolutePath());
WRITER.writeValue(resultFile, result);
} catch (Exception e) {
LOGGER.error("Failed to run the workload '{}' for driver '{}'", workload.name, driverFile.getAbsolutePath(), e);
throw e;
}
TestMetadataCapture.getInstance().storeOmbData(ombCluster, workload, driver, this);
return new OMBWorkloadResult(resultFile, createTestResult(resultFile));
}
use of io.openmessaging.benchmark.worker.LocalWorker in project openmessaging-benchmark by redpanda-data.
the class Benchmark method main.
public static void main(String[] args) throws Exception {
final Arguments arguments = new Arguments();
JCommander jc = new JCommander(arguments);
jc.setProgramName("messaging-benchmark");
try {
jc.parse(args);
} catch (ParameterException e) {
System.err.println(e.getMessage());
jc.usage();
System.exit(-1);
}
if (arguments.help) {
jc.usage();
System.exit(-1);
}
if (arguments.workers != null && arguments.workersFile != null) {
System.err.println("Only one between --workers and --workers-file can be specified");
System.exit(-1);
}
if (arguments.workers == null && arguments.workersFile == null) {
File defaultFile = new File("workers.yaml");
if (defaultFile.exists()) {
log.info("Using default worker file workers.yaml");
arguments.workersFile = defaultFile;
}
}
if (arguments.workersFile != null) {
log.info("Reading workers list from {}", arguments.workersFile);
arguments.workers = mapper.readValue(arguments.workersFile, Workers.class).workers;
}
// Dump configuration variables
log.info("Starting benchmark with config: {}", writer.writeValueAsString(arguments));
Map<String, Workload> workloads = new TreeMap<>();
for (String path : arguments.workloads) {
File file = new File(path);
String name = file.getName().substring(0, file.getName().lastIndexOf('.'));
workloads.put(name, mapper.readValue(file, Workload.class));
}
log.info("Workloads: {}", writer.writeValueAsString(workloads));
Worker worker;
if (arguments.workers != null && !arguments.workers.isEmpty()) {
worker = new DistributedWorkersEnsemble(arguments.workers);
} else {
// Use local worker implementation
worker = new LocalWorker();
}
workloads.forEach((workloadName, workload) -> {
try {
workload.validate();
} catch (IllegalArgumentException e) {
e.printStackTrace();
System.exit(-1);
}
arguments.drivers.forEach(driverConfig -> {
try {
File driverConfigFile = new File(driverConfig);
DriverConfiguration driverConfiguration = mapper.readValue(driverConfigFile, DriverConfiguration.class);
log.info("--------------- WORKLOAD : {} --- DRIVER : {}---------------", workload.name, driverConfiguration.name);
// Stop any left over workload
worker.stopAll();
worker.initializeDriver(new File(driverConfig));
WorkloadGenerator generator = new WorkloadGenerator(driverConfiguration.name, workload, worker);
TestResult result = generator.run();
String fileName;
if (arguments.output != null && arguments.output.length() > 0) {
fileName = arguments.output;
} else {
fileName = String.format("%s-%s-%s.json", workloadName, driverConfiguration.name, dateFormat.format(new Date()));
}
log.info("Writing test result into {}", fileName);
writer.writeValue(new File(fileName), result);
generator.close();
} catch (Exception e) {
log.error("Failed to run the workload '{}' for driver '{}'", workload.name, driverConfig, e);
} finally {
try {
worker.stopAll();
} catch (IOException e) {
}
}
});
});
worker.close();
}
Aggregations