首页 > 解决方案 > 我正在尝试仅针对 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 分解,那么我最终会遇到几个不同的选择查询。

我使用过的方法

应用索引。

在这种情况下,我可以提高吞吐量的最佳方法是什么?

标签: javaspringperformancemybatis

解决方案


推荐阅读