当前位置: 首页 > 知识库问答 >
问题:

Optaplanner内存泄漏问题

慎俊雄
2023-03-14

我有一个课程调度问题,带有用于分数计算的约束流。当求解分配的堆时,它会不断增加,因此在几个小时后甚至超过8GB,我得到了一个java.lang.OutOfMemoryError:java堆空间。正如optaplanner文档中所述,堆大小在求解器阶段应保持不变。我需要关于这种行为的问题以及如何调试的建议。

optaplanners toList ConstraintCollector中提供的复制器是否存在错误?将重现这种行为。这似乎是对收集器的约束。toList()ist是我的项目中唯一导致泄漏的约束。

我做了一些分析:占用不断增加的内存的分配对象是类型

org.drools.core.util.index.TupleList

线程堆栈如下所示:

SwingWorker-pool-1-thread-3
  at org.drools.core.reteoo.BaseLeftTuple.get(I)Lorg/drools/core/common/InternalFactHandle; (BaseLeftTuple.java:406)
  at org.drools.modelcompiler.constraints.BindingEvaluator.getArgument(Lorg/drools/core/common/InternalFactHandle;Lorg/drools/core/common/InternalWorkingMemory;Lorg/drools/core/rule/Declaration;Lorg/drools/core/spi/Tuple;)Ljava/lang/Object; (BindingEvaluator.java:59)
  at org.drools.modelcompiler.constraints.ConstraintEvaluator$InnerEvaluator.getArgument(Lorg/drools/core/common/InternalFactHandle;Lorg/drools/core/common/InternalWorkingMemory;Lorg/drools/core/rule/Declaration;Lorg/drools/core/spi/Tuple;)Ljava/lang/Object; (ConstraintEvaluator.java:234)
  at org.drools.modelcompiler.constraints.ConstraintEvaluator$InnerEvaluator$_2.evaluate(Lorg/drools/core/common/InternalFactHandle;Lorg/drools/core/spi/Tuple;Lorg/drools/core/common/InternalWorkingMemory;)Z (ConstraintEvaluator.java:283)
  at org.drools.modelcompiler.constraints.ConstraintEvaluator.evaluate(Lorg/drools/core/common/InternalFactHandle;Lorg/drools/core/spi/Tuple;Lorg/drools/core/common/InternalWorkingMemory;)Z (ConstraintEvaluator.java:117)
  at org.drools.modelcompiler.constraints.LambdaConstraint.isAllowedCachedRight(Lorg/drools/core/spi/Tuple;Lorg/drools/core/rule/ContextEntry;)Z (LambdaConstraint.java:160)
  at org.drools.core.common.TripleBetaConstraints.isAllowedCachedRight([Lorg/drools/core/rule/ContextEntry;Lorg/drools/core/spi/Tuple;)Z (TripleBetaConstraints.java:123)
  at org.drools.core.phreak.PhreakJoinNode.doRightUpdatesProcessChildren(Lorg/drools/core/reteoo/LeftTuple;Lorg/drools/core/reteoo/LeftTuple;Lorg/drools/core/reteoo/RightTuple;Lorg/drools/core/common/TupleSets;[Lorg/drools/core/rule/ContextEntry;Lorg/drools/core/common/BetaConstraints;Lorg/drools/core/reteoo/LeftTupleSink;Lorg/drools/core/util/FastIterator;Lorg/drools/core/common/TupleSets;)Lorg/drools/core/reteoo/LeftTuple; (PhreakJoinNode.java:347)
  at org.drools.core.phreak.PhreakJoinNode.doRightUpdates(Lorg/drools/core/reteoo/JoinNode;Lorg/drools/core/reteoo/LeftTupleSink;Lorg/drools/core/reteoo/BetaMemory;Lorg/drools/core/common/InternalWorkingMemory;Lorg/drools/core/common/TupleSets;Lorg/drools/core/common/TupleSets;Lorg/drools/core/common/TupleSets;)V (PhreakJoinNode.java:320)
  at org.drools.core.phreak.PhreakJoinNode.doNode(Lorg/drools/core/reteoo/JoinNode;Lorg/drools/core/reteoo/LeftTupleSink;Lorg/drools/core/reteoo/BetaMemory;Lorg/drools/core/common/InternalWorkingMemory;Lorg/drools/core/common/TupleSets;Lorg/drools/core/common/TupleSets;Lorg/drools/core/common/TupleSets;)V (PhreakJoinNode.java:59)
  at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(Lorg/drools/core/common/NetworkNode;Lorg/drools/core/common/TupleSets;Lorg/drools/core/common/InternalWorkingMemory;Lorg/drools/core/common/TupleSets;Lorg/drools/core/common/TupleSets;Lorg/drools/core/reteoo/LeftTupleSinkNode;Lorg/drools/core/reteoo/BetaMemory;Lorg/drools/core/reteoo/AccumulateNode$AccumulateMemory;)V (RuleNetworkEvaluator.java:569)
  at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(Lorg/drools/core/reteoo/PathMemory;Lorg/drools/core/common/NetworkNode;Lorg/drools/core/common/Memory;[Lorg/drools/core/reteoo/SegmentMemory;ILorg/drools/core/common/TupleSets;Lorg/drools/core/common/InternalAgenda;Lorg/drools/core/util/LinkedList;ZLorg/drools/core/phreak/RuleExecutor;Lorg/drools/core/common/TupleSets;Lorg/drools/core/common/TupleSets;Lorg/drools/core/reteoo/LeftTupleSinkNode;)Z (RuleNetworkEvaluator.java:555)
  at org.drools.core.phreak.RuleNetworkEvaluator.evalNode(Lorg/drools/core/reteoo/PathMemory;Lorg/drools/core/common/NetworkNode;JLorg/drools/core/common/Memory;[Lorg/drools/core/reteoo/SegmentMemory;ILorg/drools/core/common/InternalAgenda;Lorg/drools/core/util/LinkedList;ZLorg/drools/core/phreak/RuleExecutor;Lorg/drools/core/common/TupleSets;Lorg/drools/core/reteoo/SegmentMemory;Lorg/drools/core/common/TupleSets;Lorg/drools/core/reteoo/LeftTupleSinkNode;)Lorg/drools/core/common/TupleSets; (RuleNetworkEvaluator.java:382)
  at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(Lorg/drools/core/reteoo/PathMemory;Lorg/drools/core/common/NetworkNode;JLorg/drools/core/common/Memory;[Lorg/drools/core/reteoo/SegmentMemory;ILorg/drools/core/common/TupleSets;Lorg/drools/core/common/InternalAgenda;Lorg/drools/core/util/LinkedList;ZLorg/drools/core/phreak/RuleExecutor;)V (RuleNetworkEvaluator.java:342)
  at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(Lorg/drools/core/reteoo/PathMemory;Lorg/drools/core/common/NetworkNode;JLorg/drools/core/common/Memory;[Lorg/drools/core/reteoo/SegmentMemory;ILorg/drools/core/common/TupleSets;Lorg/drools/core/common/InternalAgenda;Lorg/drools/core/util/LinkedList;ZLorg/drools/core/phreak/RuleExecutor;)V (RuleNetworkEvaluator.java:178)
  at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(Lorg/drools/core/reteoo/PathMemory;Lorg/drools/core/phreak/RuleExecutor;Lorg/drools/core/common/InternalAgenda;)V (RuleNetworkEvaluator.java:136)
  at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(Lorg/drools/core/common/InternalAgenda;)V (RuleExecutor.java:215)
  at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(Lorg/drools/core/common/InternalAgenda;Lorg/kie/api/runtime/rule/AgendaFilter;II)I (RuleExecutor.java:89)
  at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(Lorg/kie/api/runtime/rule/AgendaFilter;IILorg/drools/core/phreak/RuleAgendaItem;)I (AbstractRuleEvaluator.java:33)
  at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(Lorg/kie/api/runtime/rule/AgendaFilter;IILorg/drools/core/common/InternalAgendaGroup;)I (SequentialRuleEvaluator.java:43)
  at org.drools.core.common.DefaultAgenda.fireLoop(Lorg/kie/api/runtime/rule/AgendaFilter;ILorg/drools/core/common/DefaultAgenda$RestHandler;Z)I (DefaultAgenda.java:1115)
  at org.drools.core.common.DefaultAgenda.internalFireAllRules(Lorg/kie/api/runtime/rule/AgendaFilter;IZ)I (DefaultAgenda.java:1062)
  at org.drools.core.common.DefaultAgenda.fireAllRules(Lorg/kie/api/runtime/rule/AgendaFilter;I)I (DefaultAgenda.java:1054)
  at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(Lorg/kie/api/runtime/rule/AgendaFilter;I)I (StatefulKnowledgeSessionImpl.java:1347)
  at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(Lorg/kie/api/runtime/rule/AgendaFilter;I)I (StatefulKnowledgeSessionImpl.java:1338)
  at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules()I (StatefulKnowledgeSessionImpl.java:1322)
  at org.optaplanner.core.impl.score.stream.drools.DroolsConstraintSession.calculateScore(I)Lorg/optaplanner/core/api/score/Score; (DroolsConstraintSession.java:72)
  at org.optaplanner.core.impl.score.director.stream.ConstraintStreamScoreDirector.calculateScore()Lorg/optaplanner/core/api/score/Score; (ConstraintStreamScoreDirector.java:74)
  at org.optaplanner.core.impl.score.director.AbstractScoreDirector.doAndProcessMove(Lorg/optaplanner/core/impl/heuristic/move/Move;ZLjava/util/function/Consumer;)V (AbstractScoreDirector.java:225)
  at org.optaplanner.core.impl.localsearch.decider.LocalSearchDecider.doMove(Lorg/optaplanner/core/impl/localsearch/scope/LocalSearchMoveScope;)V (LocalSearchDecider.java:133)
  at org.optaplanner.core.impl.localsearch.decider.LocalSearchDecider.decideNextStep(Lorg/optaplanner/core/impl/localsearch/scope/LocalSearchStepScope;)V (LocalSearchDecider.java:117)
  at org.optaplanner.core.impl.localsearch.DefaultLocalSearchPhase.solve(Lorg/optaplanner/core/impl/solver/scope/SolverScope;)V (DefaultLocalSearchPhase.java:71)
  at org.optaplanner.core.impl.solver.AbstractSolver.runPhases(Lorg/optaplanner/core/impl/solver/scope/SolverScope;)V (AbstractSolver.java:99)
  at org.optaplanner.core.impl.solver.DefaultSolver.solve(Ljava/lang/Object;)Ljava/lang/Object; (DefaultSolver.java:163)
  at myCalculateClass.calculate
  at mySwingWorker$1.doInBackground()
  at javax.swing.SwingWorker$1.call()Ljava/lang/Object; (SwingWorker.java:304)
  at java.util.concurrent.FutureTask.run()V (FutureTask.java:264)
  at javax.swing.SwingWorker.run()V (SwingWorker.java:343)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Ljava/util/concurrent/ThreadPoolExecutor$Worker;)V (ThreadPoolExecutor.java:1128)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run()V (ThreadPoolExecutor.java:628)
  at java.lang.Thread.run()V (Thread.java:829)

共有1个答案

穆洋
2023-03-14

(在这里重复/扩展@hornisgrinde的评论,这样这个问题就有了一个明确的答案。)

运行mvn dependency:tree(或等效的gradle命令),确保所有optaplanner-*和drools-*版本同步。

在本例中,类路径包含optaplanner test 8.3.0和optaplanner core 8.7.0,我相信这会被optaplanner tests对optaplanner core的可传递依赖性所掩盖。为了完全避免这个问题,请使用optaplanner bom。

<project>
  ...
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.optaplanner</groupId>
        <artifactId>optaplanner-bom</artifactId>
        <type>pom</type>
        <version>8.8.0.Final</version>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.optaplanner</groupId>
      <artifactId>optaplanner-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.optaplanner</groupId>
      <artifactId>optaplanner-test</artifactId>
      <scope>test</scope>
    </dependency>
    ...
  </dependencies>
</project>
 类似资料:
  • 我的Optaplanner似乎出现了内存泄漏。要复制,只需下载Quarkus示例: 然后通过增加终止时间(例如,将)和取消注释表示的行来更改以启用多线程。 然后,运行手册中的请求: 内存使用量开始稳步增加,同时生成了数百万个PhreakPropagationContext对象。我认为这不是预期的行为。我应该为此制造问题还是遗漏了什么?

  • 我正面临Spring云侦探的问题,因为它正在泄漏内存,因为我已经通过了我的应用程序的转储: 13.05mb(40.3%)的Java静态组织。springframework。云侦探。仪器异步。侦探ContextListener。隐藏物 Spring云版:霍克斯顿。SR8 Spring Boot版本:2.3.3。释放 请在下面找到heapdump报告: https://heaphero.io/my-h

  • 问题内容: 我认为我的android应用正在泄漏内存。我不是绝对确定这是问题所在。 应用程序打开时经常崩溃,并且logcat尝试加载位图图像时会显示“内存不足”异常。 崩溃后,我重新打开了该应用程序,它运行正常。Logcat会显示许多“ gc”,并且JIT表会不时地向上调整大小,而不会向下调整,直到应用程序因内存不足错误而崩溃。 这听起来像是内存泄漏吗?如果是这样,我该如何定位和关闭泄漏点。 这是

  • 问题内容: 我一直在追寻内存泄漏(由“ valgrind –leak-check = yes”报告),它似乎来自ALSA。这段代码已经存在于自由世界中一段时间​​了,所以我猜这是我做错的事情。 输出看起来像这样: 并继续一些页面 这是由于我在一个项目中使用ALSA并开始看到这种巨大的泄漏……或者至少是所说泄漏的报告。 所以问题是:是我,ALSA或valgrind在这里遇到问题吗? 问题答案: ht

  • 问题内容: 我有一个长时间运行的脚本,如果让脚本运行足够长的时间,它将消耗系统上的所有内存。 在不详细介绍脚本的情况下,我有两个问题: 是否有可遵循的“最佳实践”,以防止泄漏发生? 有什么技术可以调试Python中的内存泄漏? 问题答案: 看看这篇文章:跟踪python内存泄漏 另外,请注意,垃圾收集模块实际上可以设置调试标志。看一下功能。此外,请查看Gnibbler的这段代码,以确定调用后已创建

  • 本文向大家介绍Java 内存泄漏,包括了Java 内存泄漏的使用技巧和注意事项,需要的朋友参考一下 在Java中,垃圾回收(析构函数的工作)是使用垃圾回收自动完成的。但是,如果代码中有引用它们的对象怎么办?它无法取消分配,即无法清除其内存。如果这种情况一再发生,并且创建或引用的对象根本没有被使用,它们就会变得无用。这就是所谓的内存泄漏。 如果超过了内存限制,则程序将通过抛出错误(即“ OutOfM