From a2772762e1e0a4f3716d647f7946f0e43d6bf0b5 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Wed, 21 Sep 2022 13:33:15 -0600 Subject: [PATCH] Make pprof configurable, remove todos --- README.md | 3 +++ cmd/env.go | 6 +++++- cmd/serve.go | 11 +++++++---- pkg/service.go | 3 +-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 96fd600..96fc6fd 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,9 @@ An example config file: # path to custom chain config file (optional) # keep chainID same as that in chain config file chainConfig = "./chain.json" # ETH_CHAIN_CONFIG + +[debug] + pprof = false # Enable pprof agent listener on port 6060 ``` ### Local Setup diff --git a/cmd/env.go b/cmd/env.go index 1e20582..4fe244c 100644 --- a/cmd/env.go +++ b/cmd/env.go @@ -82,6 +82,8 @@ const ( DATABASE_MAX_CONN_LIFETIME = "DATABASE_MAX_CONN_LIFETIME" DATABASE_CONN_TIMEOUT = "DATABSE_CONN_TIMEOUT" DATABASE_MAX_CONN_IDLE_TIME = "DATABASE_MAX_CONN_IDLE_TIME" + + DEBUG_PPROF = "DEBUG_PPROF" ) // Bind env vars for eth node and DB configuration @@ -136,7 +138,7 @@ func init() { viper.BindEnv("statediff.prerun", STATEDIFF_PRERUN) viper.BindEnv("prerun.only", PRERUN_ONLY) - viper.BindEnv("prerun.only", PRERUN_PARALLEL) + viper.BindEnv("prerun.parallel", PRERUN_PARALLEL) viper.BindEnv("prerun.start", PRERUN_RANGE_START) viper.BindEnv("prerun.stop", PRERUN_RANGE_STOP) viper.BindEnv("prerun.params.intermediateStateNodes", PRERUN_INTERMEDIATE_STATE_NODES) @@ -148,4 +150,6 @@ func init() { viper.BindEnv("log.level", LOG_LEVEL) viper.BindEnv("log.file", LOG_FILE_PATH) + + viper.BindEnv("debug.pprof", DEBUG_PPROF) } diff --git a/cmd/serve.go b/cmd/serve.go index cd53a60..b178132 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -68,15 +68,18 @@ func serve() { logWithCommand.Fatal(err) } - // short circuit if we only want to perform prerun - if viper.GetBool("prerun.only") { - // TODO: make pprof optional + // Enable the pprof agent if configured + if viper.GetBool("debug.pprof") { // See: https://www.farsightsecurity.com/blog/txt-record/go-remote-profiling-20161028/ - // Do not use the default http multiplexor elsewhere in this process. + // For security reasons: do not use the default http multiplexor elsewhere in this process. go func() { logWithCommand.Info("Starting pprof listener on port 6060") logWithCommand.Fatal(http.ListenAndServe("localhost:6060", nil)) }() + } + + // short circuit if we only want to perform prerun + if viper.GetBool("prerun.only") { parallel := viper.GetBool("prerun.parallel") if err := statediffService.Run(nil, parallel); err != nil { logWithCommand.Fatal("unable to perform prerun: %v", err) diff --git a/pkg/service.go b/pkg/service.go index cefd726..0307236 100644 --- a/pkg/service.go +++ b/pkg/service.go @@ -133,7 +133,6 @@ func (sds *Service) Run(rngs []RangeRequest, parallel bool) error { wg := new(sync.WaitGroup) for i := 0; i < int(sds.workers); i++ { blockRange := RangeRequest{ - // TODO(dboreham): check this math doesn't leave gaps (are start/stop inclusive?) Start: preRun.Start + uint64(i)*chunkSize, Stop: preRun.Start + uint64(i)*chunkSize + chunkSize - 1, Params: preRun.Params, @@ -165,7 +164,7 @@ func (sds *Service) Run(rngs []RangeRequest, parallel bool) error { } } sds.preruns = nil - // TODO(dboreham): seems like this code is never called so we have not written the parallel version + // At present this code is never called so we have not written the parallel version: for _, rng := range rngs { logrus.Infof("processing requested range (%d, %d)", rng.Start, rng.Stop) for i := rng.Start; i <= rng.Stop; i++ {