运行 AWS Lambda 中的 OptaPlanner 给出与 AlphaNetworkCompilation 相关的错误

Running OptaPlanner in AWS Lambda gives AlphaNetworkCompilation related error

我正在尝试 运行 AWS Lambda 中的 Optaplanner (8.20.0) 求解器,上传到一个包含所有依赖项的 fat-jar 中。当 运行 解决方案时(或者更具体地说,当创建求解器时:在 SolverFactory.create() 上,我遇到以下错误:

  [ ... snip - large list of "Cannot find symbol" / "Cannot find package" errors ... ]
  location: class org.drools.ancompiler.CompiledPACKAGE_LOCATION_domain_ParticipationNetwork41408373267, org/drools/ancompiler/CompiledPACKAGE_LOCATION_domain_ParticipationNetwork41408373267.java (95:16) : cannot find symbol
  symbol:   variable objectTypeNode
  location: class org.drools.ancompiler.CompiledPACKAGE_LOCATION_domain_ParticipationNetwork41408373267, org/drools/ancompiler/CompiledPACKAGE_LOCATION_domain_ParticipationNetwork41408373267.java (99:16) : cannot find symbol
  symbol:   variable objectTypeNode
  location: class org.drools.ancompiler.CompiledPACKAGE_LOCATION_domain_ParticipationNetwork41408373267]
    at org.kie.memorycompiler.KieMemoryCompiler.compileNoLoad(KieMemoryCompiler.java:136)
    at org.kie.memorycompiler.KieMemoryCompiler.compileNoLoad(KieMemoryCompiler.java:104)
    at org.kie.memorycompiler.KieMemoryCompiler.compile(KieMemoryCompiler.java:56)
    at org.kie.memorycompiler.KieMemoryCompiler.compile(KieMemoryCompiler.java:42)
    at org.drools.ancompiler.KieBaseUpdaterANC.inMemoryUpdate(KieBaseUpdaterANC.java:66)
    at org.drools.ancompiler.KieBaseUpdaterANC.run(KieBaseUpdaterANC.java:52)
    at org.drools.ancompiler.KieBaseUpdaterANC.generateAndSetInMemoryANC(KieBaseUpdaterANC.java:99)
    at org.optaplanner.core.impl.score.director.stream.DroolsConstraintStreamScoreDirectorFactory.buildKieBaseFromModel(DroolsConstraintStreamScoreDirectorFactory.java:115)
    at org.optaplanner.core.impl.score.director.stream.DroolsConstraintStreamScoreDirectorFactory.buildKieBase(DroolsConstraintStreamScoreDirectorFactory.java:104)
    at org.optaplanner.core.impl.score.director.stream.DroolsConstraintStreamScoreDirectorFactory.<init>(DroolsConstraintStreamScoreDirectorFactory.java:71)
    at org.optaplanner.core.impl.score.director.stream.ConstraintStreamsScoreDirectorFactoryService.lambda$buildScoreDirectorFactory[=11=](ConstraintStreamsScoreDirectorFactoryService.java:50)
    at org.optaplanner.core.impl.score.director.ScoreDirectorFactoryFactory.decideMultipleScoreDirectorFactories(ScoreDirectorFactoryFactory.java:115)
    at org.optaplanner.core.impl.score.director.ScoreDirectorFactoryFactory.buildScoreDirectorFactory(ScoreDirectorFactoryFactory.java:52)
    at org.optaplanner.core.impl.solver.DefaultSolverFactory.buildScoreDirectorFactory(DefaultSolverFactory.java:168)
    at org.optaplanner.core.impl.solver.DefaultSolverFactory.<init>(DefaultSolverFactory.java:78)
    at org.optaplanner.core.api.solver.SolverFactory.create(SolverFactory.java:122)
[ ... snip - trace of my code before calling SolverFactory.create() ... ]

我似乎已经将问题追溯到 Drools 中存在的内存中 Alpha 网络编译器。具体来说,按照 this answer solves my problem. However, the problem does not seem to be that AWS Lambda does not provide a Java compiler. For one thing the error in the linked issue is different, and secondly 中的建议禁用 DroolsAlphaNetworkCompilationEnabled 似乎表明 AWS Lambda 函数能够编译 类 一些 运行time classpath hacks。

我的问题:

  1. 将 DroolsAlphaNetworkCompilationEnabled 设置为 false(目前解决了我的问题)对性能有何影响?
  2. 有没有办法避免内存中的 DroolsAlphaNetworkCompilation?深入研究一些源文件使我在 drools alphanetwork compiler which supports a LOAD option and loading the compiled network from a KJar. However, DroolsConstraintStreamScoreDirectorFactory calls generateAndSetInMemoryANC, which forces in-memory compilation. This might be the same question as DROOLS-5990
  3. 中找到了 KieBaseUpdaterANC.java
  4. 作为万不得已的措施, 中建议的类路径编译器破解是否以任何方式与我的 optaplanner/drools 用例相关或可实施?

Wrt。 1:性能影响可能相当大。我们已经看到性能下降高达 50%,但是 YMMV。这在很大程度上取决于正在解决的问题。

Wrt。 2:您已经能够通过求解器配置禁用 ANC。这是官方支持的选项,您无需寻找任何其他选项。

Wrt。 3:我看不出有一种方法可以像上面提到的那样通过 hack 连接到我们自己的 ANC。也许使用 Quarkus,它可以在项目 build-time 而不是在运行时进行编译,可以解决您的问题?

综上所述,这个错误不应该首先出现。让我们看看 Drools 的人对此有什么要说的。