java - 基于 Java 的 rest api 的性能测量

标签 java spring performance-testing

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

这里的性能可以分为两种。

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

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

#2 的更多信息

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

我想知道花了多少时间

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

谢谢

最佳答案

对于请求-响应性能测试,您可以使用 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

关于java - 基于 Java 的 rest api 的性能测量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33735912/

相关文章:

java - 在不同的数据库上复制修改后的数据

gpu - 替代 nvidia-smi 来测量 GPU 利用率?

java - getCurrentSession 给出 No Session Bound to Context,openSession 则没有

java - 是否可以在运行时禁用 `-XX:+PrintCompilation` 和 `-verbose:gc"`?

c# - 有什么办法可以改善 TCP 连接时间吗?

java - 为什么会出现模式不匹配的情况?

java - Pojo 到 DTO - Bean 映射

java - Sqlite 数据库未使用 java 更新

java - Spring Autowiring 跨多个层失败

java - Weblogic (12.2.1.3.0) 的 NoSuchBeanDefinitionException :No qualifying bean of type [weblogic. messages.saf.internal.SAFServerService]