Search code examples
benchmarkingquarkusoptaplanner

Optaplanner benchmarking with Quarkus


I want to do the advanced benchmarking with Quarkus Optaplanner app. What is the best way to implement and run it?

When going through "old" examples for Optaplanner they all have benchmarking implemented (in this video, there is a presentation about Optaplanner with Quarkus but benchmarking is shown with older examples). I built my optimization solver with Quarkus and I'm wondering how to implement benchmarking here. My input data is written in a JSON file and I would like to try different solver configurations.


Solution

  • This is missing feature, we're working on it, so you can just drop a benchmarkConfig.xml file in src/test/resources probably, without any entityClass etc information - or even without a config xml file at all - and just works.

    It will land in 8.5 or 8.6 I believe.

    Workaround

    Meanwhile, this works:

    // This needs to be in src/main/java, because src/test/java doesn't work
    // TODO move this to src/test/java after https://issues.redhat.com/browse/PLANNER-2341
    @QuarkusMain(name = "benchmark")
    public class VaccinationScheduleBenchmark implements QuarkusApplication {
    
        public static void main(String[] args) {
            Quarkus.run(VaccinationScheduleBenchmark.class, args);
        }
    
        @Inject
        ObjectMapper objectMapper;
    
        @Override
        public int run(String... args) {
            generateDemoFile(5, 25, 0.0);
            generateDemoFile(10, 50, 0.0);
            generateDemoFile(10, 50, 0.3);
            generateDemoFile(25, 500, 0.0);
            generateDemoFile(50, 2000, 0.0);
            generateDemoFile(50, 2000, 0.3);
            // The solverBenchmarkConfig.xml explicitly mentions the entityClass, etc :(
            PlannerBenchmarkFactory benchmarkFactory = PlannerBenchmarkFactory.createFromXmlResource("solverBenchmarkConfig.xml");
            benchmarkFactory.buildPlannerBenchmark()
                    .benchmarkAndShowReportInBrowser();
            return 0;
        }
    
        private void generateDemoFile(int vaccinationCenterCount, int totalBoothCount, double pinnedAppointmentRatio) {
            File file = new File("local/input/" + vaccinationCenterCount + "vc-" + totalBoothCount + "booths"
                    + (pinnedAppointmentRatio > 0.0 ? "-" + pinnedAppointmentRatio + "pinned" : "") + ".json");
            if (!file.exists()) {
                DemoDataGenerator demoDataGenerator = new DemoDataGenerator(33.40, 34.10, -84.90, -83.90);
                VaccinationSchedule schedule = demoDataGenerator.generate(vaccinationCenterCount, totalBoothCount, pinnedAppointmentRatio);
                try {
                    objectMapper.writeValue(file, schedule);
                } catch (IOException e) {
                    throw new IllegalArgumentException("Failed writing file (" + file + ").", e);
                }
            }
        }
    
    }