当前位置:网站首页>Summary of actual business optimization scheme - main directory - continuous update

Summary of actual business optimization scheme - main directory - continuous update

2022-04-23 18:36:00 Yin Zhen GRD_ Zhipeng

Summarize the interesting problems encountered in the work , And corresponding solutions . Encountered a record .
The business is big , There are often inexplicable problems . For example, good plug-ins , Somehow it doesn't work . You cannot change the business code at this time , Or modify a little , We have to solve the problem .

One 、Mybatis Climb a pit

1. mybatis-plus Auto fill failure 、 The paging plug-in does not pass down the interception chain

The question is shown in the title ,mybatis Auto fill does not take effect , Using the paging plug-in, it is found that the plug-in does not pass down the interception chain .

Solution

  1. Choose to use Mybatis-plus Pagination plug-in for , Meet the requirements of passing down the interception chain .
  2. imitation MyBatis-plus Auto fill using , Custom auto fill plug-in . solve Mybatis-plus Auto fill is sometimes valid and sometimes invalid .
For reasons of length , Put it in this article :https://blog.csdn.net/grd_java/article/details/124349094

2. Use Spring AOP monitor mapper execution time

The company lets you optimize the query of the report ( A query is said to be close to 20s, An interface 15 Seconds will time out , So the worst thing is to let the query in 15s within ), These reports have a large amount of data ,IO A lot , A query involves dozens of sql and IO

So you want to optimize , You have to know which operations are more time-consuming , Direct use AOP It's a good choice , Print every... Accurately IO Time for , To optimize
 Insert picture description here

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/** * 2022-04-14===>>>yinzhipeng *  Used to get mapper execution time  */
@Component
@Aspect
@Slf4j
public class MapperExecutionTimeAspect {
    
    @Pointcut("execution(* cn.xxx.mapper.*.*(..))")
    public void pointcut() {
    
    }
    @Around("pointcut()")
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
    
        long begin = System.nanoTime();
        Object obj = pjp.proceed();
        long end = System.nanoTime();

        log.info(" call Mapper Method : Execution time consuming :{} nanosecond , Time consuming :{} millisecond ,{}, Parameters :{}",
                (end - begin), (end - begin) / 1000000,
                pjp.getSignature().toString(), Arrays.toString(pjp.getArgs()));
        return obj;
    }

}

Two 、 Query optimization

1. A lot of mapper IO Optimize

When querying large reports , also sql Without much optimization space , How to improve efficiency ?

  1. That is to say, now IO Too much , But there's no way , Business really needs so much IO
  2. Single IO Efficiency optimization of , There is not much room for optimization , That is, optimize sql Our plan is not desirable
  3. So the question is how to make these IO Can you hurry up

In general, this is the case , You can consider multithreading , And large reports generally do not need to consider high concurrency . So write everything directly into the method , Not defined in a class , There's no thread safety issue . Because there is no high concurrency , There is no need to consider the problem of stack overflow ( Each thread execution will have a , Thread private , Life cycle is the same as thread , yes Java The thread memory model of method execution , When each method is executed ,Java All virtual machines will create a stack frame synchronously (Stack Frame) Used to store local variables 、 The stack of operands 、 Dynamic connection 、 Method exit information )

For reasons of length , Put it in this article :https://blog.csdn.net/grd_java/article/details/124348962

版权声明
本文为[Yin Zhen GRD_ Zhipeng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231833296538.html