In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what the role of ServerListSubsetFilter in ribbon is, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
ServerListSubsetFilter
RibbonCorp _ loadbalancerr _ 2.3.0 Mutual sources.jarcup _
Public class ServerListSubsetFilter extends ZoneAffinityServerListFilter implements IClientConfigAware, Comparator {private Random random = new Random (); private volatile Set currentSubset = Sets.newHashSet (); private DynamicIntProperty sizeProp = new DynamicIntProperty (DefaultClientConfigImpl.DEFAULT_PROPERTY_NAME_SPACE + ".ServerListSubsetFilter.size", 20); private DynamicFloatProperty eliminationPercent = new DynamicFloatProperty (DefaultClientConfigImpl.DEFAULT_PROPERTY_NAME_SPACE + ".ServerListSubsetFilter.forceSecretatePercent", 0.1f) Private DynamicIntProperty eliminationFailureCountThreshold = new DynamicIntProperty (DefaultClientConfigImpl.DEFAULT_PROPERTY_NAME_SPACE + ".ServerListSubsetFilter.eliminationFailureThresold", 0); private DynamicIntProperty eliminationConnectionCountThreshold = new DynamicIntProperty (DefaultClientConfigImpl.DEFAULT_PROPERTY_NAME_SPACE + ".ServerListSubsetFilter.eliminationConnectionThresold", 0); @ 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.forceSecretatePercent", 0.1f); eliminationFailureCountThreshold = new DynamicIntProperty (clientConfig.getClientName () + "." + clientConfig.getNameSpace () + ".ServerListSubsetFilter.eliminationFailureThresold", 0); eliminationConnectionCountThreshold = new DynamicIntProperty (clientConfig.getClientName () + "." + clientConfig.getNameSpace () + ".ServerListSubsetFilter.eliminationConnectionThresold", 0) } @ Override public List getFilteredListOfServers (List servers) {List zoneAffinityFiltered = super.getFilteredListOfServers (servers); Set candidates = Sets.newHashSet (zoneAffinityFiltered); Set newSubSet = Sets.newHashSet (currentSubset); LoadBalancerStats lbStats = getLoadBalancerStats () For (T server: currentSubset) {/ / this server is either down or out of service if (! candidates.contains (server)) {newSubSet.remove (server);} else {ServerStats stats = lbStats.getSingleServerStat (server) / / remove the servers that do not meet health criteria if (stats.getActiveRequestsCount () > eliminationConnectionCountThreshold.get () | | stats.getFailureCount () > eliminationFailureCountThreshold.get ()) {newSubSet.remove (server); / / also remove from the general pool to avoid selecting them again candidates.remove (server) } int targetedListSize = sizeProp.get (); int numEliminated = currentSubset.size ()-newSubSet.size (); int minElimination = (int) (targetedListSize * eliminationPercent.get ()); int numToForceEliminate = 0; if (targetedListSize
< newSubSet.size()) { // size is shrinking numToForceEliminate = newSubSet.size() - targetedListSize; } else if (minElimination >NumEliminated) {numToForceEliminate = minElimination-numEliminated;} if (numToForceEliminate > newSubSet.size ()) {numToForceEliminate = newSubSet.size ();} if (numToForceEliminate > 0) {List sortedSubSet = Lists.newArrayList (newSubSet); Collections.sort (sortedSubSet, this); List forceEliminated = sortedSubSet.subList (0, numToForceEliminate) NewSubSet.removeAll (forceEliminated); candidates.removeAll (forceEliminated);} / / after forced elimination or elimination of unhealthy instances, / / the size of the set may be less than the targeted size, / / then we just randomly add servers from the big pool if (newSubSet.size ()
< targetedListSize) { int numToChoose = targetedListSize - newSubSet.size(); candidates.removeAll(newSubSet); if (numToChoose >Candidates.size () {/ / Not enough healthy instances to choose, fallback to use the / / total server pool candidates = Sets.newHashSet (zoneAffinityFiltered); candidates.removeAll (newSubSet);} List chosen = randomChoose (Lists.newArrayList (candidates), numToChoose); for (T server: chosen) {newSubSet.add (server) }} currentSubset = newSubSet; return Lists.newArrayList (newSubSet);} / * * Randomly shuffle the beginning portion of server list (according to the number passed into the method) * and return them. * * @ param servers * @ param toChoose * @ return * / private List randomChoose (List servers, int toChoose) {int size = servers.size (); if (toChoose > = size | | toChoose < 0) {return servers;} for (int I = 0; I < toChoose; iTunes +) {int index = random.nextInt (size) T tmp = servers.get (index); servers.set (index, servers.get (I)); servers.set (I, tmp);} return servers.subList (0, toChoose);} / * * Function to sort the list by server health condition, with * unhealthy servers before healthy servers. The servers are first sorted by * failures count, and then concurrent connection count. * / @ Override public int compare (T server1, T server2) {LoadBalancerStats lbStats = getLoadBalancerStats (); ServerStats stats1 = lbStats.getSingleServerStat (server1); ServerStats stats2 = lbStats.getSingleServerStat (server2); int failuresDiff = (int) (stats2.getFailureCount ()-stats1.getFailureCount ()); if (failuresDiff! = 0) {return failuresDiff } else {return (stats2.getActiveRequestsCount ()-stats1.getActiveRequestsCount ());}}
ServerListSubsetFilter inherits ZoneAffinityServerListFilter and implements IClientConfigAware and Comparator interfaces.
The initWithNiwsConfig method reads ServerListSubsetFilter.size, ServerListSubsetFilter.forceEliminatePercent, ServerListSubsetFilter.eliminationFailureThresold, and ServerListSubsetFilter.eliminationConnectionThresold configurations from IClientConfig
The getFilteredListOfServers method first calls the getFilteredListOfServers of the parent class ZoneAffinityServerListFilter to filter out the zoneAffinityFiltered as the candidates, and then traverses the currentSubset to eliminate the server; that activeRequestsCount and failureCount exceed the threshold according to ServerStats, and then sort according to numToForceEliminate and failureCount, use the subList method to get forceEliminated, then remove it, finally randomChoose out the new newSubSet, and then reset currentSubset
Summary
In scenarios where there are too many server list, there is no need to maintain so many connections in the connection pool. ServerListSubsetFilter can simplify the server list in this scenario and achieve this goal by eliminating relatively unhealthy server (failureCount, activeRequestCount).
About what the role of ServerListSubsetFilter in ribbon is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.