How can I find the response time of a HTTP request through a Socket

前端 未结 7 1520
猫巷女王i
猫巷女王i 2021-02-07 04:13

I\'m using a Java socket, connected to a server. If I send a HEADER http request, how can I measure the response time from the server? Must I use a provided java timer, or is t

7条回答
  •  既然无缘
    2021-02-07 04:33

    @Aspect
    @Profile("performance")
    @Component
    public class MethodsExecutionPerformance {
        private final Logger logger = LoggerFactory.getLogger(getClass());
    
        @Pointcut("execution(* it.test.microservice.myService.service.*.*(..))")
        public void serviceMethods() {
        }
    
        @Around("serviceMethods()")
        public Object monitorPerformance(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
            StopWatch stopWatch = new StopWatch(getClass().getName());
            stopWatch.start();
            Object output = proceedingJoinPoint.proceed();
            stopWatch.stop();
            logger.info("Method execution time\n{}", stopWatch.prettyPrint());
            return output;
        }
    }
    

    In this way, you can calculate the real response time of your service independent of network speed.

提交回复
热议问题