在应用程序服务器中运行Micro-benchmark [JMH]

时间:2015-03-09 06:53:28

标签: java jboss microbenchmark jmh

我阅读了JMH并尝试了提供的样本。

我要做的是衡量以下情景的统计数据,

  

[1]客户订单 - > [2]服务器 - > [3]开始处理订单 - >   [4]成功处理订单并准备发送 - > [5]客户   收到回复

我可以成功完成[1]到[5]场景。在那里,我使用benchmark.jar

从@Benchmark注释方法调用我的客户端

现在我不得不测量从[2]到[4]的统计数据,它代表服务器端处理。我应该通过注释服务器端方法来做到这一点吗?如果是这样,我如何以获得基准统计数据的方式调用这些方法?

文档说The recommended way to run a JMH benchmark is to use Maven to setup a standalone project that depends on the jar files of your application.这是否意味着我尝试的场景无法使用JMH?

更新: 有没有办法通过rmi调用调用@Benchmark注释方法?

2 个答案:

答案 0 :(得分:2)

@Benchmark Javadoc说:

 * <p>{@link Benchmark} demarcates the benchmark payload, and JMH treats it specifically
 * as the wrapper which contains the benchmark code. In order to run the benchmark reliably,
 * JMH enforces a few stringent properties for these wrapper methods, including, but not
 * limited to:</p>

@Benchmark是划分JMH应该视为基准体的代码片段的注释。 是一个神奇的注释,可以测量程序中其他地方的任何给定方法。并且,您不应该自己调用@Benchmark方法。

您想要的不是基准,它是一种跟踪/监控/分析解决方案,可以检测和记录请求通过的所有阶段。 JMH不是这样的解决方案,你应该去别处看看。

答案 1 :(得分:1)

您可以使用石墨等监控工具作为用例。