Search in sources :

Example 1 with LocalWorker

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));
}
Also used : LocalWorker(io.openmessaging.benchmark.worker.LocalWorker) DistributedWorkersEnsemble(io.openmessaging.benchmark.worker.DistributedWorkersEnsemble) WorkloadGenerator(io.openmessaging.benchmark.WorkloadGenerator) Worker(io.openmessaging.benchmark.worker.Worker) LocalWorker(io.openmessaging.benchmark.worker.LocalWorker) TestResult(io.openmessaging.benchmark.TestResult) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with LocalWorker

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();
}
Also used : LocalWorker(io.openmessaging.benchmark.worker.LocalWorker) IOException(java.io.IOException) TreeMap(java.util.TreeMap) Date(java.util.Date) ParameterException(com.beust.jcommander.ParameterException) IOException(java.io.IOException) JCommander(com.beust.jcommander.JCommander) DistributedWorkersEnsemble(io.openmessaging.benchmark.worker.DistributedWorkersEnsemble) Worker(io.openmessaging.benchmark.worker.Worker) LocalWorker(io.openmessaging.benchmark.worker.LocalWorker) ParameterException(com.beust.jcommander.ParameterException) File(java.io.File)

Aggregations

DistributedWorkersEnsemble (io.openmessaging.benchmark.worker.DistributedWorkersEnsemble)2 LocalWorker (io.openmessaging.benchmark.worker.LocalWorker)2 Worker (io.openmessaging.benchmark.worker.Worker)2 File (java.io.File)2 IOException (java.io.IOException)2 JCommander (com.beust.jcommander.JCommander)1 ParameterException (com.beust.jcommander.ParameterException)1 TestResult (io.openmessaging.benchmark.TestResult)1 WorkloadGenerator (io.openmessaging.benchmark.WorkloadGenerator)1 Date (java.util.Date)1 TreeMap (java.util.TreeMap)1 ExecutionException (java.util.concurrent.ExecutionException)1