本文整理了Java中com.netflix.loadbalancer.ZoneAffinityServerListFilter
类的一些代码示例,展示了ZoneAffinityServerListFilter
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneAffinityServerListFilter
类的具体详情如下:
包路径:com.netflix.loadbalancer.ZoneAffinityServerListFilter
类名称:ZoneAffinityServerListFilter
[英]This server list filter deals with filtering out servers based on the Zone affinity. This filtering will be turned on if either CommonClientConfigKey#EnableZoneAffinity or CommonClientConfigKey#EnableZoneExclusivity is set to true in IClientConfig object passed into this class during initialization. When turned on, servers outside the same zone (as indicated by Server#getZone()) will be filtered out. By default, zone affinity and exclusivity are turned off and nothing is filtered out.
[中]此服务器列表筛选器用于根据区域关联筛选出服务器。如果在初始化期间传递到此类的IClientConfig对象中将CommonClientConfigKey#EnableZoneAffinity或CommonClientConfigKey#EnableZoneExclusivity设置为true,则将打开此筛选。打开时,同一区域外的服务器(如服务器#getZone()所示)将被过滤掉。默认情况下,区域亲缘关系和排他性处于关闭状态,不过滤任何内容。
代码示例来源:origin: org.springframework.cloud/spring-cloud-netflix-ribbon
@Override
public List<Server> getFilteredListOfServers(List<Server> servers) {
List<Server> output = super.getFilteredListOfServers(servers);
if (this.zone != null && output.size() == servers.size()) {
List<Server> local = new ArrayList<>();
for (Server server : output) {
if (this.zone.equalsIgnoreCase(server.getZone())) {
local.add(server);
}
}
if (!local.isEmpty()) {
return local;
}
}
return output;
}
代码示例来源:origin: com.netflix.ribbon/ribbon-loadbalancer
public ZoneAffinityServerListFilter(IClientConfig niwsClientConfig) {
initWithNiwsConfig(niwsClientConfig);
}
代码示例来源:origin: com.netflix.ribbon/ribbon-loadbalancer
@Override
public List<T> getFilteredListOfServers(List<T> servers) {
if (zone != null && (zoneAffinity || zoneExclusive) && servers !=null && servers.size() > 0){
List<T> filteredServers = Lists.newArrayList(Iterables.filter(
servers, this.zoneAffinityPredicate.getServerOnlyPredicate()));
if (shouldEnableZoneAffinity(filteredServers)) {
return filteredServers;
} else if (zoneAffinity) {
overrideCounter.increment();
}
}
return servers;
}
代码示例来源:origin: com.netflix.ribbon/ribbon-loadbalancer
private boolean shouldEnableZoneAffinity(List<T> filtered) {
if (!zoneAffinity && !zoneExclusive) {
return false;
}
if (zoneExclusive) {
return true;
}
LoadBalancerStats stats = getLoadBalancerStats();
if (stats == null) {
return zoneAffinity;
} else {
logger.debug("Determining if zone affinity should be enabled with given server list: {}", filtered);
ZoneSnapshot snapshot = stats.getZoneSnapshot(filtered);
double loadPerServer = snapshot.getLoadPerServer();
int instanceCount = snapshot.getInstanceCount();
int circuitBreakerTrippedCount = snapshot.getCircuitTrippedCount();
if (((double) circuitBreakerTrippedCount) / instanceCount >= blackOutServerPercentageThreshold.get()
|| loadPerServer >= activeReqeustsPerServerThreshold.get()
|| (instanceCount - circuitBreakerTrippedCount) < availableServersThreshold.get()) {
logger.debug("zoneAffinity is overriden. blackOutServerPercentage: {}, activeReqeustsPerServer: {}, availableServers: {}",
new Object[] {(double) circuitBreakerTrippedCount / instanceCount, loadPerServer, instanceCount - circuitBreakerTrippedCount});
return false;
} else {
return true;
}
}
}
代码示例来源:origin: nutzam/nutzboot
public Object getLoadBalancer(String name, FeignInject fc) {
EurekaClient eurekaClient = ioc.get(EurekaClient.class, "eurekaClient");
DefaultClientConfigImpl clientConfig = DefaultClientConfigImpl.getClientConfigWithDefaultValues(name);
ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList(name, ()->eurekaClient);
ServerListFilter<DiscoveryEnabledServer> filter = new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(clientConfig);
ServerListUpdater updater = new EurekaNotificationServerListUpdater(()->eurekaClient);
IRule rule = null;
switch (getLbRuleString(fc.lbRule())) {
case "random":
rule = new RandomRule();
break;
case "availability":
default:
AvailabilityFilteringRule _rule = new AvailabilityFilteringRule();
_rule.initWithNiwsConfig(clientConfig);
rule = _rule;
break;
}
ZoneAwareLoadBalancer<DiscoveryEnabledServer> lb = LoadBalancerBuilder.<DiscoveryEnabledServer>newBuilder()
.withDynamicServerList(list)
.withRule(rule)
.withServerListFilter(filter)
.withServerListUpdater(updater)
.withClientConfig(clientConfig)
.buildDynamicServerListLoadBalancerWithUpdater();
return LBClient.create(lb, clientConfig);
}
}
代码示例来源:origin: org.springframework.cloud/spring-cloud-netflix-ribbon
@Override
public void initWithNiwsConfig(IClientConfig niwsClientConfig) {
super.initWithNiwsConfig(niwsClientConfig);
if (ConfigurationManager.getDeploymentContext() != null) {
this.zone = ConfigurationManager.getDeploymentContext().getValue(
ContextKey.zone);
}
}
代码示例来源:origin: com.netflix.ribbon/ribbon-loadbalancer
List<T> zoneAffinityFiltered = super.getFilteredListOfServers(servers);
Set<T> candidates = Sets.newHashSet(zoneAffinityFiltered);
Set<T> newSubSet = Sets.newHashSet(currentSubset);
代码示例来源:origin: com.netflix.ribbon/ribbon-loadbalancer
@Override
public void initWithNiwsConfig(IClientConfig clientConfig) {
super.initWithNiwsConfig(clientConfig);
sizeProp = new DynamicIntProperty(clientConfig.getClientName() + "." + clientConfig.getNameSpace() + ".ServerListSubsetFilter.size", 20);
eliminationPercent =
new DynamicFloatProperty(clientConfig.getClientName() + "." + clientConfig.getNameSpace() + ".ServerListSubsetFilter.forceEliminatePercent", 0.1f);
eliminationFailureCountThreshold = new DynamicIntProperty( clientConfig.getClientName() + "." + clientConfig.getNameSpace()
+ ".ServerListSubsetFilter.eliminationFailureThresold", 0);
eliminationConnectionCountThreshold = new DynamicIntProperty(clientConfig.getClientName() + "." + clientConfig.getNameSpace()
+ ".ServerListSubsetFilter.eliminationConnectionThresold", 0);
}
内容来源于网络,如有侵权,请联系作者删除!