gpt4 book ai didi

com.netflix.loadbalancer.ZoneAffinityServerListFilter类的使用及代码示例

转载 作者:知者 更新时间:2024-03-20 09:40:31 24 4
gpt4 key购买 nike

本文整理了Java中com.netflix.loadbalancer.ZoneAffinityServerListFilter类的一些代码示例,展示了ZoneAffinityServerListFilter类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneAffinityServerListFilter类的具体详情如下:
包路径:com.netflix.loadbalancer.ZoneAffinityServerListFilter
类名称: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);
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com