我有大量的宏基准测试使用不同的执行引擎(其中一些是高度多线程的)来测量各种模拟的执行时间。这些作业中的大多数使用我在抽象基类中指定的 jmh 设置:
@ContextConfiguration(value = AbstractJobExecutorBenchmarker.CONTEXT_LOCATION)
@State(Scope.Benchmark)
@Fork(1)
@BenchmarkMode(Mode.SingleShotTime)
@Warmup(iterations = 1, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 5, timeUnit = TimeUnit.MILLISECONDS)
public abstract class AbstractJobExecutorBenchmarker extends AbstractTestNGSpringContextTests
(我还将 -gc -si false 添加到命令行)
当我触发这些基准中的任何一个或一些小子集时,它都可以正常工作。但是,如果我尝试一次性运行所有这些(即没有过滤选项),jmh 成功地完成了其中的几个,然后在一个特定的基准测试后突然冻结......完成了它的首字母,打印了最终结果,但是它看起来分叉的 JVM 没有被杀死并且新的没有启动,似乎整个过程都被卡住了。打印的最后一条语句的示例:
Iteration 3: 03:59:52.059 [pool-8-thread-1] INFO MessageTrafficController: Starting MessageTrafficController
03:59:52.059 [pool-8-thread-3] INFO MessageTrafficController: Starting MessageTrafficController
03:59:52.060 [pool-8-thread-5] INFO MessageTrafficController: Starting MessageTrafficController
03:59:52.060 [pool-8-thread-6] INFO MessageTrafficController: Starting MessageTrafficController
03:59:52.061 [pool-8-thread-7] INFO MessageTrafficController: Starting MessageTrafficController
03:59:52.061 [pool-8-thread-8] INFO MessageTrafficController: Starting MessageTrafficController
03:59:52.061 [pool-8-thread-9] INFO MessageTrafficController: Starting MessageTrafficController
03:59:52.061 [pool-8-thread-10] INFO MessageTrafficController: Starting MessageTrafficController
03:59:52.062 [pool-8-thread-13] INFO MessageTrafficController: Starting MessageTrafficController
03:59:52.062 [pool-8-thread-14] INFO MessageTrafficController: Starting MessageTrafficController
03:59:52.063 [pool-8-thread-15] INFO MessageTrafficController: Starting MessageTrafficController
03:59:52.063 [pool-8-thread-18] INFO MessageTrafficController: Starting MessageTrafficController
03:59:52.063 [pool-8-thread-19] INFO MessageTrafficController: Starting MessageTrafficController
03:59:52.064 [pool-8-thread-20] INFO MessageTrafficController: Starting MessageTrafficController
03:59:52.064 [pool-8-thread-22] INFO MessageTrafficController: Starting MessageTrafficController
03:59:52.065 [pool-8-thread-25] INFO MessageTrafficController: Starting MessageTrafficController
04:00:57.600 [pool-8-thread-6] WARN MessageTrafficController: Stopped due to class java.lang.InterruptedException
04:00:57.601 [pool-8-thread-7] WARN MessageTrafficController: Stopped due to class java.lang.InterruptedException
04:00:57.604 [pool-8-thread-13] WARN MessageTrafficController: Stopped due to class java.lang.InterruptedException
04:00:57.604 [pool-8-thread-10] WARN MessageTrafficController: Stopped due to class java.lang.InterruptedException
04:00:57.603 [pool-8-thread-8] WARN MessageTrafficController: Stopped due to class java.lang.InterruptedException
04:00:57.604 [pool-8-thread-9] WARN MessageTrafficController: Stopped due to class java.lang.InterruptedException
04:00:57.606 [pool-8-thread-22] WARN MessageTrafficController: Stopped due to class java.lang.InterruptedException
04:00:57.608 [pool-8-thread-25] WARN MessageTrafficController: Stopped due to class java.lang.InterruptedException
04:00:57.606 [pool-8-thread-20] WARN MessageTrafficController: Stopped due to class java.lang.InterruptedException
04:00:57.605 [pool-8-thread-15] WARN MessageTrafficController: Stopped due to class java.lang.InterruptedException
04:00:57.606 [pool-8-thread-19] WARN MessageTrafficController: Stopped due to class java.lang.InterruptedException
04:00:57.606 [pool-8-thread-18] WARN MessageTrafficController: Stopped due to class java.lang.InterruptedException
04:00:57.604 [pool-8-thread-14] WARN MessageTrafficController: Stopped due to class java.lang.InterruptedException
65598.920 ms
Result : 76749.529 Âą(99.9%) 804946.698 ms
Statistics: (min, avg, max) = (39272.712, 76749.529, 125376.954), stdev = 44121.845
Confidence interval (99.9%): [-728197.169, 881696.226]
如果我手动杀死分叉的 JVM,整个过程就会解除阻塞。然而,在完成下一个基准测试后,它再次陷入困境......任何想法为什么会发生?为什么当我分别启动相同的基准测试时它不会发生?
另外,JMH 中是否有一些超时选项,所以如果正常关闭时间过长,它会强制终止分叉进程?