Skip to content

Commit

Permalink
txsource/queries: increase the odds of querying the latest height
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Mar 26, 2020
1 parent 504394e commit 6fd448a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions .changelog/2787.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
txsource/queries: increase the odds of querying the latest height
10 changes: 8 additions & 2 deletions go/oasis-node/cmd/debug/txsource/workload/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const (

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

// QueriesFlags are the queries workload flags.
Expand Down Expand Up @@ -339,6 +341,8 @@ func (q *queries) doRuntimeQueries(ctx context.Context, rng *rand.Rand) error {
switch {
case p < queriesEarliestHeightRatio:
round = 1
case p < queriesEarliestHeightRatio+queriesLatestHeightRatio:
round = latestRound
default:
// [1, latestRound]
round = uint64(rng.Int63n(int64(latestRound) + 1))
Expand Down Expand Up @@ -425,13 +429,15 @@ func (q *queries) Run(gracefulExit context.Context, rng *rand.Rand, conn *grpc.C
earliestHeight = block.Height - numKept
}

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

0 comments on commit 6fd448a

Please sign in to comment.