博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ribbon的ServerListRefreshInterval
阅读量:6897 次
发布时间:2019-06-27

本文共 4127 字,大约阅读时间需要 13 分钟。

ribbon有个参数可以用来调整刷新server list的时间间隔参数。

ServerListRefreshInterval

ribbon-core-2.2.0-sources.jar!/com/netflix/client/config/CommonClientConfigKey.java

public static final IClientConfigKey
ServerListRefreshInterval = new CommonClientConfigKey
("ServerListRefreshInterval"){};

PollingServerListUpdater

ribbon-loadbalancer-2.2.0-sources.jar!/com/netflix/loadbalancer/PollingServerListUpdater.java

private static long getRefreshIntervalMs(IClientConfig clientConfig) {        return clientConfig.get(CommonClientConfigKey.ServerListRefreshInterval, LISTOFSERVERS_CACHE_REPEAT_INTERVAL);    }        @Override    public synchronized void start(final UpdateAction updateAction) {        if (isActive.compareAndSet(false, true)) {            final Runnable wrapperRunnable = new Runnable() {                @Override                public void run() {                    if (!isActive.get()) {                        if (scheduledFuture != null) {                            scheduledFuture.cancel(true);                        }                        return;                    }                    try {                        updateAction.doUpdate();                        lastUpdated = System.currentTimeMillis();                    } catch (Exception e) {                        logger.warn("Failed one update cycle", e);                    }                }            };            scheduledFuture = getRefreshExecutor().scheduleWithFixedDelay(                    wrapperRunnable,                    initialDelayMs,                    refreshIntervalMs,                    TimeUnit.MILLISECONDS            );        } else {            logger.info("Already active, no-op");        }    }

DynamicServerListLoadBalancer

ribbon-loadbalancer-2.2.0-sources.jar!/com/netflix/loadbalancer/DynamicServerListLoadBalancer.java

protected final ServerListUpdater.UpdateAction updateAction = new ServerListUpdater.UpdateAction() {        @Override        public void doUpdate() {            updateListOfServers();        }    };@VisibleForTesting    public void updateListOfServers() {        List
servers = new ArrayList
(); if (serverListImpl != null) { servers = serverListImpl.getUpdatedListOfServers(); LOGGER.debug("List of Servers for {} obtained from Discovery client: {}", getIdentifier(), servers); if (filter != null) { servers = filter.getFilteredListOfServers(servers); LOGGER.debug("Filtered List of Servers for {} obtained from Discovery client: {}", getIdentifier(), servers); } } updateAllServerList(servers); }/** * Update the AllServer list in the LoadBalancer if necessary and enabled * * @param ls */ protected void updateAllServerList(List
ls) { // other threads might be doing this - in which case, we pass if (serverListUpdateInProgress.compareAndSet(false, true)) { for (T s : ls) { s.setAlive(true); // set so that clients can start using these // servers right away instead // of having to wait out the ping cycle. } setServersList(ls); super.forceQuickPing(); serverListUpdateInProgress.set(false); } }

这里设置list的时候,顺带调用了forceQuickPing()方法

BaseLoadBalancer#forceQuickPing

ribbon-loadbalancer-2.2.0-sources.jar!/com/netflix/loadbalancer/BaseLoadBalancer.java

/*     * Force an immediate ping, if we're not currently pinging and don't have a     * quick-ping already scheduled.     */    public void forceQuickPing() {        if (canSkipPing()) {            return;        }        if (logger.isDebugEnabled()) {            logger.debug("LoadBalancer:  forceQuickPing invoked");        }        Pinger ping = new Pinger(pingStrategy);        try {            ping.runPinger();        } catch (Throwable t) {            logger.error("Throwable caught while running forceQuickPing() for "                    + name, t);        }    }

转载地址:http://xbcdl.baihongyu.com/

你可能感兴趣的文章
7.Spring Boot配置文件application.yml
查看>>
计算学校周次,亲测成功!
查看>>
jQuery插件
查看>>
数字3为分隔
查看>>
华章11-12月份新书简介(2017年)
查看>>
第三周作业
查看>>
Vector、ArrayList、List使用深入剖析
查看>>
【调试】Core Dump是什么?Linux下如何正确永久开启?
查看>>
新浪微博API授权
查看>>
电子政务网中信息共享机制的重要性
查看>>
【Visual C++】游戏开发笔记十四 游戏画面绘图(四) 华丽的CImage类
查看>>
Struts2的配置
查看>>
[BZOJ1296][SCOI2009]粉刷匠(DP)
查看>>
Executor执行框架
查看>>
[FMX] Android APP 启动黑屏优化补丁
查看>>
常用JavaScript的高级技巧
查看>>
bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘
查看>>
mac编辑器vim美化
查看>>
MD5摘要算法简析
查看>>
《30天自制操作系统》学习笔记一
查看>>