From 4e48b60489d064fe1d4de6adc6d909fde393e52e Mon Sep 17 00:00:00 2001 From: Dmitry Shulyak Date: Mon, 25 Sep 2023 09:47:08 +0000 Subject: [PATCH] sql: dont read dbstat by default (#5067) this is debug information and can be enabled to be collected. moreover reading dbstat frequently can interfere with other workloads. --- CHANGELOG.md | 16 ++++++++++++++++ config/config.go | 34 ++++++++++++++++++---------------- node/node.go | 4 ++-- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd8bb5daa1..27eed8d980 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,22 @@ See [RELEASE](./RELEASE.md) for workflow instructions. + +## UNRELEASED + +### Features + +* [#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 + ## v1.1.8 ### Improvements diff --git a/config/config.go b/config/config.go index a035fb5762..592bb4aa8d 100644 --- a/config/config.go +++ b/config/config.go @@ -109,8 +109,9 @@ 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"` + DatabaseConnections int `mapstructure:"db-connections"` + DatabaseLatencyMetering bool `mapstructure:"db-latency-metering"` + DatabaseSizeMeteringInterval time.Duration `mapstructure:"db-size-metering-interval"` NetworkHRP string `mapstructure:"network-hrp"` @@ -174,20 +175,21 @@ 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, - 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, + NetworkHRP: "sm", } } diff --git a/node/node.go b/node/node.go index 5396ed3016..db8e6fd09d 100644 --- a/node/node.go +++ b/node/node.go @@ -1339,8 +1339,8 @@ func (app *App) setupDBs(ctx context.Context, lg log.Log, dbPath string) 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