Skip to content

Commit

Permalink
txsource/workload/queries: Add num last kept versions argument
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Mar 25, 2020
1 parent c894604 commit 2520189
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions .changelog/2674.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
txsource/workload/queries: Add num last kept versions argument
2 changes: 1 addition & 1 deletion go/oasis-node/cmd/debug/txsource/txsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func init() {
_ = viper.BindPFlags(fs)
txsourceCmd.Flags().AddFlagSet(fs)

txsourceCmd.Flags().AddFlagSet(workload.RuntimeFlags)
txsourceCmd.Flags().AddFlagSet(workload.Flags)
txsourceCmd.Flags().AddFlagSet(cmdGrpc.ClientFlags)
txsourceCmd.Flags().AddFlagSet(cmdFlags.DebugTestEntityFlags)
txsourceCmd.Flags().AddFlagSet(cmdFlags.GenesisFileFlags)
Expand Down
27 changes: 23 additions & 4 deletions go/oasis-node/cmd/debug/txsource/workload/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math/rand"
"time"

flag "github.com/spf13/pflag"
"github.com/spf13/viper"
"google.golang.org/grpc"

Expand All @@ -27,10 +28,17 @@ const (
// NameQueries is the name of the queries workload.
NameQueries = "queries"

// CfgNumKeptVersions is the number of last versions that the nodes are keeping (e.g., due to
// a configured pruning policy). Versions older than that will not be queried.
CfgNumKeptVersions = "queries.num_kept_versions"

// Ratio of queries that should query height 1.
queriesEarliestHeightRatio = 0.1
)

// QueriesFlags are the queries workload flags.
var QueriesFlags = flag.NewFlagSet("", flag.ContinueOnError)

type queries struct {
logger *logging.Logger

Expand Down Expand Up @@ -408,16 +416,22 @@ func (q *queries) Run(gracefulExit context.Context, rng *rand.Rand, conn *grpc.C
return fmt.Errorf("consensus.GetBlock error: %w", err)
}

// Select height at which queries should be done. Earliest (height=1)
// Determine the earliest height that we can query.
earliestHeight := int64(1)
if numKept := viper.GetInt64(CfgNumKeptVersions); numKept > 0 {
earliestHeight = block.Height - numKept
}

// Select height at which queries should be done. Earliest
// is special cased with increased probability.
var height int64
p := rng.Float32()
switch {
case p < queriesEarliestHeightRatio:
height = 1
height = earliestHeight
default:
// [1, block.Height]
height = rng.Int63n(block.Height) + 1
// [earliestHeight, block.Height]
height = rng.Int63n(block.Height-earliestHeight+1) + earliestHeight
}

q.logger.Debug("Doing queries",
Expand Down Expand Up @@ -454,3 +468,8 @@ func (q *queries) Run(gracefulExit context.Context, rng *rand.Rand, conn *grpc.C
}
}
}

func init() {
QueriesFlags.Int64(CfgNumKeptVersions, 0, "Number of last versions kept by nodes")
_ = viper.BindPFlags(QueriesFlags)
}
9 changes: 9 additions & 0 deletions go/oasis-node/cmd/debug/txsource/workload/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/cenkalti/backoff/v4"
flag "github.com/spf13/pflag"
"google.golang.org/grpc"

"github.com/oasislabs/oasis-core/go/common/crypto/signature"
Expand Down Expand Up @@ -183,3 +184,11 @@ var ByName = map[string]Workload{
NameRuntime: &runtime{},
NameTransfer: &transfer{},
}

// Flags has the workload flags.
var Flags = flag.NewFlagSet("", flag.ContinueOnError)

func init() {
Flags.AddFlagSet(QueriesFlags)
Flags.AddFlagSet(RuntimeFlags)
}

0 comments on commit 2520189

Please sign in to comment.