- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中com.netflix.loadbalancer.ZoneAwareLoadBalancer
类的一些代码示例,展示了ZoneAwareLoadBalancer
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneAwareLoadBalancer
类的具体详情如下:
包路径:com.netflix.loadbalancer.ZoneAwareLoadBalancer
类名称:ZoneAwareLoadBalancer
[英]Load balancer that can avoid a zone as a whole when choosing server.
The key metric used to measure the zone condition is Average Active Requests, which is aggregated per rest client per zone. It is the total outstanding requests in a zone divided by number of available targeted instances (excluding circuit breaker tripped instances). This metric is very effective when timeout occurs slowly on a bad zone.
The LoadBalancer will calculate and examine zone stats of all available zones. If the Average Active Requests for any zone has reached a configured threshold, this zone will be dropped from the active server list. In case more than one zone has reached the threshold, the zone with the most active requests per server will be dropped. Once the the worst zone is dropped, a zone will be chosen among the rest with the probability proportional to its number of instances. A server will be returned from the chosen zone with a given Rule (A Rule is a load balancing strategy, for example AvailabilityFilteringRule) For each request, the steps above will be repeated. That is to say, each zone related load balancing decisions are made at real time with the up-to-date statistics aiding the choice.
[中]在选择服务器时可以避免整个区域的负载平衡器。
用于衡量区域状况的关键指标是平均活动请求数,即每个rest客户端和每个区域的平均活动请求数。它是一个区域中未完成的请求总数除以可用的目标实例数(不包括断路器跳闸实例)。当超时在坏区缓慢发生时,此指标非常有效。
LoadBalancer将计算并检查所有可用区域的区域统计信息。如果任何区域的平均活动请求已达到配置的阈值,则该区域将从活动服务器列表中删除。如果有多个区域达到阈值,则每个服务器上具有最活跃请求的区域将被丢弃。一旦最差的区域被删除,将在其余区域中选择一个区域,其概率与其实例数成正比。对于每个请求,将使用给定的规则(规则是一种负载平衡策略,例如AvailabilityFilteringRule)从所选区域返回服务器,并重复上述步骤。也就是说,每个区域相关的负载平衡决策都是实时做出的,最新的统计数据有助于做出选择。
代码示例来源:origin: yu199195/hmily
@Override
public Server chooseServer(final Object key) {
List<Server> serverList;
serverList = super.getServerListImpl().getUpdatedListOfServers();
serverList = super.getFilter().getFilteredListOfServers(serverList);
if (null == serverList || serverList.isEmpty() || serverList.size() == 1) {
return super.chooseServer(key);
}
final Server server = super.chooseServer(key);
final HmilyTransactionContext hmilyTransactionContext = HmilyTransactionContextLocal.getInstance().get();
if (Objects.isNull(hmilyTransactionContext)) {
return server;
}
final String transId = hmilyTransactionContext.getTransId();
//if try
if (hmilyTransactionContext.getAction() == HmilyActionEnum.TRYING.getCode()) {
SERVER_MAP.put(transId, server);
return server;
}
final Server oldServer = SERVER_MAP.get(transId);
SERVER_MAP.remove(transId);
if (Objects.nonNull(oldServer)) {
for (Server s : serverList) {
if (Objects.equals(s, oldServer)) {
return oldServer;
}
}
}
return server;
}
代码示例来源:origin: Nepxion/Discovery
@Bean
public ILoadBalancer ribbonLoadBalancer(IClientConfig config, ServerList<Server> serverList, ServerListFilter<Server> serverListFilter, IRule rule, IPing ping, ServerListUpdater serverListUpdater) {
if (this.propertiesFactory.isSet(ILoadBalancer.class, serviceId)) {
return this.propertiesFactory.get(ILoadBalancer.class, config, serviceId);
}
ZoneAwareLoadBalancer<?> loadBalancer = new ZoneAwareLoadBalancer<>(config, rule, ping, serverList, serverListFilter, serverListUpdater);
loadBalanceListenerExecutor.setLoadBalancer(loadBalancer);
return loadBalancer;
}
}
代码示例来源:origin: com.netflix.ribbon/ribbon-loadbalancer
@VisibleForTesting
BaseLoadBalancer getLoadBalancer(String zone) {
zone = zone.toLowerCase();
BaseLoadBalancer loadBalancer = balancers.get(zone);
if (loadBalancer == null) {
// We need to create rule object for load balancer for each zone
IRule rule = cloneRule(this.getRule());
loadBalancer = new BaseLoadBalancer(this.getName() + "_" + zone, rule, this.getLoadBalancerStats());
BaseLoadBalancer prev = balancers.putIfAbsent(zone, loadBalancer);
if (prev != null) {
loadBalancer = prev;
}
}
return loadBalancer;
}
代码示例来源:origin: spring-cloud/spring-cloud-core-tests
/**
* Throws exception if the SpringClientFactory doesn't return a balancer with a server
* list of the expected type.
*
*/
@PostConstruct
public void test() throws Exception {
@SuppressWarnings("unchecked")
ZoneAwareLoadBalancer<Server> lb = (ZoneAwareLoadBalancer<Server>) this.clientFactory.getLoadBalancer("baz");
ServerList<Server> serverList = lb.getServerListImpl();
if (!(serverList instanceof MyDefaultRibbonConfig.BazServiceList)) {
throw new Exception("wrong server list type");
}
}
代码示例来源:origin: smoketurner/dropwizard-consul
/**
* Fetch a server from the load balancer or throw an exception if none are available.
*
* @return a server
* @throws IllegalStateException if no servers are available
*/
private Server fetchServerOrThrow() {
final Server server = loadBalancer.chooseServer();
if (server == null) {
throw new IllegalStateException("No available servers for " + loadBalancer.getName());
}
return server;
}
代码示例来源:origin: com.netflix.ribbon/ribbon-loadbalancer
@Override
public Server chooseServer(Object key) {
if (!ENABLED.get() || getLoadBalancerStats().getAvailableZones().size() <= 1) {
logger.debug("Zone aware logic disabled or there is only one zone");
return super.chooseServer(key);
LoadBalancerStats lbStats = getLoadBalancerStats();
Map<String, ZoneSnapshot> zoneSnapshot = ZoneAvoidanceRule.createSnapshot(lbStats);
logger.debug("Zone snapshots: {}", zoneSnapshot);
if (triggeringLoad == null) {
triggeringLoad = DynamicPropertyFactory.getInstance().getDoubleProperty(
"ZoneAwareNIWSDiscoveryLoadBalancer." + this.getName() + ".triggeringLoadPerServerThreshold", 0.2d);
"ZoneAwareNIWSDiscoveryLoadBalancer." + this.getName() + ".avoidZoneWithBlackoutPercetage", 0.99999d);
logger.debug("Zone chosen: {}", zone);
if (zone != null) {
BaseLoadBalancer zoneLoadBalancer = getLoadBalancer(zone);
server = zoneLoadBalancer.chooseServer(key);
代码示例来源:origin: com.netflix.ribbon/ribbon-loadbalancer
@Override
public void setRule(IRule rule) {
super.setRule(rule);
if (balancers != null) {
for (String zone: balancers.keySet()) {
balancers.get(zone).setRule(cloneRule(rule));
}
}
}
}
代码示例来源:origin: com.netflix.ribbon/ribbon-loadbalancer
private IRule cloneRule(IRule toClone) {
IRule rule;
if (toClone == null) {
rule = new AvailabilityFilteringRule();
} else {
String ruleClass = toClone.getClass().getName();
try {
rule = (IRule) ClientFactory.instantiateInstanceWithClientConfig(ruleClass, this.getClientConfig());
} catch (Exception e) {
throw new RuntimeException("Unexpected exception creating rule for ZoneAwareLoadBalancer", e);
}
}
return rule;
}
代码示例来源:origin: org.springframework.cloud/spring-cloud-netflix-ribbon
@Bean
@ConditionalOnMissingBean
public ILoadBalancer ribbonLoadBalancer(IClientConfig config,
ServerList<Server> serverList, ServerListFilter<Server> serverListFilter,
IRule rule, IPing ping, ServerListUpdater serverListUpdater) {
if (this.propertiesFactory.isSet(ILoadBalancer.class, name)) {
return this.propertiesFactory.get(ILoadBalancer.class, config, name);
}
return new ZoneAwareLoadBalancer<>(config, rule, ping, serverList,
serverListFilter, serverListUpdater);
}
代码示例来源:origin: liaokailin/springcloud
@RequestMapping("/")
public void getServerList() throws Exception {
ZoneAwareLoadBalancer<Server> lb = (ZoneAwareLoadBalancer<Server>) clientFactory.getLoadBalancer("myclient");
ServerList<Server> serverList = lb.getServerListImpl();
List<Server> serverDetailList = serverList.getInitialListOfServers();
if (!CollectionUtils.isEmpty(serverDetailList)) {
for (Server s : serverDetailList) {
System.out.println(s.getHost() + "," + s.getPort());
}
} else {
System.out.println("no service");
}
}
代码示例来源:origin: com.netflix.ribbon/ribbon-loadbalancer
/**
* Build a {@link ZoneAwareLoadBalancer} with a dynamic {@link ServerList} and an {@link IRule}. The {@link ServerList} can be
* either set in the {@link #withDynamicServerList(ServerList)} or in the {@link IClientConfig} using {@link CommonClientConfigKey#NIWSServerListClassName}.
* The {@link IRule} can be either set by {@link #withRule(IRule)} or in the {@link IClientConfig} using
* {@link CommonClientConfigKey#NFLoadBalancerRuleClassName}.
*/
public ZoneAwareLoadBalancer<T> buildDynamicServerListLoadBalancer() {
if (serverListImpl == null) {
serverListImpl = createServerListFromConfig(config);
}
if (rule == null) {
rule = createRuleFromConfig(config);
}
return new ZoneAwareLoadBalancer<T>(config, rule, ping, serverListImpl, serverListFilter);
}
代码示例来源:origin: com.netflix.ribbon/ribbon-loadbalancer
/**
* Build a {@link ZoneAwareLoadBalancer} with a dynamic {@link ServerList} and an {@link IRule} and a {@link ServerListUpdater}.
*
* The {@link ServerList} can be either set in the {@link #withDynamicServerList(ServerList)} or in the {@link IClientConfig}
* using {@link CommonClientConfigKey#NIWSServerListClassName}.
* The {@link IRule} can be either set by {@link #withRule(IRule)} or in the {@link IClientConfig} using
* {@link CommonClientConfigKey#NFLoadBalancerRuleClassName}.
* The {@link ServerListUpdater} can be either set by {@link #withServerListUpdater(ServerListUpdater)} or
* in the {@link IClientConfig} using {@link CommonClientConfigKey#ServerListUpdaterClassName}.
*/
public ZoneAwareLoadBalancer<T> buildDynamicServerListLoadBalancerWithUpdater() {
if (serverListImpl == null) {
serverListImpl = createServerListFromConfig(config);
}
if (rule == null) {
rule = createRuleFromConfig(config);
}
if (serverListUpdater == null) {
serverListUpdater = createServerListUpdaterFromConfig(config);
}
return new ZoneAwareLoadBalancer<T>(config, rule, ping, serverListImpl, serverListFilter, serverListUpdater);
}
代码示例来源:origin: org.apache.camel/camel-ribbon
private ZoneAwareLoadBalancer<RibbonServiceDefinition> createLoadBalancer(String serviceName) {
// setup client config
IClientConfig config = configuration.getClientName() != null
? IClientConfig.Builder.newBuilder(configuration.getClientName()).build()
: IClientConfig.Builder.newBuilder().build();
if (configuration.getProperties() != null) {
for (Map.Entry<String, String> entry : configuration.getProperties().entrySet()) {
IClientConfigKey key = CommonClientConfigKey.valueOf(entry.getKey());
String value = entry.getValue();
LOGGER.debug("RibbonClientConfig: {}={}", key.key(), value);
config.set(key, value);
}
}
ZoneAwareLoadBalancer<RibbonServiceDefinition> loadBalancer;
if (serviceDiscovery != null) {
loadBalancer = new ZoneAwareLoadBalancer<>(
config,
configuration.getRuleOrDefault(RoundRobinRule::new),
configuration.getPingOrDefault(DummyPing::new),
new RibbonServerList(serviceName, serviceDiscovery, serviceFilter),
null,
new PollingServerListUpdater(config));
} else {
loadBalancer = new ZoneAwareLoadBalancer<>(config);
}
return loadBalancer;
}
Nginx默认支持'Round Robin'负载平衡,如果我将kubernetes服务类型设置为'LoadBalancer'(我认为这是服务提供商的network-LB?如this),那不会在堆栈中形
本文整理了Java中com.netflix.loadbalancer.ZoneAwareLoadBalancer类的一些代码示例,展示了ZoneAwareLoadBalancer类的具体用法。这些代码
本文整理了Java中com.netflix.loadbalancer.ZoneAvoidanceRule类的一些代码示例,展示了ZoneAvoidanceRule类的具体用法。这些代码示例主要来源于G
本文整理了Java中com.netflix.loadbalancer.ZoneAffinityServerListFilter类的一些代码示例,展示了ZoneAffinityServerListFil
我有一个 clusterIP 类型的 k8s 服务..我需要通过 CLI 更改以下配置 http 端口到 https 端口 端口号 负载均衡器的类型 有没有办法做到这一点..? 最佳答案 您无法删除现
我正在尝试使用 python/paramiko 将 SFTP 服务器部署到 AKS 中。 这已成功部署到裸机开发服务器中,但是我在将其部署到 AKS 中时遇到问题。 问题在创建 LoadBalance
我有 6 个 Pod,每个 Pod 应用程序从不同的端口监听,每个 Pod 都有自己的 IP 地址。 我有 Kubernetes LoadBalancer 服务 (Azure LoadBalancer
我有一项使用 Azure Kubernetes 群集和 AKS 负载均衡器的服务。我想将一些 HTTP(客户端)请求转发到所有实例。一般来说,有什么方法可以使用 AKS 或 Kubernetes 配置
Kubernetes 同时拥有 Ingress (在服务前面)和服务类型: LoadBalancer .这些似乎做相同的事情:允许公共(public)流量进入与服务选择器匹配的 pod。各自的优点和缺
我有一项使用 Azure Kubernetes 群集和 AKS 负载均衡器的服务。我想将一些 HTTP(客户端)请求转发到所有实例。一般来说,有什么方法可以使用 AKS 或 Kubernetes 配置
我有一个关于使用 Spring-Cloud Netflix 进行客户端负载平衡的问题。 启用负载平衡后,Ribbon 将选择要调用的服务器。选择规则取决于被选择的 IRule 实现。 以下实现之间有什
更新: 我编辑了我的问题,使其更加关注问题。 上下文 编写代码以了解负载平衡的工作原理。Debian 64 位。 127.0.0.1:36001 上的负载均衡器后端位于 127.0.0.1:36000
我正在尝试学习如何将 Kibernetes 与 Minikube 一起使用,并具有以下部署和服务: --- kind: Service apiVersion: v1 metadata: name:
apiVersion: v1 kind: Service metadata: name: nginx labels: name: nginx spec: ports: #
我用 nginx-ingress-controller:0.24.1 (Inspired by) 我想将 DNS A 记录设置为 LB IP 地址,以便将其连接到根中具有公共(public) inde
我有一个配置为 LoadBalancer 的服务,在运行 1.9.11 的五节点集群上运行。 LoadBalancer 位于运行 ASP.NET Core Web 应用程序的三个 pod 前面(该应用
我刚刚开始使用 Kubernetes,我对 NodePort 和 LoadBalancer 类型的服务之间的区别感到困惑。 我理解的区别是 LoadBalancer 不支持 UDP,但除此之外,每当我
我正在尝试在 Azure AKS 中部署 ftp 服务器镜像。为了向公众公开服务器,我添加了一个 LoadBalancer 类型的服务。 apiVersion: v1 kind: Service me
我在负载均衡器 (F5) 后面运行 2 个 OAuth2 授权服务器实例。我正在使用 JdbcTokenStore。一切工作正常,但有时我会收到错误“处理错误:InvalidGrantExceptio
我使用 Helm 图表在我的测试集群上安装了 Spinnaker。当我尝试创建 LoadBalancer 时,我注意到对话框中的“命名空间”下拉列表是空白的。当我刚刚尝试创建负载均衡器时,我看到错误“
我是一名优秀的程序员,十分优秀!