Skip to content

Conversation

@petesimard
Copy link
Contributor

main: Sample config file for cache value to allow setting Go GC cache values though a config file
node: Add new configuration variable "Cache"
utils: Set configuration value based on command line parameter

When Geth detects it is operating on the mainnet it will bump up cache values. This happens before the configuration file is parsed so the value is unable to be set by the config file and must be set via a command line parameter.

This patch adds a new configuration variable allowing this cache value to be set. In order to read this value, the config file must be parsed early to detect the presence of this value.

Fixes #21090

Create new config flag for Cache and check for that flag in the config file early
Make comment text clearer
Fix spelling on comment
Set the config Cache value if provided by command line
@petesimard petesimard requested review from fjl and renaynay as code owners March 10, 2021 17:51
@petesimard petesimard changed the title Cache config all: Cache config Mar 10, 2021
@petesimard petesimard changed the title all: Cache config all: Fix cache variable with config files Mar 10, 2021
if err := loadConfig(file, &cfg); err != nil {
utils.Fatalf("%v", err)
}
}
Copy link
Contributor

@fjl fjl Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why the config needs to be loaded another time here. Maybe it's because the code below, which post-processes the cache amount automatically is in the wrong place.

There are two parts to this post-processing. First we have some logic to set the default value based on blockchain if it is not specified as a flag. This part is only related to flags and doesn't need the config file value. Then there is the part where the cache amount is 'sanitized'. We need to apply that to the config file as well. Maybe it should be moved to cmd/utils/flags.go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config file is loaded first here since this code is executed before the config file is normally processed.

From my understanding the problem is the cache has to be set early here before the p2p networking is setup.

I'm still new to the codebase so please let me know how you'd prefer it to be implemented.

Copy link
Contributor

@fjl fjl Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Geth startup works as follows (see it here).

  1. pre-setup (everything that runs before makeConfigNode)
  2. config file is loaded
  3. flags related to node.Config are processed and override values in config
  4. node.Node object is constructed
  5. flags related to ethconfig.Config are processed and override values in config
  6. eth.Ethereum object is constructed and registered in node
  7. node is started

I think this code here runs during the pre-setup, which is the wrong place to adjust anything in the config.
To make it work properly, this code needs to run during phase 3 or phase 5. The code for those phases is in package cmd/utils. This is why I suggest that the adjusting of the cache amount should be moved there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we discussed this PR in the team today, someone said that adding the Cache field to node.Config is a bad idea. I agree, because we already have config fields for the cache amount in ethconfig.Config:

DatabaseCache: 512,

So what really needs to happen here is: the sanity checking of the database cache amount needs to be moved into phase 5, i.e. in the SetEthConfig function

@fjl fjl changed the title all: Fix cache variable with config files cmd/geth: fix cache variable with config files Mar 16, 2021
@fjl fjl removed the status:triage label Mar 16, 2021
@petesimard petesimard closed this Mar 16, 2021
@petesimard
Copy link
Contributor Author

Created new pull request with different approach

#22510

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache config in config file is useless for mainnet

3 participants