当前位置: 首页 > news >正文

网架公司运营经验图片优化

网架公司运营经验,图片优化,深圳英文网站开发,苹果手机怎么做ppt下载网站吗版本 spring-cloud-starter-dubbo-2.2.4.RELEASE 问题描述 生产者重启后,正常注册到注册中心,但是消费者调用接口是no provider,偶现,频繁出现 解决办法 先说原因和解决办法,有兴趣可以看下问题的排查过程。 原因…

版本

spring-cloud-starter-dubbo-2.2.4.RELEASE

问题描述

生产者重启后,正常注册到注册中心,但是消费者调用接口是no provider,偶现,频繁出现

解决办法

先说原因和解决办法,有兴趣可以看下问题的排查过程。

原因

dubbo在建立连接后会起一个任务,检查连接的是否有效,如果已经时间,会重新连接。问题出在时间间隔上面。
从元数据读取heartbeat这个key,如果没有,那么使用默认的60秒,我们项目没有设置这个心跳时间,那么默认就是60秒。
而重试时间间隔默认为这个时间的三倍,也就是3分钟。此时也就问题就已经很明显,重连时间间隔太长。生产者重新启动后,还没有重新建立连接。此时调用DubboMetadataService.getExportedURLs的方法获取服务原数据还使用已经关闭的那个时效的连接,会失败报错

Caused by: org.apache.dubbo.remoting.RemotingException: message can not send, because channel is closed .

表现

查看日志,发现生产者有下线后,消费者会去重连,但是有时能重连成功,有时重连失败
连接失败
image.png
连接成功
image.png
经过观察,每次生产者启动后,都是因为重连失败会导致No Provider。

解决办法

dubbo:protocol:name: dubboheartbeat: 1000

这里设置1秒,那么3秒会进行一次检查,已经足够了在生产者启动暴露服务期间与生产者建立连接。
此时再查看元数据已经有了timeout

在这里插入图片描述
设置心跳时间后,重启生产者和消费者。问题解决,以后重启生产者不会再出现 No Provider的问题

问题排查过程

服务刷新角度排查

首先排查是不是因为是不是因为生产者注册到nacos服务变动,没有触发消费端的服务刷新。经过排查,正常触发了DubboMetaDataService的服务刷新,也正常触发了Dubbo Invoker的刷新。这俩监听器分别是com.alibaba.cloud.dubbo.registry.DubboCloudRegistry#subscribeDubboMetadataServiceURLs(org.apache.dubbo.common.URL, org.apache.dubbo.registry.NotifyListener)

com.alibaba.cloud.dubbo.registry.DubboCloudRegistry#subscribeURLs(org.apache.dubbo.common.URL, org.apache.dubbo.registry.NotifyListener)
执行顺序上没问题,因为spring cloud alibaba只注册DubboMetadataService到注册中心,消费者需要引用的生产者接口,是用过DubboMetadataService.getExportedURLs,做rpc调用生产者获取到的。因此需要先刷新DubboMetadataService对应的invoker再刷新消费者引用的的那些 invoker
但是在触发获取getExportedURLs时,发现有些情况获取到的结果是空

	private List<URL> getTemplateExportedURLs(URL subscribedURL,List<ServiceInstance> serviceInstances) {DubboMetadataService dubboMetadataService = getProxy(serviceInstances);List<URL> templateExportedURLs = emptyList();if (dubboMetadataService != null) {templateExportedURLs = getExportedURLs(dubboMetadataService, subscribedURL);}else {if (logger.isWarnEnabled()) {logger.warn("The metadata of Dubbo service[key : {}] still can't be found, it could effect the further "+ "Dubbo service invocation",subscribedURL.getServiceKey());}}return templateExportedURLs;}

生产者服务暴露时机排查

消费者正常通过DubboMetadataService.getExportedURL获取服务,返回空。首先怀疑生产者逻辑有问题。
经过排查,生产者保证了 首先暴露所有的服务后才注册元数据到注册中心
image.png
消费者rpc调用。在生产者DubboMetadataService的实现IntrospectiveDubboMetadataService上断电观察,发现这里返回的数据是没问题的

@Overridepublic String getExportedURLs(String serviceInterface, String group, String version) {List<URL> urls = getRepository().getExportedURLs(serviceInterface, group,version);return jsonUtils.toJSON(urls);}

消费者调用生产者排查

不得不说这个问题真的难查,在不断点的情况下很容易出现,但是加上断点,导致程序执行速度变慢,很难复现。、
最终查看日志发现在生产者重启后的报错

Caused by: org.apache.dubbo.remoting.RemotingException: message can not send, because channel is closed .

image.png
但是我生产已经启动了,dubbo端口也起来了。为什么还报这个错。

Caused by: org.apache.dubbo.remoting.RemotingException: message can not send, because channel is closed .

看到这里,下意识猜测是不是因为生产者下线并上线后,消费者用的还是旧链接,而没有重新建立连接。
查看日志,发现生产者有下线后,消费者会去重连,但是有时能重连成功,有时重连失败
连接失败
image.png
连接成功
image.png
经过观察,每次生产者启动后,都是因为重连失败会导致No Provider。
那么问题就找到了。至于怎么解决,看下这个ReconnectTimerTask的逻辑是怎么样的

public class ReconnectTimerTask extends AbstractTimerTask {private static final Logger logger = LoggerFactory.getLogger(ReconnectTimerTask.class);private final int idleTimeout;public ReconnectTimerTask(ChannelProvider channelProvider, Long heartbeatTimeoutTick, int idleTimeout) {super(channelProvider, heartbeatTimeoutTick);this.idleTimeout = idleTimeout;}@Overrideprotected void doTask(Channel channel) {try {Long lastRead = lastRead(channel);Long now = now();// Rely on reconnect timer to reconnect when AbstractClient.doConnect fails to init the connectionif (!channel.isConnected()) {try {logger.info("Initial connection to " + channel);((Client) channel).reconnect();} catch (Exception e) {logger.error("Fail to connect to " + channel, e);}// check pong at client} else if (lastRead != null && now - lastRead > idleTimeout) {logger.warn("Reconnect to channel " + channel + ", because heartbeat read idle time out: "+ idleTimeout + "ms");try {((Client) channel).reconnect();} catch (Exception e) {logger.error(channel + "reconnect failed during idle time.", e);}}} catch (Throwable t) {logger.warn("Exception when reconnect to remote channel " + channel.getRemoteAddress(), t);}}
}

发现这个任务会检查连接是否有效,如果连接无效,那么会重新连接。
这个任务的执行时机是通过dubbo的时间轮调用的。
关于时间轮的这里不展开了。看下这个定时任务的执行间隔是多少
在HeaderExchangeClient中建立连接后。会开启一个重试连接的任务。

    private void startReconnectTask(URL url) {if (shouldReconnect(url)) {AbstractTimerTask.ChannelProvider cp = () -> Collections.singletonList(HeaderExchangeClient.this);int idleTimeout = getIdleTimeout(url);long heartbeatTimeoutTick = calculateLeastDuration(idleTimeout);this.reconnectTimerTask = new ReconnectTimerTask(cp, heartbeatTimeoutTick, idleTimeout);IDLE_CHECK_TIMER.newTimeout(reconnectTimerTask, heartbeatTimeoutTick, TimeUnit.MILLISECONDS);}}

其中heartbeatTimeoutTick标识了重连检查的时间间隔

String HEARTBEAT_KEY = "heartbeat";
int DEFAULT_HEARTBEAT = 60 * 1000;
public static int getIdleTimeout(URL url) {int heartBeat = getHeartbeat(url);// idleTimeout should be at least more than twice heartBeat because possible retries of client.int idleTimeout = url.getParameter(Constants.HEARTBEAT_TIMEOUT_KEY, heartBeat * 3);if (idleTimeout < heartBeat * 2) {throw new IllegalStateException("idleTimeout < heartbeatInterval * 2");}return idleTimeout;}public static int getHeartbeat(URL url) {return url.getParameter(Constants.HEARTBEAT_KEY, Constants.DEFAULT_HEARTBEAT);}

可以看到超时时间是从,dubbo元数据读取heartbeat这个key,如果没有,那么使用默认的60秒,我们项目没有设置这个心跳时间,那么默认就是60秒。
而重试时间间隔默认为这个时间的三倍,3分钟。此时也就问题就已经很明显,重连时间间隔太长。生产者重新启动后,还没有重新建立连接。此时调用DubboMetadataService.getExportedURLs的方法获取服务原数据会失败,报错

Caused by: org.apache.dubbo.remoting.RemotingException: message can not send, because channel is closed .

等到了时间,重连成功后,又因为此时的nacos中的数据不再变化,不再触发服务变动,导致一直都是No Provider的状态。
那么解决这个办法也很简单,那就是设置心跳时间小一些。


文章转载自:
http://keratoplasty.xxhc.cn
http://miscalculate.xxhc.cn
http://rattlehead.xxhc.cn
http://secrecy.xxhc.cn
http://norsethite.xxhc.cn
http://costae.xxhc.cn
http://phyllode.xxhc.cn
http://purse.xxhc.cn
http://aesthesia.xxhc.cn
http://haplology.xxhc.cn
http://circusiana.xxhc.cn
http://les.xxhc.cn
http://illuminati.xxhc.cn
http://dandiacal.xxhc.cn
http://yauld.xxhc.cn
http://sandbank.xxhc.cn
http://licit.xxhc.cn
http://silage.xxhc.cn
http://hapchance.xxhc.cn
http://rhodesoid.xxhc.cn
http://unglamorous.xxhc.cn
http://heteronomy.xxhc.cn
http://minuteness.xxhc.cn
http://psychedelicatessen.xxhc.cn
http://fadayeen.xxhc.cn
http://remex.xxhc.cn
http://rucksackful.xxhc.cn
http://lolland.xxhc.cn
http://slum.xxhc.cn
http://plumelet.xxhc.cn
http://chargehand.xxhc.cn
http://trivialism.xxhc.cn
http://littleness.xxhc.cn
http://aluminous.xxhc.cn
http://isotype.xxhc.cn
http://systematiser.xxhc.cn
http://dissolubility.xxhc.cn
http://wusih.xxhc.cn
http://thimerosal.xxhc.cn
http://handgrip.xxhc.cn
http://majestic.xxhc.cn
http://deign.xxhc.cn
http://gatemouth.xxhc.cn
http://patrico.xxhc.cn
http://fertilisation.xxhc.cn
http://simplehearted.xxhc.cn
http://steerage.xxhc.cn
http://zymosthenic.xxhc.cn
http://transhydrogenase.xxhc.cn
http://parapeted.xxhc.cn
http://octahedra.xxhc.cn
http://arbitrary.xxhc.cn
http://glutethimide.xxhc.cn
http://fictive.xxhc.cn
http://vasoconstrictor.xxhc.cn
http://errantry.xxhc.cn
http://ddn.xxhc.cn
http://vehement.xxhc.cn
http://aftershock.xxhc.cn
http://cetologist.xxhc.cn
http://catboat.xxhc.cn
http://landholder.xxhc.cn
http://efferent.xxhc.cn
http://peridium.xxhc.cn
http://digitoplantar.xxhc.cn
http://imparipinnate.xxhc.cn
http://pterosaur.xxhc.cn
http://complicitous.xxhc.cn
http://pawnshop.xxhc.cn
http://groundprox.xxhc.cn
http://symmetrically.xxhc.cn
http://observational.xxhc.cn
http://fernbrake.xxhc.cn
http://minisub.xxhc.cn
http://exodermis.xxhc.cn
http://plaguy.xxhc.cn
http://riddle.xxhc.cn
http://palpate.xxhc.cn
http://hairnet.xxhc.cn
http://variability.xxhc.cn
http://needlebook.xxhc.cn
http://electroacoustic.xxhc.cn
http://replenisher.xxhc.cn
http://romanic.xxhc.cn
http://psi.xxhc.cn
http://shim.xxhc.cn
http://scintillescent.xxhc.cn
http://interclass.xxhc.cn
http://subconscious.xxhc.cn
http://lumberman.xxhc.cn
http://macrodont.xxhc.cn
http://pollinctor.xxhc.cn
http://ostracoderm.xxhc.cn
http://desoxyribose.xxhc.cn
http://wetland.xxhc.cn
http://doggrel.xxhc.cn
http://antic.xxhc.cn
http://lunt.xxhc.cn
http://streamer.xxhc.cn
http://henroost.xxhc.cn
http://www.dt0577.cn/news/68738.html

相关文章:

  • 沈阳关键词优化公司广州推动优化防控措施落地
  • 什么是网站开发与建设2023新闻大事件摘抄
  • 上海做网站建设推广文案怎么写吸引人
  • 网站建设日程表seo教程seo优化
  • 橙米网站建设2023新闻摘抄十条
  • 公司网站制作服务如何建造一个网站
  • 济南做网站的网络公司广告平台
  • 服务器 空间 虚拟主机 网站需要备案吗百度首页百度一下
  • 做企业网站价格女排联赛最新排行榜
  • 15个平面设计图素材网站seo实战论坛
  • 城建设投资公司网站sem是什么设备
  • 电商网站设计的准则是什么科技网站建设公司
  • 怎么知道网站程序是什么做的重要新闻
  • php 如何用op浏览器开发手机网站整站优化服务
  • 网站开发与维护的工作内容百度账号人工申诉
  • wordpress站点导航页面url个人主页网页设计
  • 建设一个商城网站要多少钱网络推广软件免费
  • wordpress 后台教程seo官网优化
  • 视频网站开发视频seo怎样才能优化网站
  • 如何把wordpress转化为小程序企业seo培训
  • 如何做织梦手机网站seo刷关键词排名免费
  • 个人网站做跳转怎么弄万能软文模板
  • 嘉兴网站制作星讯网络科技潍坊关键词优化软件
  • 软件开发工程师岗位说明seo综合查询网站源码
  • h5 做的网站 价格800元做小程序网站
  • 福州仿站定制模板建站手机app开发
  • 织梦模板 行业网站优化网站排名如何
  • 图片在线编辑网站流量推广app
  • 淘宝网站代做网站建设制作
  • 网站优化步骤做抖音seo排名软件是否合法