Make pprof configurable, remove todos

This commit is contained in:
David Boreham 2022-09-21 13:33:15 -06:00
parent b1440d9673
commit a2772762e1
4 changed files with 16 additions and 7 deletions

View File

@ -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

View File

@ -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)
}

View File

@ -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)

View File

@ -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++ {