Skip to content

Commit

Permalink
sql: dont read dbstat by default (#5067)
Browse files Browse the repository at this point in the history
this is debug information and can be enabled to be collected.
moreover reading dbstat frequently can interfere with other workloads.
  • Loading branch information
dshulyak committed Sep 25, 2023
1 parent ca91fc5 commit 6513733
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ Support for old certificate sync protocol is dropped. This update is incompatibl
### Features

* [#5031](https://github.com/spacemeshos/go-spacemesh/pull/5031) Nodes will also fetch from PoET 112 for round 4 if they were able to register to PoET 110.
* [#5067](https://github.com/spacemeshos/go-spacemesh/pull/5067) dbstat virtual table can be read periodically to collect table/index sizes.

In order to enable provide following configuration:
```json
"main": {
"db-size-metering-interval": "10m"
}
```

### Improvements

Expand Down
38 changes: 20 additions & 18 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ type BaseConfig struct {
OptFilterThreshold int `mapstructure:"optimistic-filtering-threshold"`
TickSize uint64 `mapstructure:"tick-size"`

DatabaseConnections int `mapstructure:"db-connections"`
DatabaseLatencyMetering bool `mapstructure:"db-latency-metering"`
DatabasePruneInterval time.Duration `mapstructure:"db-prune-interval"`
DatabaseConnections int `mapstructure:"db-connections"`
DatabaseLatencyMetering bool `mapstructure:"db-latency-metering"`
DatabaseSizeMeteringInterval time.Duration `mapstructure:"db-size-metering-interval"`
DatabasePruneInterval time.Duration `mapstructure:"db-prune-interval"`

NetworkHRP string `mapstructure:"network-hrp"`

Expand Down Expand Up @@ -174,21 +175,22 @@ func DefaultTestConfig() Config {
// DefaultBaseConfig returns a default configuration for spacemesh.
func defaultBaseConfig() BaseConfig {
return BaseConfig{
DataDirParent: defaultDataDir,
FileLock: filepath.Join(os.TempDir(), "spacemesh.lock"),
CollectMetrics: false,
MetricsPort: 1010,
ProfilerName: "gp-spacemesh",
LayerDuration: 30 * time.Second,
LayersPerEpoch: 3,
PoETServers: []string{"127.0.0.1"},
TxsPerProposal: 100,
BlockGasLimit: math.MaxUint64,
OptFilterThreshold: 90,
TickSize: 100,
DatabaseConnections: 16,
DatabasePruneInterval: 30 * time.Minute,
NetworkHRP: "sm",
DataDirParent: defaultDataDir,
FileLock: filepath.Join(os.TempDir(), "spacemesh.lock"),
CollectMetrics: false,
MetricsPort: 1010,
ProfilerName: "gp-spacemesh",
LayerDuration: 30 * time.Second,
LayersPerEpoch: 3,
PoETServers: []string{"127.0.0.1"},
TxsPerProposal: 100,
BlockGasLimit: math.MaxUint64,
OptFilterThreshold: 90,
TickSize: 100,
DatabaseConnections: 16,
DatabaseSizeMeteringInterval: 10 * time.Minute,
DatabasePruneInterval: 30 * time.Minute,
NetworkHRP: "sm",
}
}

Expand Down
11 changes: 6 additions & 5 deletions config/presets/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ func testnet() config.Config {
defaultdir := filepath.Join(home, "spacemesh-testnet", "/")
return config.Config{
BaseConfig: config.BaseConfig{
DataDirParent: defaultdir,
FileLock: filepath.Join(os.TempDir(), "spacemesh.lock"),
MetricsPort: 1010,
DatabaseConnections: 16,
NetworkHRP: "stest",
DataDirParent: defaultdir,
FileLock: filepath.Join(os.TempDir(), "spacemesh.lock"),
MetricsPort: 1010,
DatabaseConnections: 16,
DatabaseSizeMeteringInterval: 10 * time.Minute,
NetworkHRP: "stest",

LayerDuration: 5 * time.Minute,
LayerAvgSize: 50,
Expand Down
4 changes: 2 additions & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1341,8 +1341,8 @@ func (app *App) setupDBs(ctx context.Context, lg log.Log) error {
return fmt.Errorf("open sqlite db %w", err)
}
app.db = sqlDB
if app.Config.CollectMetrics {
app.dbMetrics = dbmetrics.NewDBMetricsCollector(ctx, sqlDB, app.addLogger(StateDbLogger, lg), 5*time.Minute)
if app.Config.CollectMetrics && app.Config.DatabaseSizeMeteringInterval != 0 {
app.dbMetrics = dbmetrics.NewDBMetricsCollector(ctx, sqlDB, app.addLogger(StateDbLogger, lg), app.Config.DatabaseSizeMeteringInterval)
}
app.cachedDB = datastore.NewCachedDB(sqlDB, app.addLogger(CachedDBLogger, lg), datastore.WithConfig(app.Config.Cache))
return nil
Expand Down

0 comments on commit 6513733

Please sign in to comment.