Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2cd67c

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request #36756 from gmarek/contention
Automatic merge from submit-queue Add a flag allowing contention profiling of the API server Useful for performance debugging. cc @smarterclayton @timothysc @lavalamp ```release-note Add a flag allowing contention profiling of the API server ```
2 parents 05d067d + c97633b commit b2cd67c

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

hack/verify-flags/known-flags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ container-port
105105
container-runtime
106106
container-runtime-endpoint
107107
contain-pod-resources
108+
contention-profiling
108109
controller-start-interval
109110
cors-allowed-origins
110111
cpu-cfs-quota

pkg/genericapiserver/config.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"os"
2525
"path"
2626
"regexp"
27+
goruntime "runtime"
2728
"sort"
2829
"strconv"
2930
"strings"
@@ -78,10 +79,12 @@ type Config struct {
7879
// Allows api group versions or specific resources to be conditionally enabled/disabled.
7980
APIResourceConfigSource APIResourceConfigSource
8081
// allow downstream consumers to disable the index route
81-
EnableIndex bool
82-
EnableProfiling bool
83-
EnableMetrics bool
84-
EnableGarbageCollection bool
82+
EnableIndex bool
83+
EnableProfiling bool
84+
// Requires generic profiling enabled
85+
EnableContentionProfiling bool
86+
EnableMetrics bool
87+
EnableGarbageCollection bool
8588

8689
Version *version.Info
8790
CorsAllowedOriginList []string
@@ -285,6 +288,7 @@ func (c *Config) ApplyOptions(options *options.ServerRunOptions) *Config {
285288
c.CorsAllowedOriginList = options.CorsAllowedOriginList
286289
c.EnableGarbageCollection = options.EnableGarbageCollection
287290
c.EnableProfiling = options.EnableProfiling
291+
c.EnableContentionProfiling = options.EnableContentionProfiling
288292
c.EnableSwaggerUI = options.EnableSwaggerUI
289293
c.ExternalAddress = options.ExternalHost
290294
c.MaxRequestsInFlight = options.MaxRequestsInFlight
@@ -462,6 +466,9 @@ func (s *GenericAPIServer) installAPI(c *Config) {
462466
}
463467
if c.EnableProfiling {
464468
routes.Profiling{}.Install(s.HandlerContainer)
469+
if c.EnableContentionProfiling {
470+
goruntime.SetBlockProfileRate(1)
471+
}
465472
}
466473
if c.EnableMetrics {
467474
if c.EnableProfiling {

pkg/genericapiserver/options/server_run_options.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ type ServerRunOptions struct {
8383
AuditLogMaxSize int
8484
EnableGarbageCollection bool
8585
EnableProfiling bool
86+
EnableContentionProfiling bool
8687
EnableSwaggerUI bool
8788
EnableWatchCache bool
8889
EtcdServersOverrides []string
@@ -139,6 +140,7 @@ func NewServerRunOptions() *ServerRunOptions {
139140
DeleteCollectionWorkers: 1,
140141
EnableGarbageCollection: true,
141142
EnableProfiling: true,
143+
EnableContentionProfiling: false,
142144
EnableWatchCache: true,
143145
InsecureBindAddress: net.ParseIP("127.0.0.1"),
144146
InsecurePort: 8080,
@@ -347,6 +349,8 @@ func (s *ServerRunOptions) AddUniversalFlags(fs *pflag.FlagSet) {
347349

348350
fs.BoolVar(&s.EnableProfiling, "profiling", s.EnableProfiling,
349351
"Enable profiling via web interface host:port/debug/pprof/")
352+
fs.BoolVar(&s.EnableContentionProfiling, "contention-profiling", s.EnableContentionProfiling,
353+
"Enable contention profiling. Requires --profiling to be set to work.")
350354

351355
fs.BoolVar(&s.EnableSwaggerUI, "enable-swagger-ui", s.EnableSwaggerUI,
352356
"Enables swagger ui on the apiserver at /swagger-ui")

0 commit comments

Comments
 (0)