当前位置:网站首页>Loadbalancer dynamically refreshes Nacos server
Loadbalancer dynamically refreshes Nacos server
2022-07-02 08:40:00 【kq1983】
DynamicServerListLoadBalancer
public DynamicServerListLoadBalancer(IClientConfig clientConfig, IRule rule, IPing ping,
ServerList<T> serverList, ServerListFilter<T> filter,
ServerListUpdater serverListUpdater) {
super(clientConfig, rule, ping);
this.serverListImpl = serverList;
this.filter = filter;
this.serverListUpdater = serverListUpdater;
if (filter instanceof AbstractServerListFilter) {
((AbstractServerListFilter) filter).setLoadBalancerStats(getLoadBalancerStats());
}
restOfInit(clientConfig); //
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
void restOfInit(IClientConfig clientConfig) {
boolean primeConnection = this.isEnablePrimingConnections();
// turn this off to avoid duplicated asynchronous priming done in BaseLoadBalancer.setServerList()
this.setEnablePrimingConnections(false);
enableAndInitLearnNewServersFeature(); // serverListUpdater.start(updateAction);
updateListOfServers();
if (primeConnection && this.getPrimeConnections() != null) {
this.getPrimeConnections()
.primeConnections(getReachableServers());
}
this.setEnablePrimingConnections(primeConnection);
LOGGER.info("DynamicServerListLoadBalancer for client {} initialized: {}", clientConfig.getClientName(), this.toString());
}
/**
* Feature that lets us add new instances (from AMIs) to the list of
* existing servers that the LB will use Call this method if you want this
* feature enabled
*/
public void enableAndInitLearnNewServersFeature() {
LOGGER.info("Using serverListUpdater {}", serverListUpdater.getClass().getSimpleName());
serverListUpdater.start(updateAction); // Start calling updateAction
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
UpdateAction
protected final ServerListUpdater.UpdateAction updateAction = new ServerListUpdater.UpdateAction() {
@Override
public void doUpdate() {
updateListOfServers();
}
};
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
updateListOfServers
public void updateListOfServers() {
List<T> servers = new ArrayList<T>();
if (serverListImpl != null) { // NacosServerList
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);
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
ServerListUpdater
PollingServerListUpdater
PollingServerListUpdater.start
private static long LISTOFSERVERS_CACHE_UPDATE_DELAY = 1000; // msecs;
private static int LISTOFSERVERS_CACHE_REPEAT_INTERVAL = 30 * 1000; // msecs;
@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 {
// DynamicServerListLoadBalancer.doUpdate()
updateAction.doUpdate(); // updateListOfServers()
lastUpdated = System.currentTimeMillis();
} catch (Exception e) {
logger.warn("Failed one update cycle", e);
}
}
};
scheduledFuture = getRefreshExecutor().scheduleWithFixedDelay(
wrapperRunnable,
initialDelayMs, // 1s
refreshIntervalMs, // 30s
TimeUnit.MILLISECONDS
);
// Every time 30s perform 1 Time
} else {
logger.info("Already active, no-op");
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
边栏推荐
- [blackmail virus data recovery] suffix Hydra blackmail virus
- Deep understanding of JVM
- Tcp/ip - transport layer
- Data asset management function
- OpenShift构建镜像
- Openfeign is easy to use
- 用数字 5,5,5,1 ,进行四则运算,每个数字当且仅当用一次,要求运算结果值为 24
- D interface and domain problems
- Routing foundation - dynamic routing
- How to build the alliance chain? How much is the development of the alliance chain
猜你喜欢
C language custom type enumeration, Union (clever use of enumeration, calculation of union size)
链表经典面试题(反转链表,中间节点,倒数第k个节点,合并分割链表,删除重复节点)
Solid principle: explanation and examples
Flex layout
Kubedm deploys kubernetes v1.23.5 cluster
Kubesphere virtualization KSV installation experience
Generate database documents with one click, which can be called swagger in the database industry
Getting started with k8s: building MySQL with Helm
双向链表的实现(双向链表与单向链表的简单区别联系和实现)
Tcp/ip - transport layer
随机推荐
2022 Heilongjiang's latest eight member (Safety Officer) simulated test question bank and answers
Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
D interface and domain problems
CarSim learning experience - rough translation 1
HCIA—数据链路层
The best blog to explain the basics of compilation (share)
实现双向链表(带傀儡节点)
Comparable,Comparator,Clonable 接口使用剖析
方法递归(斐波那契数列,青蛙跳台阶,汉诺塔问题)
Live broadcast platform development, flexible menu, and freely adjust the horizontal size of the menu bar
STM32-新建工程(参考正点原子)
Shortcut key to comment code and cancel code in idea
Call Stack
Viewing JS array through V8
Flex layout
Nacos 下载启动、配置 MySQL 数据库
Openshift deployment application
W10 is upgraded to W11 system, but the screen is black, but the mouse and desktop shortcuts can be used. How to solve it
Programmer training, crazy job hunting, overtime ridiculed by colleagues deserve it
Qunhui NAS configuring iSCSI storage