当前位置:   article > 正文

Spring boot 系统出现请求卡顿缓慢排查解决方案

Spring boot 系统出现请求卡顿缓慢排查解决方案

系统出现请求卡顿缓慢,使用jstack,jmap,jstat都没查看到问题

写一个切面,切controller service dao mapper层,看是哪层出现问题,在具体排查

切面代码

  1. import org.aspectj.lang.ProceedingJoinPoint;
  2. import org.aspectj.lang.annotation.Around;
  3. import org.aspectj.lang.annotation.Aspect;
  4. import org.aspectj.lang.annotation.Pointcut;
  5. import org.aspectj.lang.reflect.MethodSignature;
  6. import org.slf4j.Logger;
  7. import org.slf4j.LoggerFactory;
  8. import org.springframework.stereotype.Component;
  9. import java.lang.reflect.Method;
  10. import java.util.Arrays;
  11. @Aspect
  12. @Component
  13. public class TimingAspect {
  14. private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
  15. @Pointcut("execution(* com.company..controller..*.*(..)) || " +
  16. "execution(* com.company..service..*.*(..)) || " +
  17. "execution(* com.company..mapper..*.*(..)) || " +
  18. "execution(* com.company..dao..*.*(..))")
  19. public void performancePointcut() {}
  20. @Around("performancePointcut()")
  21. public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
  22. long start = System.currentTimeMillis();
  23. Object result = joinPoint.proceed(); // 继续执行拦截的方法
  24. long finish = System.currentTimeMillis();
  25. MethodSignature signature = (MethodSignature) joinPoint.getSignature();
  26. Method method = signature.getMethod();
  27. String methodName = joinPoint.getSignature().toString();
  28. String className = joinPoint.getTarget().getClass().getName();
  29. LOGGER.info("执行类" + className + " 执行方法:"+methodName + "请求参数"+Arrays.toString(joinPoint.getArgs()) +" 方法耗时:" + (finish - start) + "ms");
  30. return result;
  31. }
  32. }

查看日志,配合jstack线程栈 看哪个方法最耗时长。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小舞很执着/article/detail/953605
推荐阅读
相关标签
  

闽ICP备14008679号