我想测量RestTemplate.getForObject调用的HTTP GET请求的时间,而不需要解析响应所需的时间.所以只是远程HTTP调用所需的时间.我已经尝试过设置ClientHttpRequestInterceptor,但我不认为这是正确的方法,因为时间似乎是错误的:
public class PerfRequestSyncInterceptor implements ClientHttpRequestInterceptor {
private Logger log = Logger.getLogger(this.getClass());
@Override
public ClientHttpResponse intercept(HttpRequest request,byte[] body,ClientHttpRequestExecution execution) throws IOException {
long start = System.nanoTime();
ClientHttpResponse resp = execution.execute(request,body);
log.debug("remote request time: "
+ ((System.nanoTime() - start) * Math.pow(10,-9)));
return resp;
}
}
呼叫:
RestTemplate rest = new RestTemplate();
List
如何衡量RestTemplate HTTP请求的时间?
最佳答案