我有一个非常基本的 Spring boot 应用程序,它为一个非常简单的实体公开 CRUD Rest API。使用 JMeter 运行性能测试显示响应时间非常糟糕
Product (id, name, description)
约束: id PK 自动增量
设置:
公开 4 个 API 来执行以下功能
@Override
public Product findById(Integer id) {
return repository.findById(id)
.map(mapper::map)
.orElseThrow(() -> new RecordNotFoundException(1, "Product not found"));
}
@Transactional
@Override
public Product create(Product Product) {
ProductEntity entity = mapper.map(Product);
repository.save(entity);
return mapper.map(entity);
}
@Transactional
@Override
public Product update(Integer id, Product Product) {
ProductEntity entity = repository.findById(id).orElseThrow();
mapper.mapTo(entity, Product);
repository.save(entity);
return mapper.map(entity);
}
@Transactional
@Override
public void delete(Integer id) {
repository.deleteById(id);
}
我尝试用可视化虚拟机看看原因。看来存储库功能花费了太多时间。我认为是数据库导致了问题。
连接池设置:因为我没有设置任何内容并假设我的应用程序正在使用 HikariCP 并且默认大小为 100。
数据库: 对于上述结果,使用 MySQL(innodb 引擎)尝试并禁用了自动提交。
Spring Boot版本:2.4.0
系统: 16GB RAM,酷睿 i7
问题:
我对吗,连接池或数据库是这里的瓶颈,池大小的最佳值是多少,以减少响应时间?
为什么所有 API 在图表中都遵循相同的趋势 - 一起上升或下降?
更新:
您可以执行以下操作来查找问题:
1- 使用 Gattle 进行性能测试,它使用较低的资源并且不会影响您的结果。
2- 使用 APM 代理来准确监控耗时较长的过程,是数据库查询还是不是(APM)
3-使用 undertow 代替 tomcat 或其他 Web 应用程序