Skip to content

Commit 67a075a

Browse files
authored
Merge pull request #2942 from TortillaZHawaii/neg-balancing-etp-cluster
Reduce the number of Endpoints for ILB ETP Cluster
2 parents 8f353e0 + b451809 commit 67a075a

File tree

3 files changed

+542
-15
lines changed

3 files changed

+542
-15
lines changed

pkg/neg/syncers/endpoints_calculator.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,22 +214,22 @@ func (l *ClusterL4EndpointsCalculator) CalculateEndpoints(eds []types.EndpointsD
214214
}
215215
l.logger.V(2).Info("Got zoneNodeMap as input for service", "zoneNodeMap", nodeMapToString(zoneNodeMap), "serviceID", l.svcId)
216216

217-
wanted := l.subsetSizeLimit
217+
wanted := l.wantedInternalEndpointsCount(len(zoneNodeMap))
218218
if l.lbType == types.L4ExternalLB {
219-
wanted = l.wantedNEGsCount(eds, currentMap, len(zoneSubnetPairs))
219+
wanted = l.wantedExternalEndpointsCount(eds, currentMap, len(zoneSubnetPairs))
220220
}
221221

222222
subsetMap, err := getSubsetPerZone(zoneNodeMap, wanted, l.svcId, currentMap, l.logger, l.networkInfo)
223223
return subsetMap, nil, 0, err
224224
}
225225

226-
// wantedNEGsCount will determine the amount of NEGs that:
226+
// wantedExternalEndpointsCount will determine the amount of endpoints that:
227227
// * scales linearly based on the number of pods
228-
// * won't over provision NEGs over the nodes or pods count
229-
// * won't delete already existing NEGs, as that requires connection draining
230-
// * will provide at least 3 NEGs per zone/subnet pair
228+
// * won't over provision endpoints over the nodes or pods count
229+
// * won't delete already existing endpoints, as that requires connection draining
230+
// * will provide at least 3 endpoints per zone/subnet pair
231231
// * takes into account limits for passthrough NetLB and ILB
232-
func (l *ClusterL4EndpointsCalculator) wantedNEGsCount(eds []types.EndpointsData, currentMap map[types.NEGLocation]types.NetworkEndpointSet, zoneSubnetPairCount int) int {
232+
func (l *ClusterL4EndpointsCalculator) wantedExternalEndpointsCount(eds []types.EndpointsData, currentMap map[types.NEGLocation]types.NetworkEndpointSet, zoneSubnetPairCount int) int {
233233
// Compute the networkEndpoints, with total endpoints <= l.subsetSizeLimit.
234234
optimal := linearEndpointsPerPods(zoneSubnetPairCount, edsLen(eds), l.subsetSizeLimit)
235235

@@ -242,6 +242,26 @@ func (l *ClusterL4EndpointsCalculator) wantedNEGsCount(eds []types.EndpointsData
242242
return wanted
243243
}
244244

245+
// wantedInternalEndpointsCount will determine the amount of endpoints that is divisible by the number of zones
246+
// This should lead to improvements in the amount of connection draining that is done,
247+
func (l *ClusterL4EndpointsCalculator) wantedInternalEndpointsCount(zonesCount int) int {
248+
// | zones | endpoints per zone | total endpoints |
249+
// | ----- | ------------------ | --------------- |
250+
// | 1 | 24 | 24 |
251+
// | 2 | 12 | 24 |
252+
// | 3 | 8 | 24 |
253+
// | 4 | 6 | 24 |
254+
// | 5 | 5 | 25 |
255+
// | 6 | 4 | 24 |
256+
// | ----- | ------------------ | --------------- |
257+
// Based on https://cloud.google.com/compute/docs/regions-zones#available
258+
// There are no regions with more than 4 zones currently.
259+
if zonesCount != 0 && 24%zonesCount == 0 { // If there is some issue with zonesCount we don't want to divide by zero
260+
return 24
261+
}
262+
return 25
263+
}
264+
245265
func linearEndpointsPerPods(zoneSubnetPairCount, endpointsCount, subsetSizeLimit int) int {
246266
const minCountPerZoneSubnetPair = 3
247267
lowerZonalBasedBound := zoneSubnetPairCount * minCountPerZoneSubnetPair

0 commit comments

Comments
 (0)