Skip to content

Commit

Permalink
Change l4 healthcheck timeout
Browse files Browse the repository at this point in the history
According to l4 healthcheck constants
the default set up has timeout = 8 seconds
and threshold = 3 times. As result it can
lead to 24 (8*3) seconds of lost requests.
This change is supposed to decrease this
time to only 6 seconds for sharedHc=false.

Signed-off-by: Elina Akhmanova <elinka@google.com>
  • Loading branch information
code-elinka committed Oct 6, 2022
1 parent 43e9cf6 commit ae443dc
Show file tree
Hide file tree
Showing 2 changed files with 302 additions and 41 deletions.
53 changes: 38 additions & 15 deletions pkg/healthchecksl4/healthchecksl4.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ import (

const (
// L4 Load Balancer parameters
gceHcCheckIntervalSeconds = int64(8)
gceHcTimeoutSeconds = int64(1)
gceSharedHcCheckIntervalSeconds = int64(8) // Shared Health check Interval
gceLocalHcCheckIntervalSeconds = int64(3) // Local Health check Interval
gceHcTimeoutSeconds = int64(1)
// Start sending requests as soon as one healthcheck succeeds.
gceHcHealthyThreshold = int64(1)
// Defaults to 3 * 8 = 24 seconds before the LB will steer traffic away.
gceHcUnhealthyThreshold = int64(3)
gceHcHealthyThreshold = int64(1)
gceSharedHcUnhealthyThreshold = int64(3) // 3 * 8 = 24 seconds before the LB will steer traffic away
gceLocalHcUnhealthyThreshold = int64(2) // 2 * 3 = 6 seconds before the LB will steer traffic away
)

var (
Expand Down Expand Up @@ -79,6 +80,24 @@ func Fake(cloud *gce.Cloud, recorder record.EventRecorder) *l4HealthChecks {
}
}

// Returns an interval constant based of shared/local status
func healthcheckInterval(isShared bool) int64 {
if isShared {
return gceSharedHcCheckIntervalSeconds
} else {
return gceLocalHcCheckIntervalSeconds
}
}

// Returns a threshold for unhealthy instance based of shared/local status
func healthcheckUnhealthyThreshold(isShared bool) int64 {
if isShared {
return gceSharedHcUnhealthyThreshold
} else {
return gceLocalHcUnhealthyThreshold
}
}

// EnsureHealthCheckWithFirewall exist for the L4
// LoadBalancer Service.
//
Expand Down Expand Up @@ -285,12 +304,16 @@ func newL4HealthCheck(name string, svcName types.NamespacedName, shared bool, pa
if err != nil {
klog.Warningf("Failed to generate description for L4HealthCheck %s, err %v", name, err)
}
// Get constant values based on shared/local status
interval := healthcheckInterval(shared)
unhealthyThreshold := healthcheckUnhealthyThreshold(shared)

return &composite.HealthCheck{
Name: name,
CheckIntervalSec: gceHcCheckIntervalSeconds,
CheckIntervalSec: interval,
TimeoutSec: gceHcTimeoutSeconds,
HealthyThreshold: gceHcHealthyThreshold,
UnhealthyThreshold: gceHcUnhealthyThreshold,
UnhealthyThreshold: unhealthyThreshold,
HttpHealthCheck: &httpSettings,
Type: "HTTP",
Description: desc,
Expand Down Expand Up @@ -325,12 +348,12 @@ func mergeHealthChecks(hc, newHC *composite.HealthCheck) {
// needToUpdateHealthChecks checks whether the healthcheck needs to be updated.
func needToUpdateHealthChecks(hc, newHC *composite.HealthCheck) bool {
return hc.HttpHealthCheck == nil ||
newHC.HttpHealthCheck == nil ||
hc.HttpHealthCheck.Port != newHC.HttpHealthCheck.Port ||
hc.HttpHealthCheck.RequestPath != newHC.HttpHealthCheck.RequestPath ||
hc.Description != newHC.Description ||
hc.CheckIntervalSec < newHC.CheckIntervalSec ||
hc.TimeoutSec < newHC.TimeoutSec ||
hc.UnhealthyThreshold < newHC.UnhealthyThreshold ||
hc.HealthyThreshold < newHC.HealthyThreshold
newHC.HttpHealthCheck == nil ||
hc.HttpHealthCheck.Port != newHC.HttpHealthCheck.Port ||
hc.HttpHealthCheck.RequestPath != newHC.HttpHealthCheck.RequestPath ||
hc.Description != newHC.Description ||
hc.CheckIntervalSec < newHC.CheckIntervalSec ||
hc.TimeoutSec < newHC.TimeoutSec ||
hc.UnhealthyThreshold < newHC.UnhealthyThreshold ||
hc.HealthyThreshold < newHC.HealthyThreshold
}
Loading

0 comments on commit ae443dc

Please sign in to comment.