3

请教一个使用 RestTemplete 调用服务周期性卡顿的问题

 2 years ago
source link: https://www.v2ex.com/t/838954
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

请教一个使用 RestTemplete 调用服务周期性卡顿的问题

  BlackZhu · 19 小时 17 分钟前 · 283 次点击

背景:项目使用 spring nacos+RestTemplete

现象:服务之间调用偶发响应时间 10s(上下几十毫秒波动)

目前定位到的问题:接口之间通信是没问题的,在执行到下面两行代码时

response = request.execute();

handleResponse(url, method, response);

打断点后发现 response 已经有返回值,问题出在 handleResponse 方法里面,在获取 response 的 responseCode 时,会调用 HttpURLConnection.getResponseCode()方法,方法内会调用 getInputStream()检查连接是否可用,该方法由 synchronized 修饰

走到这一步发现 nacos 的 beat 方法也会一直调用到 HttpURLConnection.getResponseCode()方法,所以猜测可能是偶发性 nacos 占用了锁导致调用服务的线程一直阻塞,并且 10s 也符合 RestTemplete 默认的最大等待时间

目前不知道怎么进行下去解决问题了,希望大家能指点迷津!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK