【问题标题】:Performance measurement for Java based rest api基于 Java 的 rest api 的性能测量
【发布时间】:2016-02-17 13:59:19
【问题描述】:

我编写了一个基于 Java 的 rest API 项目。我想测试 API 的性能。

这里的表现可以分为两种。

  1. 请求响应时间。
  2. 实际代码执行时间。

我知道如何测试或测量 #1,但我不确定如何测量 #2。

#2 的更多信息

假设我有一个映射到休息端点的方法。

我想知道花了多少时间

  1. 将数据解析为方法参数
  2. 执行方法中的代码
  3. 将响应转换回 JSON 所花费的时间

谢谢

【问题讨论】:

标签: java spring performance-testing


【解决方案1】:

对于请求-响应性能测试,您可以使用 SoapUI 或 Jmeter:

http://www.soapui.org/rest-testing/getting-started.html

对于代码执行时间,“分析”是最好的选择,因为它不需要修改代码,但对于非专家用户来说可能很难。

https://visualvm.java.net/

一种老式的方式,修改代码是记录(使用 Log4j 或类似的)方法的执行时间:

long startT = System.nanoTime();
//Code you want to measure
long endT = System.nanoTime();

long executionTime = (endT - startT);  //divide by 1000000 to get millisecs.
//Log this in specific category and level, so you can turn it on/off depending on your needs

【讨论】:

    【解决方案2】:

    对于您的性能测试,我建议使用 JMeter (http://jmeter.apache.org/),如果您怀疑存在瓶颈,我建议您使用 jprof (http://perfinsp.sourceforge.net/jprof.html) 之类的工具创建 java 配置文件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-29
      • 2016-04-25
      • 2016-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-27
      • 1970-01-01
      相关资源
      最近更新 更多