@@ -1806,7 +1806,7 @@ func loadLocationStables(
18061806 return
18071807 }
18081808 if 0 < filter .Count {
1809- stable := MinStableProviderCount <= filter .Count
1809+ stable := MinStableNetReliabilityWeight <= filter .NetReliabilityWeight
18101810 locationStables [locationId ] = stable
18111811 }
18121812 // else there are no providers
@@ -2109,15 +2109,20 @@ type ClientScore struct {
21092109}
21102110
21112111type ClientFilter struct {
2112- Count int
2113- Index int
2112+ Count int
2113+ NetReliabilityWeight float64
2114+ Index int
21142115}
21152116
21162117// scores are [0, max], where 0 is best
21172118const MaxClientScore = 50
21182119const ClientScoreSampleCount = 200
21192120
2120- const MinStableProviderCount = 30
2121+ // choose a filter that has at least this number of providers
2122+ const MinExportNetReliabilityWeight = float64 (200 )
2123+
2124+ // the number of filtered providers to consider a location stable
2125+ const MinStableNetReliabilityWeight = float64 (10 )
21212126
21222127func clientScoreLocationCountsKey (forceMinimum bool , rankMode RankMode , locationId server.Id , callerLocationId server.Id ) string {
21232128 fm := 0
@@ -2204,38 +2209,6 @@ func UpdateClientScores(ctx context.Context, ttl time.Duration) (returnErr error
22042209 missingLatencyScore := scorePerTier
22052210 missingSpeedScore := scorePerTier
22062211
2207- type filter struct {
2208- maxScore int
2209- minIndependentReliabilityWeights map [int ]float64
2210- }
2211-
2212- filters := []filter {
2213- filter {
2214- maxScore : scorePerTier ,
2215- minIndependentReliabilityWeights : map [int ]float64 {
2216- 1 : float64 (0.999 ),
2217- 2 : float64 (0.99 ),
2218- 3 : float64 (0.9 ),
2219- },
2220- },
2221- filter {
2222- maxScore : 2 * scorePerTier ,
2223- minIndependentReliabilityWeights : map [int ]float64 {
2224- 1 : float64 (0.99 ),
2225- 2 : float64 (0.9 ),
2226- 3 : float64 (0.8 ),
2227- },
2228- },
2229- filter {
2230- maxScore : 2 * scorePerTier ,
2231- minIndependentReliabilityWeights : map [int ]float64 {
2232- 1 : float64 (0.9 ),
2233- 2 : float64 (0.8 ),
2234- 3 : float64 (0.7 ),
2235- },
2236- },
2237- }
2238-
22392212 performanceTargets := map [RankMode ]performanceTarget {
22402213 RankModeQuality : performanceTarget {
22412214 relativeLatencyMillisThreshold : 50 ,
@@ -2518,6 +2491,48 @@ func UpdateClientScores(ctx context.Context, ttl time.Duration) (returnErr error
25182491 }
25192492 }
25202493
2494+ type filter struct {
2495+ maxScore int
2496+ minIndependentReliabilityWeights map [int ]float64
2497+ minBytesPerSecond ByteCount
2498+ maxRelativeLatencyMillis int
2499+ }
2500+ // filters are tested in order of declaration for `MinExportNetReliabilityWeight`
2501+ // to minimize the chance of bad providers in the `FindProviders2` randomized shuffle
2502+ // the last filter represents the worst case the network will expose to users
2503+ filters := []filter {
2504+ filter {
2505+ maxScore : scorePerTier ,
2506+ minIndependentReliabilityWeights : map [int ]float64 {
2507+ 1 : float64 (0.999 ),
2508+ 2 : float64 (0.99 ),
2509+ 3 : float64 (0.9 ),
2510+ },
2511+ // minBytesPerSecond: Mib * 1,
2512+ // maxRelativeLatencyMillis: 200,
2513+ },
2514+ filter {
2515+ maxScore : 2 * scorePerTier ,
2516+ minIndependentReliabilityWeights : map [int ]float64 {
2517+ 1 : float64 (0.99 ),
2518+ 2 : float64 (0.9 ),
2519+ 3 : float64 (0.8 ),
2520+ },
2521+ // minBytesPerSecond: Mib * 1,
2522+ // maxRelativeLatencyMillis: 400,
2523+ },
2524+ filter {
2525+ maxScore : 2 * scorePerTier ,
2526+ minIndependentReliabilityWeights : map [int ]float64 {
2527+ 1 : float64 (0.9 ),
2528+ 2 : float64 (0.8 ),
2529+ 3 : float64 (0.7 ),
2530+ },
2531+ // minBytesPerSecond: Kib * 512,
2532+ // maxRelativeLatencyMillis: 600,
2533+ },
2534+ }
2535+
25212536 exportClientScores := func (forceMinimum bool , rankMode RankMode , s map [server.Id ]* ClientScore ) (
25222537 countsBytes []byte ,
25232538 samplesBytes [][]byte ,
@@ -2534,24 +2549,37 @@ func UpdateClientScores(ctx context.Context, ttl time.Duration) (returnErr error
25342549 }
25352550 // all lookback thresholds must pass
25362551 for lookbackIndex , lookbackClientScore := range clientScore .LookbackClientScores {
2537- if lookbackClientScore .IndependentReliabilityWeight < f .minIndependentReliabilityWeights [lookbackIndex ] || f .maxScore <= lookbackClientScore .Scores [rankMode ] {
2552+ if lookbackClientScore .IndependentReliabilityWeight < f .minIndependentReliabilityWeights [lookbackIndex ] {
2553+ return false
2554+ }
2555+ if f .maxScore <= lookbackClientScore .Scores [rankMode ] {
2556+ return false
2557+ }
2558+ if 0 < f .minBytesPerSecond && lookbackClientScore .MaxBytesPerSecond < f .minBytesPerSecond {
2559+ return false
2560+ }
2561+ if 0 < f .maxRelativeLatencyMillis && f .maxRelativeLatencyMillis <= lookbackClientScore .MinRelativeLatencyMillis {
25382562 return false
25392563 }
25402564 }
25412565 return true
25422566 }
25432567 cs := []* ClientScore {}
2568+ netReliabilityWeight := float64 (0 )
25442569 for _ , clientScore := range s {
25452570 if passesMinimum (clientScore ) {
2571+ netReliabilityWeight += clientScore .ReliabilityWeight
25462572 cs = append (cs , clientScore )
25472573 }
25482574 }
2575+
25492576 clientScores = cs
25502577 filter = & ClientFilter {
2551- Index : i ,
2552- Count : len (cs ),
2578+ Index : i ,
2579+ Count : len (cs ),
2580+ NetReliabilityWeight : netReliabilityWeight ,
25532581 }
2554- if MinStableProviderCount <= len ( cs ) {
2582+ if MinExportNetReliabilityWeight <= netReliabilityWeight {
25552583 break
25562584 }
25572585 }
0 commit comments