Skip to content

Commit

Permalink
profiler: Inc DefaultBlockRate from 10µs to 100ms (#1192)
Browse files Browse the repository at this point in the history
* profiler: Inc DefaultBlockRate from 10µs to 100ms

See https://github.com/DataDog/go-profiler-notes/pull/15/files for more
information.

Co-authored-by: Nick Ripley <97066770+nsrip-dd@users.noreply.github.com>
  • Loading branch information
felixge and nsrip-dd committed Mar 1, 2022
1 parent c5d3ff2 commit 07c5508
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
25 changes: 12 additions & 13 deletions profiler/options.go
Expand Up @@ -34,12 +34,14 @@ const (
// For more information or for changing this value, check MutexProfileFraction
DefaultMutexFraction = 10

// DefaultBlockRate specifies the default block profiling rate used by the
// block profiler. For more information or for changing this value, check
// BlockProfileRate. The default rate is chosen to prevent high overhead
// based on the research from:
// https://github.com/felixge/go-profiler-notes/blob/main/block.md#benchmarks
DefaultBlockRate = 10000
// DefaultBlockRate specifies the default block profiling rate (in ns) used
// by the block profiler. For more information or for changing this value,
// check BlockProfileRate(). The default value of 100ms is somewhat
// arbitrary. There is no provably safe value that will guarantee low
// overhead for this profile type for all workloads. We don't recommend
// enabling it under normal circumstances. See the link below for more
// information: https://github.com/DataDog/go-profiler-notes/pull/15/files
DefaultBlockRate = 100000000

// DefaultPeriod specifies the default period at which profiles will be collected.
DefaultPeriod = time.Minute
Expand Down Expand Up @@ -356,13 +358,10 @@ func MutexProfileFraction(rate int) Option {
}
}

// BlockProfileRate turns on block profiles with the given rate.
// The profiler samples an average of one blocking event per rate nanoseconds spent blocked.
// For example, set rate to 1000000000 (aka int(time.Second.Nanoseconds())) to
// record one sample per second a goroutine is blocked.
// A rate of 1 catches every event.
// Setting an aggressive rate can hurt performance.
// For more information on this value, check runtime.SetBlockProfileRate.
// BlockProfileRate turns on block profiles with the given rate. We do not
// recommend enabling this profile type, see DefaultBlockRate for more
// information. The rate is given in nanoseconds and a block event with a given
// duration has a min(duration/rate, 1) chance of getting sampled.
func BlockProfileRate(rate int) Option {
return func(cfg *config) {
cfg.addProfileType(BlockProfile)
Expand Down
6 changes: 4 additions & 2 deletions profiler/profile.go
Expand Up @@ -30,8 +30,10 @@ const (
// CPUProfile determines where a program spends its time while actively consuming
// CPU cycles (as opposed to while sleeping or waiting for I/O).
CPUProfile
// BlockProfile shows where goroutines block waiting on synchronization primitives
// (including timer channels). Block profile is not enabled by default.
// BlockProfile shows where goroutines block waiting on mutex and channel
// operations. The block profile is not enabled by default and may cause
// noticeable CPU overhead. We recommend against enabling it, see
// DefaultBlockRate for more information.
BlockProfile
// MutexProfile reports the lock contentions. When you think your CPU is not fully utilized due
// to a mutex contention, use this profile. Mutex profile is not enabled by default.
Expand Down

0 comments on commit 07c5508

Please sign in to comment.