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

打印 上一主题 下一主题

主题 1018|帖子 1018|积分 3054

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
系统出现请求卡顿迟钝,使用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线程栈 看哪个方法最耗时长。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

滴水恩情

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表