Skip to content

Commit

Permalink
a bit working
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski committed Nov 6, 2024
1 parent 8774211 commit efd0022
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 48 deletions.
1 change: 1 addition & 0 deletions scripts/init-simapp-v2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ $SIMD_BIN config set client chain-id simapp-v2-chain
$SIMD_BIN config set client keyring-backend test
$SIMD_BIN config set client keyring-default-keyname alice
$SIMD_BIN config set app rest.enable true
$SIMD_BIN config set app telemetry.prometheus-retention-time 600
$SIMD_BIN keys add alice --indiscreet
$SIMD_BIN keys add bob --indiscreet
$SIMD_BIN init simapp-v2-node --chain-id simapp-v2-chain
Expand Down
3 changes: 3 additions & 0 deletions scripts/init-simapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ $SIMD_BIN config set client chain-id demo
$SIMD_BIN config set client keyring-backend test
$SIMD_BIN config set client keyring-default-keyname alice
$SIMD_BIN config set app api.enable true
$SIMD_BIN config set app telemetry.enabled true
$SIMD_BIN config set app telemetry.prometheus-retention-time 600
$SIMD_BIN config set config instrumentation.prometheus true
$SIMD_BIN keys add alice --indiscreet
$SIMD_BIN keys add bob --indiscreet
$SIMD_BIN init test --chain-id demo
Expand Down
2 changes: 1 addition & 1 deletion simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ var (
GenesisParams: &benchmarkmodulev1.GenesisParams{
Seed: 34,
StoreKeyCount: 10,
KeyCount: 10_000_000,
KeyCount: 100_000,
KeyMeanLength: 64,
KeyStdDevLength: 12,
ValueMeanLength: 1024,
Expand Down
2 changes: 1 addition & 1 deletion simapp/v2/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ var (
GenesisParams: &benchmarkmodulev1.GenesisParams{
Seed: 34,
StoreKeyCount: 10,
KeyCount: 10_000_000,
KeyCount: 100_000,
KeyMeanLength: 64,
KeyStdDevLength: 12,
ValueMeanLength: 1024,
Expand Down
2 changes: 1 addition & 1 deletion simapp/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ require (
)

require (
cosmossdk.io/server/v2/stf v0.0.0-20240708142107-25e99c54bac1
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
Expand All @@ -65,6 +64,7 @@ require (
cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 // indirect
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect
cosmossdk.io/server/v2/appmanager v0.0.0-20240802110823-cffeedff643d // indirect
cosmossdk.io/server/v2/stf v0.0.0-20240708142107-25e99c54bac1 // indirect
cosmossdk.io/store v1.1.1 // indirect
cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
Expand Down
4 changes: 3 additions & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cosmos/cosmos-sdk/tests

go 1.23.1
go 1.23.2

require (
cosmossdk.io/api v0.7.6
Expand Down Expand Up @@ -72,6 +72,7 @@ require (
cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 // indirect
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect
cosmossdk.io/server/v2/appmanager v0.0.0-00010101000000-000000000000 // indirect
cosmossdk.io/x/benchmark v0.0.0-00010101000000-000000000000 // indirect
cosmossdk.io/x/circuit v0.0.0-20230613133644-0a778132a60f // indirect
cosmossdk.io/x/epochs v0.0.0-20240522060652-a1ae4c3e0337 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
Expand Down Expand Up @@ -254,6 +255,7 @@ replace (
cosmossdk.io/x/accounts/defaults/multisig => ../x/accounts/defaults/multisig
cosmossdk.io/x/authz => ../x/authz
cosmossdk.io/x/bank => ../x/bank
cosmossdk.io/x/benchmark => ../x/benchmark
cosmossdk.io/x/circuit => ../x/circuit
cosmossdk.io/x/consensus => ../x/consensus
cosmossdk.io/x/distribution => ../x/distribution
Expand Down
54 changes: 50 additions & 4 deletions x/benchmark/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package cli

import (
"context"
"os"
"os/signal"
"syscall"

"cosmossdk.io/x/benchmark"
gen "cosmossdk.io/x/benchmark/generator"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand All @@ -27,16 +33,56 @@ func NewTxCmd() *cobra.Command {

func NewLoadTestCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "load-test [from_key_or_address]",
Args: cobra.ExactArgs(3),
Use: "load-test [from_key_or_address]",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := &benchmark.MsgLoadTest{Caller: clientCtx.FromAddress}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
ctx, cancelFn := context.WithCancel(cmd.Context())
go func() {
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
select {
case sig := <-sigCh:
cancelFn()
cmd.Printf("caught %s signal\n", sig.String())
case <-ctx.Done():
cancelFn()
}
}()

// TODO: fetch or share state from genesis
seed := uint64(34)
storeKeyCount := uint64(10)
storeKeys, err := gen.StoreKeys("benchmark", seed, storeKeyCount)
if err != nil {
return err
}

g := gen.NewGenerator(gen.Options{
Seed: 34,
KeyMean: 64,
KeyStdDev: 8,
ValueMean: 1024,
ValueStdDev: 256,
BucketCount: storeKeyCount,
})
for {
select {
case <-ctx.Done():
return nil
default:
}
op, ski := g.Next()
op.Actor = storeKeys[ski]
msg := &benchmark.MsgLoadTest{
Caller: clientCtx.FromAddress,
Ops: []*benchmark.Op{op},
}
tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
}
},
}

Expand Down
45 changes: 40 additions & 5 deletions x/benchmark/generator/gen.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gen

import (
"fmt"
"math/rand/v2"

"github.com/cespare/xxhash/v2"
Expand All @@ -17,6 +18,8 @@ type Options struct {
ValueStdDev uint64

DeleteFraction float64

BucketCount uint64
}

type State struct {
Expand All @@ -26,20 +29,27 @@ type State struct {
type Generator struct {
Options

digest *xxhash.Digest
rand *rand.Rand
rand *rand.Rand
}

func NewGenerator(opts Options) *Generator {
return &Generator{
Options: opts,
digest: xxhash.New(),
rand: rand.New(rand.NewPCG(opts.Seed, opts.Seed>>32)),
}
}

func (g *Generator) Next() (*benchmark.Op, error) {
return nil, nil
func (g *Generator) Next() (*benchmark.Op, uint64) {
op := &benchmark.Op{
Seed: g.rand.Uint64(),
KeyLength: g.NormUint64(g.KeyMean, g.KeyStdDev),
ValueLength: g.NormUint64(g.ValueMean, g.ValueStdDev),
}
if op.KeyLength == 0 {
op.KeyLength = 1
}

return op, g.rand.Uint64N(g.BucketCount)
}

func (g *Generator) Bytes(seed, length uint64) []byte {
Expand Down Expand Up @@ -100,3 +110,28 @@ func encodeUint64(x uint64) []byte {
b[7] = byte(x >> 56)
return b[:]
}

const maxStoreKeyGenIterations = 100

func StoreKeys(prefix string, seed, count uint64) ([]string, error) {
g := NewGenerator(Options{})
r := rand.New(rand.NewPCG(seed, seed>>32))
keys := make([]string, count)
seen := make(map[string]struct{})

var i, j uint64
for i < count {
if j > maxStoreKeyGenIterations {
return nil, fmt.Errorf("failed to generate %d unique store keys", count)
}
sk := fmt.Sprintf("%s_%x", prefix, g.Bytes(r.Uint64(), 8))
if _, ok := seen[sk]; ok {
j++
continue
}
keys[i] = sk
seen[sk] = struct{}{}
i++
}
return keys, nil
}
13 changes: 6 additions & 7 deletions x/benchmark/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ go 1.23.2
require (
cosmossdk.io/api v0.7.6
cosmossdk.io/core v1.0.0-alpha.5
cosmossdk.io/depinject v1.0.0
cosmossdk.io/depinject v1.1.0
cosmossdk.io/log v1.4.1
github.com/cespare/xxhash/v2 v2.3.0
github.com/cosmos/cosmos-sdk v0.53.0
github.com/cosmos/gogoproto v1.7.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.67.1
)

Expand All @@ -17,7 +21,6 @@ require (
buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.4.1 // indirect
cosmossdk.io/math v1.3.0 // indirect
cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect
cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc // indirect
Expand All @@ -29,8 +32,6 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.2.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cockroachdb/errors v1.11.3 // indirect
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
Expand All @@ -45,7 +46,7 @@ require (
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
github.com/cosmos/crypto v0.1.2 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/iavl v1.3.0 // indirect
github.com/cosmos/iavl v1.3.1 // indirect
github.com/cosmos/ics23/go v0.11.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/danieljoos/wincred v1.2.1 // indirect
Expand Down Expand Up @@ -107,10 +108,8 @@ require (
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.13 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
Expand Down
12 changes: 4 additions & 8 deletions x/benchmark/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s=
cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0=
cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY=
cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs=
cosmossdk.io/depinject v1.0.0 h1:dQaTu6+O6askNXO06+jyeUAnF2/ssKwrrszP9t5q050=
cosmossdk.io/depinject v1.0.0/go.mod h1:zxK/h3HgHoA/eJVtiSsoaRaRA2D5U4cJ5thIG4ssbB8=
cosmossdk.io/depinject v1.1.0 h1:wLan7LG35VM7Yo6ov0jId3RHWCGRhe8E8bsuARorl5E=
cosmossdk.io/depinject v1.1.0/go.mod h1:kkI5H9jCGHeKeYWXTqYdruogYrEeWvBQCw1Pj4/eCFI=
cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0=
cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U=
cosmossdk.io/log v1.4.1 h1:wKdjfDRbDyZRuWa8M+9nuvpVYxrEOwbD/CA8hvhU8QM=
Expand All @@ -36,7 +36,6 @@ github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ=
github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE=
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand All @@ -57,8 +56,6 @@ github.com/btcsuite/btcd/btcutil v1.1.6/go.mod h1:9dFymx8HpuLqBnsPELrImQeTQfKBQq
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
Expand Down Expand Up @@ -104,8 +101,8 @@ github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiK
github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ4GUkT+tbFI=
github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fro=
github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0=
github.com/cosmos/iavl v1.3.0 h1:Ezaxt8aPA3kbkhsfyqwenChGLQwHDAIif3tG9x1FMV8=
github.com/cosmos/iavl v1.3.0/go.mod h1:T6SfBcyhulVIY2G/ZtAtQm/QiJvsuhIos52V4dWYk88=
github.com/cosmos/iavl v1.3.1 h1:+W1G2uSUtJMqMGpwz/fKiwZxY2DDT/9/0hyNLm6Geu0=
github.com/cosmos/iavl v1.3.1/go.mod h1:T6SfBcyhulVIY2G/ZtAtQm/QiJvsuhIos52V4dWYk88=
github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU=
github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0=
github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM=
Expand Down Expand Up @@ -393,7 +390,6 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
Expand Down
28 changes: 8 additions & 20 deletions x/benchmark/module/depinject.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package module

import (
"cosmossdk.io/depinject"
"fmt"
"math/rand/v2"
"unsafe"

"cosmossdk.io/depinject"

modulev1 "cosmossdk.io/api/cosmos/benchmark/module/v1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/store"
Expand Down Expand Up @@ -44,31 +43,20 @@ func ProvideModule(
in Input,
) (appmodule.AppModule, error) {
cfg := in.Cfg
g := gen.NewGenerator(gen.Options{Seed: cfg.GenesisParams.Seed})
r := rand.New(rand.NewPCG(cfg.GenesisParams.Seed, cfg.GenesisParams.Seed>>32))
kvMap := make(KVServiceMap)
storeKeys := make([]string, cfg.GenesisParams.StoreKeyCount)

var i, j uint64
for i < cfg.GenesisParams.StoreKeyCount {
if j > maxStoreKeyGenIterations {
return nil, fmt.Errorf("failed to generate %d unique store keys", cfg.GenesisParams.StoreKeyCount)
}
sk := fmt.Sprintf("%s_%x", ModuleName, g.Bytes(r.Uint64(), 8))
if _, ok := kvMap[sk]; ok {
j++
continue
}
storeKeys, err := gen.StoreKeys(ModuleName, cfg.GenesisParams.Seed, cfg.GenesisParams.StoreKeyCount)
if err != nil {
return nil, err
}
for _, sk := range storeKeys {
// app v2 case
if in.Registrar != nil {
in.Registrar.RegisterKey(sk)
}
kvService := in.StoreFactory(unsafeStrToBytes(sk))
kvMap[sk] = kvService
storeKeys[i] = sk
i++
j++
}

return NewAppModule(cfg.GenesisParams, storeKeys, kvMap, in.Logger), nil
}

Expand Down
Loading

0 comments on commit efd0022

Please sign in to comment.