[#39] ir: Add optional profilers
Includes `block` and `mutex` profiles configuration. Signed-off-by: Pavel Karpy <p.karpy@yadro.com> Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
f989bc52be
commit
f604d6bbdc
5 changed files with 72 additions and 8 deletions
|
@ -64,12 +64,16 @@ func (c *httpComponent) shutdown() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *httpComponent) reload() {
|
||||
log.Info(fmt.Sprintf("reload %s", c.name))
|
||||
func (c *httpComponent) needReload() bool {
|
||||
enabled := cfg.GetBool(c.name + enabledKeyPostfix)
|
||||
address := cfg.GetString(c.name + addressKeyPostfix)
|
||||
dur := cfg.GetDuration(c.name + shutdownTimeoutKeyPostfix)
|
||||
if enabled != c.enabled || enabled && (address != c.address || dur != c.shutdownDur) {
|
||||
return enabled != c.enabled || enabled && (address != c.address || dur != c.shutdownDur)
|
||||
}
|
||||
|
||||
func (c *httpComponent) reload() {
|
||||
log.Info(fmt.Sprintf("reload %s", c.name))
|
||||
if c.needReload() {
|
||||
log.Info(fmt.Sprintf("%s config updated", c.name))
|
||||
if err := c.shutdown(); err != nil {
|
||||
log.Debug(logs.FrostFSIRCouldNotShutdownHTTPServer,
|
||||
|
|
|
@ -30,7 +30,7 @@ var (
|
|||
intErr = make(chan error) // internal inner ring errors
|
||||
logPrm = new(logger.Prm)
|
||||
innerRing *innerring.Server
|
||||
pprofCmp *httpComponent
|
||||
pprofCmp *pprofComponent
|
||||
metricsCmp *httpComponent
|
||||
log *logger.Logger
|
||||
cfg *viper.Viper
|
||||
|
|
|
@ -1,12 +1,68 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
||||
httputil "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/http"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func newPprofComponent() *httpComponent {
|
||||
return &httpComponent{
|
||||
type pprofComponent struct {
|
||||
httpComponent
|
||||
blockRate int
|
||||
mutexRate int
|
||||
}
|
||||
|
||||
const (
|
||||
pprofBlockRateKey = "pprof.block_rate"
|
||||
pprofMutexRateKey = "pprof.mutex_rate"
|
||||
)
|
||||
|
||||
func newPprofComponent() *pprofComponent {
|
||||
return &pprofComponent{
|
||||
httpComponent: httpComponent{
|
||||
name: "pprof",
|
||||
handler: httputil.Handler(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (c *pprofComponent) init() {
|
||||
c.httpComponent.init()
|
||||
|
||||
if c.enabled {
|
||||
c.blockRate = cfg.GetInt(pprofBlockRateKey)
|
||||
c.mutexRate = cfg.GetInt(pprofMutexRateKey)
|
||||
runtime.SetBlockProfileRate(c.blockRate)
|
||||
runtime.SetMutexProfileFraction(c.mutexRate)
|
||||
} else {
|
||||
c.blockRate = 0
|
||||
c.mutexRate = 0
|
||||
runtime.SetBlockProfileRate(0)
|
||||
runtime.SetMutexProfileFraction(0)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *pprofComponent) needReload() bool {
|
||||
blockRate := cfg.GetInt(pprofBlockRateKey)
|
||||
mutexRate := cfg.GetInt(pprofMutexRateKey)
|
||||
return c.httpComponent.needReload() ||
|
||||
c.enabled && (c.blockRate != blockRate || c.mutexRate != mutexRate)
|
||||
}
|
||||
|
||||
func (c *pprofComponent) reload() {
|
||||
log.Info(fmt.Sprintf("reload %s", c.name))
|
||||
if c.needReload() {
|
||||
log.Info(fmt.Sprintf("%s config updated", c.name))
|
||||
if err := c.shutdown(); err != nil {
|
||||
log.Debug(logs.FrostFSIRCouldNotShutdownHTTPServer,
|
||||
zap.String("error", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
c.init()
|
||||
c.start()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,6 +74,8 @@ FROSTFS_IR_CONTRACTS_ALPHABET_ZHIVETE=f584699bc2ff457d339fb09f16217042c1a42101
|
|||
FROSTFS_IR_PPROF_ENABLED=true
|
||||
FROSTFS_IR_PPROF_ADDRESS=localhost:6060
|
||||
FROSTFS_IR_PPROF_SHUTDOWN_TIMEOUT=30s
|
||||
FROSTFS_IR_PPROF_BLOCK_RATE=10000
|
||||
FROSTFS_IR_PPROF_MUTEX_RATE=10000
|
||||
|
||||
FROSTFS_IR_PROMETHEUS_ENABLED=true
|
||||
FROSTFS_IR_PROMETHEUS_ADDRESS=localhost:9090
|
||||
|
|
|
@ -113,6 +113,8 @@ pprof:
|
|||
enabled: true
|
||||
address: localhost:6060 # Endpoint for application pprof profiling; disabled by default
|
||||
shutdown_timeout: 30s # Timeout for profiling HTTP server graceful shutdown
|
||||
block_rate: 10000 # sampling rate: an average of one blocking event per rate nanoseconds spent blocked is reported; "1" reports every blocking event; "0" disables profiler
|
||||
mutex_rate: 10000 # sampling rate: on average 1/rate events are reported; "0" disables profiler
|
||||
|
||||
prometheus:
|
||||
enabled: true
|
||||
|
|
Loading…
Reference in a new issue