5

JPA 并发查询同一条数据时的效率问题

 2 years ago
source link: https://www.v2ex.com/t/836450
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Java

JPA 并发查询同一条数据时的效率问题

  joooooker21 · 1 天前 · 606 次点击
    public RespData findOrderTest(@RequestParam String orderCode,@RequestParam String strategy) {
        TbOrder tbOrder = orderDao.findByOrderCodeAndStrategy(orderCode, strategy);
        
        //do something
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return RespData.success(tbOrder);
    }

使用 jmeter 并发调用,查询条件不变,反复查询同一条数据,发现查询速率变慢

正常耗时日志

    `---[5054.53776ms] cn.*.PatientAppController:findOrderTest()
        +---[54.165884ms] cn.*.TbOrderDao:findByOrderCodeAndStrategy() #349
        +---[0.079756ms] javax.persistence.EntityManager:clear() #350
        `---[0.018264ms] cn.*.RespData:buildSuccess() #363

测试期间接口耗时逐渐增加,异常耗时日志

    `---[29406.81247ms] cn.*.PatientAppController:findOrderTest()
        +---[24406.507885ms] cn.*.TbOrderDao:findByOrderCodeAndStrategy() #349
        +---[0.036484ms] javax.persistence.EntityManager:clear() #350
        `---[0.020533ms] cn.*.RespData:buildSuccess() #363

已排除是数据库性能问题,怀疑是 jpa 内部的实现机制所致,多番测试还是没有找到问题,分享出来给大家看看,请大佬指教


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK