当前位置:网站首页>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.
边栏推荐
- HackTheBox-Gunship
- Googlenet network explanation and model building
- Web security -- Logical ultra vires
- [blackmail virus data recovery] suffix Rook3 blackmail virus
- Causes of laptop jam
- OpenShift 部署应用
- Global and Chinese market of electric cheese grinder 2022-2028: Research Report on technology, participants, trends, market size and share
- 顺序表基本功能函数的实现
- What are the platforms for selling green label domain names? What is the green label domain name like?
- HCIA - data link layer
猜你喜欢

kubeadm部署kubernetes v1.23.5集群

Method recursion (Fibonacci sequence, frog jumping steps, tower of Hanoi problem)

OpenShift构建镜像

File upload Labs

Implementation of bidirectional linked list (simple difference, connection and implementation between bidirectional linked list and unidirectional linked list)

When a custom exception encounters reflection

C language custom type enumeration, Union (clever use of enumeration, calculation of union size)

2022 Heilongjiang latest construction eight members (materialman) simulated examination questions and answers
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]

Linux二进制安装Oracle Database 19c
随机推荐
How to apply for a secondary domain name?
Pclpy projection filter -- projection of point cloud to cylinder
OpenShift 容器平台社区版 OKD 4.10.0部署
Qunhui NAS configuring iSCSI storage
KubeSphere 虚拟化 KSV 安装体验
Smart agriculture solutions smart agriculture system development
kubeadm部署kubernetes v1.23.5集群
sqli-labs第2关
Openshift deployment application
HackTheBox-Gunship
cve_ 2019_ 0708_ bluekeep_ Rce vulnerability recurrence
W10 is upgraded to W11 system, but the screen is black, but the mouse and desktop shortcuts can be used. How to solve it
Short video with goods source code, double-click to zoom in when watching the video
旋转链表(图解说明)
sqli-labs(POST类型注入)
Sqli labs Level 2
Force deduction method summary: find classes
Makefile Fundamentals
web安全--逻辑越权
Programmer training, crazy job hunting, overtime ridiculed by colleagues deserve it