java - 如何在 Spring Boot 中调试 REST 调用的性能问题
问题描述
Spring 框架的优点和缺点在于注释背后发生了很多神奇的事情。我已经构建了一个我认为公平的东西vanilla REST api
,它使GET、PUT 和 POST都在同一个上URL
。当调用PUT
or调用时,在我从Postman发送查询到控制器方法获得控制权之间POST
有一个严重的时间(8 到 10 秒)。然而,呼叫几乎是瞬间的。在调用控制器方法之前,我需要一种方法来追踪魔术以查看性能瓶颈在哪里。如何调试此代码?delay
GET
spring
@RequestMapping(value = "/{collection}/branches", method = RequestMethod.GET)
public ResponseEntity<CollectionApi<BranchApi>> getBranches(@PathVariable String collection,
@RequestParam(defaultValue = ModelsController.DEF_OFFSET) Long _offset,
@RequestParam(defaultValue = ModelsController.DEF_LIMIT) Integer _limit,
@RequestParam(required = false) String rep,
@RequestParam(defaultValue = ModelsController.DEF_SYNC) Integer _sync) {
try {
CollectionApi<BranchApi> branches = branchesService.getBranches(collection);
if (branches == null) {
throw new NotFoundException("Collection not found");
}
return ResponseEntity.ok(branches);
} catch (NucleusModelingException e) {
throw new BadRequestException(e.getLocalizedMessage(), e);
}
}
@RequestMapping(value = "/{collection}/branches", method = RequestMethod.PUT)
public ResponseEntity<CollectionApi<BranchApi>> setActiveBranch(
@PathVariable String collection,
@RequestParam String branch) {
try {
CollectionApi<BranchApi> branches = branchesService.setActiveBranch(collection, branch);
return ResponseEntity.ok(branches);
} catch (NucleusModelingException e) {
throw new BadRequestException(e.getLocalizedMessage(),e);
}
}
@RequestMapping(value = "/{collection}/branches", method = RequestMethod.POST)
public ResponseEntity<CollectionApi<BranchApi>> createBranch(
@PathVariable String collection,
@RequestParam String branch) {
try {
CollectionApi<BranchApi> branches = branchesService.checkoutBranch(collection, branch);
return ResponseEntity.status(HttpStatus.CREATED).body(branches);
} catch (NucleusModelingException e) {
throw new BadRequestException(e.getLocalizedMessage(),e);
}
}
解决方案
推荐阅读
- laravel - 如何在 laravel 运行时设置或更改全局变量值
- node.js - 当 npm audit fix / update / shrinkwrap 手动更改不起作用时,如何更新 node-sass 的嵌套包 ansi-regex?
- python - RuntimeWarning: 在 cosh -- Python 中遇到溢出。这是什么意思?
- angular - 在嵌套事件处理程序中传递参数
- php - 来自 php Curl 的 FCM 请求永远存在
- firebase - 如何在 List 小部件 Flutter 中无上下文导航
- python - 尝试并在它下面不打印线 python
- python-3.x - Django SAML2 idp saml2.response.IncorrectlySigned 内部服务器错误:/idp/login/process/
- database - Sqlite> 未出现在 Git Bash 终端中
- regex - 无法解析多行正则表达式模式