com.netflix.loadbalancer.LoadBalancerStats Java Examples
The following examples show how to use
com.netflix.loadbalancer.LoadBalancerStats.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestSessionSticknessRule.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@Test public void testRuleFullOperation() { SessionStickinessRule rule = new SessionStickinessRule(); LoadBalancer mockedLb = mock(LoadBalancer.class); Transport transport = mock(Transport.class); MicroserviceInstance instance1 = new MicroserviceInstance(); instance1.setInstanceId("1234"); ServiceCombServer mockedServer = new ServiceCombServer(transport, new CacheEndpoint("rest:127.0.0.1:8889", instance1)); Invocation invocation = mock(Invocation.class); LoadBalancerStats stats = mock(LoadBalancerStats.class); Mockito.when(mockedLb.getLoadBalancerStats()).thenReturn(stats); Deencapsulation.invoke(rule, "chooseServerWhenTimeout", Arrays.asList(mockedServer), invocation); mockedServer.setAlive(true); mockedServer.setReadyToServe(true); List<ServiceCombServer> allServers = Arrays.asList(mockedServer); rule.setLoadBalancer(mockedLb); Server s = rule.choose(allServers, invocation); Assert.assertEquals(s, mockedServer); s = rule.choose(allServers, invocation); Assert.assertEquals(s, mockedServer); }
Example #2
Source File: SessionStickinessRule.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
private boolean isErrorThresholdMet() { LoadBalancerStats stats = loadBalancer.getLoadBalancerStats(); if (stats != null && stats.getServerStats() != null && stats.getServerStats().size() > 0) { ServerStats serverStats = stats.getSingleServerStat(lastServer); int successiveFaildCount = serverStats.getSuccessiveConnectionFailureCount(); if (Configuration.INSTANCE.getSuccessiveFailedTimes(microserviceName) > 0 && successiveFaildCount >= Configuration.INSTANCE.getSuccessiveFailedTimes(microserviceName)) { serverStats.clearSuccessiveConnectionFailureCount(); return true; } } return false; }
Example #3
Source File: LoadBalancer.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
public LoadBalancer(RuleExt rule, String microServiceName) { this.microServiceName = microServiceName; this.rule = rule; this.lbStats = new LoadBalancerStats(microServiceName + id.getAndDecrement()); // load new instances, because filters work on service information this.filters = SPIServiceUtils.loadSortedService(ServerListFilterExt.class); this.rule.setLoadBalancer(this); this.filters.forEach((item) -> item.setLoadBalancer(this)); }
Example #4
Source File: DefaultNIWSServerListFilterTest.java From ribbon with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testZoneExclusivity() throws Exception { ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest2.ribbon.DeploymentContextBasedVipAddresses", "l10nservicegeneral.cloud.netflix.net:7001"); ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest2.ribbon.NFLoadBalancerClassName", DynamicServerListLoadBalancer.class.getName()); ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest2.ribbon.EnableZoneExclusivity", "true"); ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest2.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName()); DynamicServerListLoadBalancer lb = (DynamicServerListLoadBalancer) ClientFactory.getNamedLoadBalancer("DefaultNIWSServerListFilterTest2"); ZoneAffinityServerListFilter filter = (ZoneAffinityServerListFilter) lb.getFilter(); LoadBalancerStats loadBalancerStats = lb.getLoadBalancerStats(); List<DiscoveryEnabledServer> servers = new ArrayList<DiscoveryEnabledServer>(); servers.add(createServer(1, "a")); servers.add(createServer(2, "a")); servers.add(createServer(3, "a")); servers.add(createServer(4, "a")); servers.add(createServer(1, "b")); servers.add(createServer(2, "b")); servers.add(createServer(3, "b")); servers.add(createServer(1, "c")); servers.add(createServer(2, "c")); servers.add(createServer(3, "c")); servers.add(createServer(4, "c")); servers.add(createServer(5, "c")); List<DiscoveryEnabledServer> filtered = filter.getFilteredListOfServers(servers); List<DiscoveryEnabledServer> expected = new ArrayList<DiscoveryEnabledServer>(); expected.add(createServer(1, "c")); expected.add(createServer(2, "c")); expected.add(createServer(3, "c")); expected.add(createServer(4, "c")); expected.add(createServer(5, "c")); assertEquals(expected, filtered); lb.setServersList(filtered); for (int i = 1; i <= 4; i++) { loadBalancerStats.incrementActiveRequestsCount(createServer(i, "c")); } filtered = filter.getFilteredListOfServers(servers); assertEquals(expected, filtered); }
Example #5
Source File: LoadBalancer.java From servicecomb-java-chassis with Apache License 2.0 | 4 votes |
public LoadBalancerStats getLoadBalancerStats() { return lbStats; }
Example #6
Source File: DefaultNIWSServerListFilterTest.java From ribbon with Apache License 2.0 | 4 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testZoneAffinityEnabled() throws Exception { ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest1.ribbon.DeploymentContextBasedVipAddresses", "l10nservicegeneral.cloud.netflix.net:7001"); ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest1.ribbon.NFLoadBalancerClassName", DynamicServerListLoadBalancer.class.getName()); ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest1.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName()); ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest1.ribbon.EnableZoneAffinity", "true"); DynamicServerListLoadBalancer lb = (DynamicServerListLoadBalancer) ClientFactory.getNamedLoadBalancer("DefaultNIWSServerListFilterTest1"); assertTrue(lb.getRule() instanceof AvailabilityFilteringRule); ZoneAffinityServerListFilter filter = (ZoneAffinityServerListFilter) lb.getFilter(); LoadBalancerStats loadBalancerStats = lb.getLoadBalancerStats(); List<DiscoveryEnabledServer> servers = new ArrayList<DiscoveryEnabledServer>(); servers.add(createServer(1, "a")); servers.add(createServer(2, "a")); servers.add(createServer(3, "a")); servers.add(createServer(4, "a")); servers.add(createServer(1, "b")); servers.add(createServer(2, "b")); servers.add(createServer(3, "b")); servers.add(createServer(1, "c")); servers.add(createServer(2, "c")); servers.add(createServer(3, "c")); servers.add(createServer(4, "c")); servers.add(createServer(5, "c")); List<DiscoveryEnabledServer> filtered = filter.getFilteredListOfServers(servers); List<DiscoveryEnabledServer> expected = new ArrayList<DiscoveryEnabledServer>(); expected.add(createServer(1, "c")); expected.add(createServer(2, "c")); expected.add(createServer(3, "c")); expected.add(createServer(4, "c")); expected.add(createServer(5, "c")); assertEquals(expected, filtered); lb.setServersList(filtered); for (int i = 1; i <= 4; i++) { loadBalancerStats.incrementActiveRequestsCount(createServer(i, "c")); } filtered = filter.getFilteredListOfServers(servers); assertEquals(servers, filtered); }
Example #7
Source File: DefaultNIWSServerListFilterTest.java From ribbon with Apache License 2.0 | 4 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testZoneAffinityOverride() throws Exception { ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest3.ribbon.DeploymentContextBasedVipAddresses", "l10nservicegeneral.cloud.netflix.net:7001"); ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest3.ribbon.NFLoadBalancerClassName", DynamicServerListLoadBalancer.class.getName()); ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest3.ribbon.EnableZoneAffinity", "true"); ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest3.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName()); ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest3.ribbon.zoneAffinity.minAvailableServers", "3"); DynamicServerListLoadBalancer lb = (DynamicServerListLoadBalancer) ClientFactory.getNamedLoadBalancer("DefaultNIWSServerListFilterTest3"); ZoneAffinityServerListFilter filter = (ZoneAffinityServerListFilter) lb.getFilter(); LoadBalancerStats loadBalancerStats = lb.getLoadBalancerStats(); List<DiscoveryEnabledServer> servers = new ArrayList<DiscoveryEnabledServer>(); servers.add(createServer(1, "a")); servers.add(createServer(2, "a")); servers.add(createServer(3, "a")); servers.add(createServer(4, "a")); servers.add(createServer(1, "b")); servers.add(createServer(2, "b")); servers.add(createServer(3, "b")); servers.add(createServer(1, "c")); servers.add(createServer(2, "c")); List<DiscoveryEnabledServer> filtered = filter.getFilteredListOfServers(servers); List<DiscoveryEnabledServer> expected = new ArrayList<DiscoveryEnabledServer>(); /* expected.add(createServer(1, "c")); expected.add(createServer(2, "c")); expected.add(createServer(3, "c")); expected.add(createServer(4, "c")); expected.add(createServer(5, "c")); */ // less than 3 servers in zone c, will not honor zone affinity assertEquals(servers, filtered); lb.setServersList(filtered); servers.add(createServer(3, "c")); filtered = filter.getFilteredListOfServers(servers); expected.add(createServer(1, "c")); expected.add(createServer(2, "c")); expected.add(createServer(3, "c")); filtered = filter.getFilteredListOfServers(servers); // now we have enough servers in C assertEquals(expected, filtered); // make one server black out for (int i = 1; i <= 3; i++) { loadBalancerStats.incrementSuccessiveConnectionFailureCount(createServer(1, "c")); } filtered = filter.getFilteredListOfServers(servers); assertEquals(servers, filtered); // new server added in zone c, zone c should now have enough servers servers.add(createServer(4, "c")); filtered = filter.getFilteredListOfServers(servers); expected.add(createServer(4, "c")); assertEquals(expected, filtered); }
Example #8
Source File: URLConnectionLoadBalancer.java From ribbon with Apache License 2.0 | 4 votes |
public LoadBalancerStats getLoadBalancerStats() { return ((BaseLoadBalancer) loadBalancer).getLoadBalancerStats(); }