【问题标题】:Optaplanner benchmarking with Quarkus使用 Quarkus 进行 Optaplanner 基准测试
【发布时间】:2021-04-07 16:34:14
【问题描述】:

我想使用 Quarkus Optaplanner 应用程序进行高级基准测试。实现和运行它的最佳方式是什么?

在浏览 Optaplanner 的“旧”示例时,它们都实现了基准测试(在这个 video 中,有一个关于使用 Quarkus 的 Optaplanner 的演示文稿,但使用旧示例显示了基准测试)。我用 Quarkus 构建了我的优化求解器,我想知道如何在这里实现基准测试。我的输入数据写在 JSON 文件中,我想尝试不同的求解器配置。

【问题讨论】:

    标签: benchmarking quarkus optaplanner


    【解决方案1】:

    这是缺少的功能,我们正在处理它,因此您可能只需将 benchmarkConfig.xml 文件放在 src/test/resources 中,而无需任何 entityClass 等信息 - 甚至根本没有配置 xml 文件 - 并且刚刚好。

    我相信它会在 8.5 或 8.6 登陆。

    解决方法

    同时,这可行:

    // 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);
                }
            }
        }
    
    }
    

    【讨论】:

    • 我明白了,它不包含在 8.5 中 :( 我对 Optaplanner 还不够熟悉,还没有弄清楚如何使用/实现您的答案。我需要哪些类来完成这项工作+如何做我运行它?
    • 我有你提出的这个文件和solverBenchmarkConfig.xml 都直接在src/main/java 中。我收到此错误: benchmarkConfigResource 在类加载器(QuarkusClassLoader:Quarkus Runtime ClassLoader)中不作为类路径资源存在。我能做什么?
    猜你喜欢
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-12
    • 2012-01-23
    • 2011-04-27
    相关资源
    最近更新 更多