java - 我正在尝试仅针对 Select 查询提高 Springboot + MyBatis 中 API 的性能
问题描述
我想将 API 响应时间的性能提高到 1 秒以内。目前正在遭受更多的延迟,至少需要 20 秒。
我的控制器调用服务,在服务中我使用不同的 SQL 选择语句调用 4-5 个方法。
服务等级
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.springframework.beans.factory.annotation.Autowired;
public class APIService {
@Autowired
private Repo1 repo1;
@Autowired
private Repo2 repo2;
@Autowired
private Repo3 repo3;
@Autowired
private Repo3 repo4;
public void extractData(String input1, String input2) {
try {
DataBinder binder = repo1.getDetails(input1, input2);
CompletableFuture<Options> ooptions = null;
ooptions = repo2.getInfo(binder.getVal1());
CompletableFuture<List<Management>> mgmntObj = null;
mgmntObj = repo3.getMngmt(binder.getVal1());
CompletableFuture<List<Premise>> premiObj = null;
premiObj = repo4.getPremise(binder.getVal1());
CompletableFuture.allOf(ooptions, mgmntObj, premiObj).join();
} catch (Exception e) {
e.printStackTrace();
}
}
}
这是从存储过程到 Java 代码的代码分解,作为业务需求。尽管存储过程在 1 秒内运行良好。存储过程的优点是单个块中有多个子查询。如果我想用 Java 分解,那么我最终会遇到几个不同的选择查询。
我使用过的方法
- 在 Java 中使用“CompletableFuture”并行触发查询。
- 数据库端查询和基础设施调整(应用 SQL 数据库散列)。
- 应用索引。
应用索引。
在这种情况下,我可以提高吞吐量的最佳方法是什么?
解决方案
推荐阅读
- mysql - InnoDB:错误意味着另一个程序正在使用 InnoDB 的文件。在 MYSQL 错误日志中获取操作系统错误 32
- anaconda - 在没有 MKL 的情况下为 AMD Ryzen 设置 Anaconda
- ansible - 如何在 Ansible Tower 中为单个作业模板使用多个凭据?
- python - 根据 Python 3.x 文本文件中存储的文件名将文件复制到新目录
- highcharts - 需要并排放置两个堆栈图,共享单个配置设置
- mysql - 如果我检查日期 2019-01-12 是否在 12 月到 1 月的日期范围内,查询会给出空结果
- python - 如何使用 MATPLOTLIB 保持数字阈值
- r - ggplot 错误:“名称”属性 [2] 必须与向量 [1] 的长度相同
- c++ - ffmpeg 减少内存消耗
- java - Hibernate - 将两个实体分组