From f2e9c0de7e5030c9178add5fe3ddd1a5d2ea502e Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Sun, 8 Dec 2024 12:02:50 -0600 Subject: [PATCH 1/5] improve rate logging --- tools/benchmark/client/cli/tx.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/benchmark/client/cli/tx.go b/tools/benchmark/client/cli/tx.go index b92ca0c7dcd3..e1f46d0aaf0a 100644 --- a/tools/benchmark/client/cli/tx.go +++ b/tools/benchmark/client/cli/tx.go @@ -62,8 +62,8 @@ func NewLoadTestCmd(params *modulev1.GeneratorParams) *cobra.Command { }() var ( - successCount uint64 - errCount uint64 + successCount int + errCount int since = time.Now() last int ) @@ -110,6 +110,7 @@ func NewLoadTestCmd(params *modulev1.GeneratorParams) *cobra.Command { }() i := 0 + begin := time.Now() ops := make([]*benchmark.Op, numOps) for { select { @@ -119,10 +120,13 @@ func NewLoadTestCmd(params *modulev1.GeneratorParams) *cobra.Command { } if time.Since(since) > 5*time.Second { cmd.Printf( - "success_tx=%d err_tx=%d seq=%d rate=%.2f/s\n", - successCount, errCount, accSeq, float64(i-last)/time.Since(since).Seconds()) + "success_tx=%d err_tx=%d seq=%d rate=%.2f/s overall=%.2f/s\n", + successCount, errCount, accSeq, + float64(successCount-last)/time.Since(since).Seconds(), + float64(successCount)/time.Since(begin).Seconds(), + ) since = time.Now() - last = i + last = successCount } for j := range numOps { From 0693d8c5c655e7b8324442ee5ab23449286f2b87 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 10 Dec 2024 16:52:47 -0600 Subject: [PATCH 2/5] go mod tidy all --- simapp/v2/go.mod | 2 +- tools/benchmark/go.mod | 4 ++-- tools/benchmark/go.sum | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/simapp/v2/go.mod b/simapp/v2/go.mod index cfcc5b7d19c1..4129553481f1 100644 --- a/simapp/v2/go.mod +++ b/simapp/v2/go.mod @@ -43,8 +43,8 @@ require ( ) require ( - cosmossdk.io/tools/benchmark v0.0.0-00010101000000-000000000000 cosmossdk.io/indexer/postgres v0.0.0-20241204160609-556102cfa046 + cosmossdk.io/tools/benchmark v0.0.0-00010101000000-000000000000 cosmossdk.io/x/accounts/defaults/base v0.0.0-00010101000000-000000000000 cosmossdk.io/x/accounts/defaults/lockup v0.0.0-00010101000000-000000000000 cosmossdk.io/x/accounts/defaults/multisig v0.0.0-00010101000000-000000000000 diff --git a/tools/benchmark/go.mod b/tools/benchmark/go.mod index 8af851297594..d4a143ad9142 100644 --- a/tools/benchmark/go.mod +++ b/tools/benchmark/go.mod @@ -22,7 +22,7 @@ require ( cosmossdk.io/collections v0.4.1-0.20241128094659-bd76b47e1d8b // indirect cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/math v1.4.0 // indirect - cosmossdk.io/schema v0.3.1-0.20241128094659-bd76b47e1d8b // indirect + cosmossdk.io/schema v0.4.0 // indirect cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect filippo.io/edwards25519 v1.1.0 // indirect @@ -89,7 +89,7 @@ require ( github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/linxGnu/grocksdb v1.9.3 // indirect - github.com/magiconair/properties v1.8.7 // indirect + github.com/magiconair/properties v1.8.9 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect diff --git a/tools/benchmark/go.sum b/tools/benchmark/go.sum index 91457b7e51b6..490fe724f419 100644 --- a/tools/benchmark/go.sum +++ b/tools/benchmark/go.sum @@ -18,8 +18,8 @@ cosmossdk.io/log v1.5.0 h1:dVdzPJW9kMrnAYyMf1duqacoidB9uZIl+7c6z0mnq0g= cosmossdk.io/log v1.5.0/go.mod h1:Tr46PUJjiUthlwQ+hxYtUtPn4D/oCZXAkYevBeh5+FI= cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ= cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk= -cosmossdk.io/schema v0.3.1-0.20241128094659-bd76b47e1d8b h1:svpFdulZRrYz+RTHu2u9CeKkMKrIHx5354vjiHerovo= -cosmossdk.io/schema v0.3.1-0.20241128094659-bd76b47e1d8b/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.4.0 h1:TrBs5BUnGqniAwEBVsjiisrAk3h3DK/zHLU1O8fRnO0= +cosmossdk.io/schema v0.4.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc h1:R9O9d75e0qZYUsVV0zzi+D7cNLnX2JrUOQNoIPaF0Bg= cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc/go.mod h1:amTTatOUV3u1PsKmNb87z6/galCxrRbz9kRdJkL0DyU= cosmossdk.io/x/tx v1.0.0-alpha.1 h1:5w61etWMQbdCSR7uveWXCnGnD5eQ/64B2vzIhqA80yo= @@ -297,8 +297,8 @@ github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/linxGnu/grocksdb v1.9.3 h1:s1cbPcOd0cU2SKXRG1nEqCOWYAELQjdqg3RVI2MH9ik= github.com/linxGnu/grocksdb v1.9.3/go.mod h1:QYiYypR2d4v63Wj1adOOfzglnoII0gLj3PNh4fZkcFA= -github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= -github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a8RkpQM= +github.com/magiconair/properties v1.8.9/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= From 91d4291389342f835f2c7c6f66859c19b542fd87 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 10 Dec 2024 18:06:09 -0600 Subject: [PATCH 3/5] add comments, some review fixes --- scripts/build/build.mk | 5 +++ simapp/app_config.go | 19 ++-------- simapp/app_di.go | 3 +- simapp/benchmark.go | 30 ++++++++++++++++ simapp/v2/app_config.go | 19 ++-------- simapp/v2/app_di.go | 3 +- simapp/v2/benchmark.go | 30 ++++++++++++++++ tools/benchmark/generator/gen.go | 35 ++++++++++++++++++- tools/benchmark/module/depinject.go | 1 - tools/benchmark/module/module.go | 5 +-- tools/benchmark/proto/buf.yaml | 2 +- .../cosmos/benchmark/module/v1/module.proto | 11 ++++++ 12 files changed, 120 insertions(+), 43 deletions(-) create mode 100644 simapp/benchmark.go create mode 100644 simapp/v2/benchmark.go diff --git a/scripts/build/build.mk b/scripts/build/build.mk index 581ee1dbe06d..da13b0e95e23 100644 --- a/scripts/build/build.mk +++ b/scripts/build/build.mk @@ -70,6 +70,11 @@ ifeq (bls12381,$(findstring bls12381,$(COSMOS_BUILD_OPTIONS))) build_tags += bls12381 endif +# benchmark module +ifeq (benchmark,$(findstring benchmark,$(COSMOS_BUILD_OPTIONS))) + build_tags += benchmark +endif + whitespace := whitespace += $(whitespace) comma := , diff --git a/simapp/app_config.go b/simapp/app_config.go index 45846b673aba..1eb1d5b16dd0 100644 --- a/simapp/app_config.go +++ b/simapp/app_config.go @@ -12,7 +12,6 @@ import ( authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" authzmodulev1 "cosmossdk.io/api/cosmos/authz/module/v1" bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1" - benchmarkmodulev1 "cosmossdk.io/api/cosmos/benchmark/module/v1" circuitmodulev1 "cosmossdk.io/api/cosmos/circuit/module/v1" consensusmodulev1 "cosmossdk.io/api/cosmos/consensus/module/v1" distrmodulev1 "cosmossdk.io/api/cosmos/distribution/module/v1" @@ -109,7 +108,7 @@ var ( } // application configuration (used by depinject) - appConfig = appconfig.Compose(&appv1alpha1.Config{ + appConfig = &appv1alpha1.Config{ Modules: []*appv1alpha1.ModuleConfig{ { Name: runtime.ModuleName, @@ -299,20 +298,6 @@ var ( Name: bankv2types.ModuleName, Config: appconfig.WrapAny(&bankmodulev2.Module{}), }, - { - Name: benchmark.ModuleName, - Config: appconfig.WrapAny(&benchmarkmodulev1.Module{ - GenesisParams: &benchmarkmodulev1.GeneratorParams{ - Seed: 34, - BucketCount: 1, - GenesisCount: 100, - KeyMean: 64, - KeyStdDev: 12, - ValueMean: 1024, - ValueStdDev: 256, - }, - }), - }, }, - }) + } ) diff --git a/simapp/app_di.go b/simapp/app_di.go index 90de295e8b7d..e57e2899d1c0 100644 --- a/simapp/app_di.go +++ b/simapp/app_di.go @@ -13,6 +13,7 @@ import ( "cosmossdk.io/core/registry" corestore "cosmossdk.io/core/store" "cosmossdk.io/depinject" + "cosmossdk.io/depinject/appconfig" _ "cosmossdk.io/indexer/postgres" // register the postgres indexer "cosmossdk.io/log" "cosmossdk.io/x/accounts" @@ -96,7 +97,7 @@ func init() { // AppConfig returns the default app config. func AppConfig() depinject.Config { return depinject.Configs( - appConfig, // Alternatively use appconfig.LoadYAML(AppConfigYAML) + appconfig.Compose(appConfig), // Alternatively use appconfig.LoadYAML(AppConfigYAML) depinject.Provide( ProvideExampleMintFn, // optional: override the mint module's mint function with epoched minting ), diff --git a/simapp/benchmark.go b/simapp/benchmark.go new file mode 100644 index 000000000000..64bb9e039ac8 --- /dev/null +++ b/simapp/benchmark.go @@ -0,0 +1,30 @@ +//go:build benchmark + +package simapp + +import ( + appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" + benchmarkmodulev1 "cosmossdk.io/api/cosmos/benchmark/module/v1" + "cosmossdk.io/depinject/appconfig" + benchmark "cosmossdk.io/tools/benchmark/module" +) + +func init() { + // WARNING! + // Enabling this module will produce 3M keys in the genesis state for the benchmark module. + // Will also enable processing of benchmark transactions which can easily overwhelm the system. + appConfig.Modules = append(appConfig.Modules, &appv1alpha1.ModuleConfig{ + Name: benchmark.ModuleName, + Config: appconfig.WrapAny(&benchmarkmodulev1.Module{ + GenesisParams: &benchmarkmodulev1.GeneratorParams{ + Seed: 34, + BucketCount: 3, + GenesisCount: 3_000_000, + KeyMean: 64, + KeyStdDev: 12, + ValueMean: 1024, + ValueStdDev: 256, + }, + }), + }) +} diff --git a/simapp/v2/app_config.go b/simapp/v2/app_config.go index b21565822ee0..b8271884fb5e 100644 --- a/simapp/v2/app_config.go +++ b/simapp/v2/app_config.go @@ -12,7 +12,6 @@ import ( authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" authzmodulev1 "cosmossdk.io/api/cosmos/authz/module/v1" bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1" - benchmarkmodulev1 "cosmossdk.io/api/cosmos/benchmark/module/v1" circuitmodulev1 "cosmossdk.io/api/cosmos/circuit/module/v1" consensusmodulev1 "cosmossdk.io/api/cosmos/consensus/module/v1" distrmodulev1 "cosmossdk.io/api/cosmos/distribution/module/v1" @@ -109,7 +108,7 @@ var ( } // ModuleConfig is the application module configuration used by depinject - ModuleConfig = appconfig.Compose(&appv1alpha1.Config{ + ModuleConfig = &appv1alpha1.Config{ Modules: []*appv1alpha1.ModuleConfig{ { Name: runtime.ModuleName, @@ -304,20 +303,6 @@ var ( Name: bankv2types.ModuleName, Config: appconfig.WrapAny(&bankmodulev2.Module{}), }, - { - Name: benchmark.ModuleName, - Config: appconfig.WrapAny(&benchmarkmodulev1.Module{ - GenesisParams: &benchmarkmodulev1.GeneratorParams{ - Seed: 34, - BucketCount: 1, - GenesisCount: 100, - KeyMean: 64, - KeyStdDev: 12, - ValueMean: 1024, - ValueStdDev: 256, - }, - }), - }, }, - }) + } ) diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index e78708807b33..601d641ad060 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -10,6 +10,7 @@ import ( "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" "cosmossdk.io/depinject" + "cosmossdk.io/depinject/appconfig" _ "cosmossdk.io/indexer/postgres" // register the postgres indexer "cosmossdk.io/log" "cosmossdk.io/runtime/v2" @@ -49,7 +50,7 @@ type SimApp[T transaction.Tx] struct { // AppConfig returns the default app config. func AppConfig() depinject.Config { return depinject.Configs( - ModuleConfig, // Alternatively use appconfig.LoadYAML(AppConfigYAML) + appconfig.Compose(ModuleConfig), // Alternatively use appconfig.LoadYAML(AppConfigYAML) runtime.DefaultServiceBindings(), codec.DefaultProviders, depinject.Provide( diff --git a/simapp/v2/benchmark.go b/simapp/v2/benchmark.go new file mode 100644 index 000000000000..25e5f9956003 --- /dev/null +++ b/simapp/v2/benchmark.go @@ -0,0 +1,30 @@ +//go:build benchmark + +package simapp + +import ( + appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" + benchmarkmodulev1 "cosmossdk.io/api/cosmos/benchmark/module/v1" + "cosmossdk.io/depinject/appconfig" + benchmark "cosmossdk.io/tools/benchmark/module" +) + +func init() { + // WARNING! + // Enabling this module will produce 3M keys in the genesis state for the benchmark module. + // Will also enable processing of benchmark transactions which can easily overwhelm the system. + ModuleConfig.Modules = append(ModuleConfig.Modules, &appv1alpha1.ModuleConfig{ + Name: benchmark.ModuleName, + Config: appconfig.WrapAny(&benchmarkmodulev1.Module{ + GenesisParams: &benchmarkmodulev1.GeneratorParams{ + Seed: 34, + BucketCount: 3, + GenesisCount: 3_000_000, + KeyMean: 64, + KeyStdDev: 12, + ValueMean: 1024, + ValueStdDev: 256, + }, + }), + }) +} diff --git a/tools/benchmark/generator/gen.go b/tools/benchmark/generator/gen.go index 1d473781cbab..c8c4e2c00c27 100644 --- a/tools/benchmark/generator/gen.go +++ b/tools/benchmark/generator/gen.go @@ -16,6 +16,7 @@ import ( "cosmossdk.io/tools/benchmark" ) +// Options is the configuration for the generator. type Options struct { *module.GeneratorParams // HomeDir is for reading/writing state @@ -27,6 +28,8 @@ type Options struct { DeleteWeight float64 } +// State is the state of the generator. +// It can be marshaled and unmarshaled to/from a binary format. type State struct { Src interface { rand.Source @@ -36,6 +39,7 @@ type State struct { Keys [][]Payload } +// Marshal writes the state to w. func (s *State) Marshal(w io.Writer) error { srcBz, err := s.Src.MarshalBinary() if err != nil { @@ -65,6 +69,7 @@ func (s *State) Marshal(w io.Writer) error { return nil } +// Unmarshal reads the state from r. func (s *State) Unmarshal(r io.Reader) error { srcBz := make([]byte, 20) if _, err := r.Read(srcBz); err != nil { @@ -95,6 +100,9 @@ func (s *State) Unmarshal(r io.Reader) error { return nil } +// Generator generates operations for a benchmark transaction. +// The generator is stateful, keeping track of which keys have been inserted +// so that meaningful gets and deletes can be generated. type Generator struct { Options @@ -104,6 +112,7 @@ type Generator struct { type opt func(*Generator) +// NewGenerator creates a new generator with the given options. func NewGenerator(opts Options, f ...opt) *Generator { g := &Generator{ Options: opts, @@ -118,6 +127,9 @@ func NewGenerator(opts Options, f ...opt) *Generator { return g } +// WithGenesis sets the generator state to the genesis seed. +// When the generator is created, it will sync to genesis state. +// The benchmark client needs to do this so that it can generate meaningful tx operations. func WithGenesis() func(*Generator) { return func(g *Generator) { // sync state to genesis seed @@ -130,6 +142,7 @@ func WithGenesis() func(*Generator) { } } +// WithSeed sets the seed for the generator. func WithSeed(seed uint64) func(*Generator) { return func(g *Generator) { g.state.Src = rand.NewPCG(seed, seed>>32) @@ -137,6 +150,7 @@ func WithSeed(seed uint64) func(*Generator) { } } +// Load loads the generator state from disk. func (g *Generator) Load() error { f := fmt.Sprintf("%s/data/generator_state.bin", g.HomeDir) r, err := os.Open(f) @@ -149,16 +163,22 @@ func (g *Generator) Load() error { return g.state.Unmarshal(r) } +// Payload is a 2-tuple of seed and length. +// A seed is uint64 which is used to generate a byte slice of size length. type Payload [2]uint64 +// Seed returns the seed in the payload. func (p Payload) Seed() uint64 { return p[0] } +// Length returns the length in the payload. func (p Payload) Length() uint64 { return p[1] } +// Bytes returns the byte slice generated from the seed and length. +// The underlying byte slice is deterministically generated using the (very fast) xxhash algorithm. func (p Payload) Bytes() []byte { return Bytes(p.Seed(), p.Length()) } @@ -171,6 +191,7 @@ func NewPayload(seed, length uint64) Payload { return Payload{seed, length} } +// KV is a key-value pair with a store key. type KV struct { StoreKey uint64 Key Payload @@ -194,6 +215,9 @@ func (g *Generator) setKey(bucket uint64, payload Payload) { g.state.Keys[bucket] = append(g.state.Keys[bucket], payload) } +// GenesisSet returns a sequence of key-value pairs for the genesis state. +// It is called by the server during InitGenesis to generate and set the initial state. +// The client uses WithGenesis to sync to the genesis state. func (g *Generator) GenesisSet() iter.Seq[*KV] { return func(yield func(*KV) bool) { for range g.GenesisCount { @@ -209,9 +233,12 @@ func (g *Generator) GenesisSet() iter.Seq[*KV] { } } +// Next generates the next benchmark operation. +// The operation is one of insert, update, get, or delete. +// The tx client calls this function to deterministically generate the next operation. func (g *Generator) Next() (uint64, *benchmark.Op, error) { if g.InsertWeight+g.UpdateWeight+g.GetWeight+g.DeleteWeight != 1 { - return 0, nil, fmt.Errorf("probabilities must sum to 1") + return 0, nil, fmt.Errorf("weights must sum to 1") } var ( @@ -265,6 +292,7 @@ func (g *Generator) Next() (uint64, *benchmark.Op, error) { return bucket, op, nil } +// NormUint64 returns a random uint64 with a normal distribution. func (g *Generator) NormUint64(mean, stdDev uint64) uint64 { return uint64(g.rand.NormFloat64()*float64(stdDev) + float64(mean)) } @@ -277,6 +305,7 @@ func (g *Generator) getLength(mean, stdDev uint64) uint64 { return length } +// UintN returns a random uint64 in the range [0, n). func (g *Generator) UintN(n uint64) uint64 { return g.rand.Uint64N(n) } @@ -305,6 +334,7 @@ func encodeUint64(x uint64) []byte { const maxStoreKeyGenIterations = 100 +// StoreKeys deterministically generates a set of unique store keys from seed. func StoreKeys(prefix string, seed, count uint64) ([]string, error) { r := rand.New(rand.NewPCG(seed, seed>>32)) keys := make([]string, count) @@ -323,10 +353,13 @@ func StoreKeys(prefix string, seed, count uint64) ([]string, error) { keys[i] = sk seen[sk] = struct{}{} i++ + j++ } return keys, nil } +// Bytes generates a byte slice of length length from seed. +// The byte slice is deterministically generated using the (very fast) xxhash algorithm. func Bytes(seed, length uint64) []byte { b := make([]byte, length) rounds := length / 8 diff --git a/tools/benchmark/module/depinject.go b/tools/benchmark/module/depinject.go index ffb9b653aa28..d09d98c895e1 100644 --- a/tools/benchmark/module/depinject.go +++ b/tools/benchmark/module/depinject.go @@ -17,7 +17,6 @@ const ModuleName = "benchmark" const maxStoreKeyGenIterations = 100 func init() { - // TODO try depinject gogo API appconfig.RegisterModule( &modulev1.Module{}, appconfig.Provide( diff --git a/tools/benchmark/module/module.go b/tools/benchmark/module/module.go index dfe1423b2d7b..ad40eb04e9d9 100644 --- a/tools/benchmark/module/module.go +++ b/tools/benchmark/module/module.go @@ -3,8 +3,6 @@ package module import ( "context" "encoding/json" - "fmt" - "github.com/cosmos/cosmos-sdk/types/msgservice" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -67,8 +65,7 @@ func (a *AppModule) InitGenesis(ctx context.Context, _ json.RawMessage) error { for kv := range g.GenesisSet() { i++ if i%100_000 == 0 { - fmt.Printf("init genesis: %d/%d\n", i, a.genesisParams.GenesisCount) - a.log.Warn("init genesis", "progress", i, "total", a.genesisParams.GenesisCount) + a.log.Warn("benchmark: init genesis", "progress", i, "total", a.genesisParams.GenesisCount) } sk := a.storeKeys[kv.StoreKey] key := gen.Bytes(kv.Key.Seed(), kv.Key.Length()) diff --git a/tools/benchmark/proto/buf.yaml b/tools/benchmark/proto/buf.yaml index 19fd0b6afb95..ae83b8045617 100644 --- a/tools/benchmark/proto/buf.yaml +++ b/tools/benchmark/proto/buf.yaml @@ -1,5 +1,5 @@ version: v1 -name: buf.build/mods/consensus +name: buf.build/mods/benchmark deps: - buf.build/cosmos/cosmos-sdk # pin the Cosmos SDK version - buf.build/cometbft/cometbft:4a62c99d422068a5165429b62a7eb824df46cca9 # CometBFT v0.38 diff --git a/tools/benchmark/proto/cosmos/benchmark/module/v1/module.proto b/tools/benchmark/proto/cosmos/benchmark/module/v1/module.proto index 2e22994cdf9b..c0bc93f0dfb5 100644 --- a/tools/benchmark/proto/cosmos/benchmark/module/v1/module.proto +++ b/tools/benchmark/proto/cosmos/benchmark/module/v1/module.proto @@ -15,18 +15,29 @@ message Module { // GenesisParams defines the genesis parameters for the benchmark module. message GeneratorParams { + // seed is the seed for the random number generator. uint64 seed = 1; + // bucket_count is the number of store keys to uniformly distribute genesis_count keys across. uint64 bucket_count = 2; + // key_mean is the mean size (in normal distribution) of keys in each bucket. uint64 key_mean = 3; + // key_std_dev is the standard deviation of key sizes in each bucket. uint64 key_std_dev = 4; + // value_mean is the mean size (in normal distribution) of values in each bucket. uint64 value_mean = 6; + // value_std_dev is the standard deviation of value sizes in each bucket. uint64 value_std_dev = 7; + // genesis_count is the number of keys to insert in the store, distributed across all buckets. uint64 genesis_count = 8; + // insert_weight is the weight of insert operations. float insert_weight = 9; + // update_weight is the weight of update operations. float update_weight = 10; + // get_weight is the weight of get operations. float get_weight = 12; + // delete_weight is the weight of delete operations. float delete_weight = 11; } \ No newline at end of file From 1d25773df8518d3dc40cad35ac4b35f97ac1d0c2 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Tue, 10 Dec 2024 19:05:43 -0600 Subject: [PATCH 4/5] fix init genesis order --- simapp/app_config.go | 2 -- simapp/benchmark.go | 9 +++++++++ simapp/v2/app_config.go | 2 -- simapp/v2/benchmark.go | 9 +++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/simapp/app_config.go b/simapp/app_config.go index 1eb1d5b16dd0..275c3f730fe0 100644 --- a/simapp/app_config.go +++ b/simapp/app_config.go @@ -31,7 +31,6 @@ import ( validatemodulev1 "cosmossdk.io/api/cosmos/validate/module/v1" vestingmodulev1 "cosmossdk.io/api/cosmos/vesting/module/v1" "cosmossdk.io/depinject/appconfig" - benchmark "cosmossdk.io/tools/benchmark/module" "cosmossdk.io/x/accounts" "cosmossdk.io/x/authz" _ "cosmossdk.io/x/authz/module" // import for side-effects @@ -175,7 +174,6 @@ var ( circuittypes.ModuleName, pooltypes.ModuleName, epochstypes.ModuleName, - benchmark.ModuleName, }, // When ExportGenesis is not specified, the export genesis module order // is equal to the init genesis order diff --git a/simapp/benchmark.go b/simapp/benchmark.go index 64bb9e039ac8..50a16ea909b8 100644 --- a/simapp/benchmark.go +++ b/simapp/benchmark.go @@ -3,10 +3,12 @@ package simapp import ( + runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" benchmarkmodulev1 "cosmossdk.io/api/cosmos/benchmark/module/v1" "cosmossdk.io/depinject/appconfig" benchmark "cosmossdk.io/tools/benchmark/module" + "fmt" ) func init() { @@ -27,4 +29,11 @@ func init() { }, }), }) + runtimeConfig := &runtimev1alpha1.Module{} + err := appConfig.Modules[0].Config.UnmarshalTo(runtimeConfig) + if err != nil { + panic(fmt.Errorf("benchmark init: failed to unmarshal runtime module config: %w", err)) + } + runtimeConfig.InitGenesis = append(runtimeConfig.InitGenesis, benchmark.ModuleName) + appConfig.Modules[0].Config = appconfig.WrapAny(runtimeConfig) } diff --git a/simapp/v2/app_config.go b/simapp/v2/app_config.go index b8271884fb5e..0681354b549e 100644 --- a/simapp/v2/app_config.go +++ b/simapp/v2/app_config.go @@ -31,7 +31,6 @@ import ( validatemodulev1 "cosmossdk.io/api/cosmos/validate/module/v1" vestingmodulev1 "cosmossdk.io/api/cosmos/vesting/module/v1" "cosmossdk.io/depinject/appconfig" - benchmark "cosmossdk.io/tools/benchmark/module" "cosmossdk.io/x/accounts" "cosmossdk.io/x/authz" _ "cosmossdk.io/x/authz/module" // import for side-effects @@ -174,7 +173,6 @@ var ( circuittypes.ModuleName, pooltypes.ModuleName, epochstypes.ModuleName, - benchmark.ModuleName, }, // When ExportGenesis is not specified, the export genesis module order // is equal to the init genesis order diff --git a/simapp/v2/benchmark.go b/simapp/v2/benchmark.go index 25e5f9956003..85376b02cb83 100644 --- a/simapp/v2/benchmark.go +++ b/simapp/v2/benchmark.go @@ -3,10 +3,12 @@ package simapp import ( + runtimev2 "cosmossdk.io/api/cosmos/app/runtime/v2" appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" benchmarkmodulev1 "cosmossdk.io/api/cosmos/benchmark/module/v1" "cosmossdk.io/depinject/appconfig" benchmark "cosmossdk.io/tools/benchmark/module" + "fmt" ) func init() { @@ -27,4 +29,11 @@ func init() { }, }), }) + runtimeConfig := &runtimev2.Module{} + err := ModuleConfig.Modules[0].Config.UnmarshalTo(runtimeConfig) + if err != nil { + panic(fmt.Errorf("benchmark init: failed to unmarshal runtime module config: %w", err)) + } + runtimeConfig.InitGenesis = append(runtimeConfig.InitGenesis, benchmark.ModuleName) + ModuleConfig.Modules[0].Config = appconfig.WrapAny(runtimeConfig) } From 256ca9342b9743921151960febb370113aa4abb3 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Wed, 11 Dec 2024 10:22:18 -0600 Subject: [PATCH 5/5] a store/v1 replace directive is required --- tools/benchmark/go.mod | 3 ++- tools/benchmark/go.sum | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/benchmark/go.mod b/tools/benchmark/go.mod index d4a143ad9142..3f84dfb70325 100644 --- a/tools/benchmark/go.mod +++ b/tools/benchmark/go.mod @@ -20,6 +20,7 @@ require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.2-20241120201313-68e42a58b301.1 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88ef6483f90f.1 // indirect cosmossdk.io/collections v0.4.1-0.20241128094659-bd76b47e1d8b // indirect + cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e // indirect cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/math v1.4.0 // indirect cosmossdk.io/schema v0.4.0 // indirect @@ -48,7 +49,6 @@ require ( github.com/cometbft/cometbft-db v1.0.1 // indirect github.com/cometbft/cometbft/api v1.0.0-rc2 // indirect github.com/cosmos/btcutil v1.0.5 // indirect - github.com/cosmos/cosmos-db v1.1.0 // indirect github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/iavl v1.3.2 // indirect @@ -151,6 +151,7 @@ require ( replace ( cosmossdk.io/api => ../../api + cosmossdk.io/store => ../../store cosmossdk.io/x/bank => ../../x/bank cosmossdk.io/x/staking => ../../x/staking github.com/cosmos/cosmos-sdk => ../../ diff --git a/tools/benchmark/go.sum b/tools/benchmark/go.sum index 490fe724f419..95258663a3cb 100644 --- a/tools/benchmark/go.sum +++ b/tools/benchmark/go.sum @@ -20,8 +20,6 @@ cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ= cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk= cosmossdk.io/schema v0.4.0 h1:TrBs5BUnGqniAwEBVsjiisrAk3h3DK/zHLU1O8fRnO0= cosmossdk.io/schema v0.4.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= -cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc h1:R9O9d75e0qZYUsVV0zzi+D7cNLnX2JrUOQNoIPaF0Bg= -cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc/go.mod h1:amTTatOUV3u1PsKmNb87z6/galCxrRbz9kRdJkL0DyU= cosmossdk.io/x/tx v1.0.0-alpha.1 h1:5w61etWMQbdCSR7uveWXCnGnD5eQ/64B2vzIhqA80yo= cosmossdk.io/x/tx v1.0.0-alpha.1/go.mod h1:xlJjZV1wxZBTCP+ygZx9pNT/XxsfHDPf1H0VhHaUp5w= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=