有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java我正在努力提高Springboot+MyBatis中API的性能,仅用于Select查询

我想将API响应时间的性能提高到1秒以内。目前遭受了更多的延迟,需要20秒

我的控制器调用服务,在服务中,我使用不同的SQL select语句调用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中进行分解,那么我将在几个不同的Select查询中结束

我使用的方法

  • 在Java中使用“CompletableFuture”并行触发查询
  • 数据库端查询&;infra调优(应用SQL数据库哈希)
  • 应用索引

应用索引

在这种情况下,我仍然可以采用哪些最佳方法来提高吞吐量


共 (0) 个答案