From 6fd448a90cadd23be760e173e440c12901687492 Mon Sep 17 00:00:00 2001 From: ptrus Date: Thu, 26 Mar 2020 14:13:08 +0100 Subject: [PATCH] txsource/queries: increase the odds of querying the latest height --- .changelog/2787.internal.md | 1 + go/oasis-node/cmd/debug/txsource/workload/queries.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .changelog/2787.internal.md diff --git a/.changelog/2787.internal.md b/.changelog/2787.internal.md new file mode 100644 index 00000000000..902ed53e601 --- /dev/null +++ b/.changelog/2787.internal.md @@ -0,0 +1 @@ +txsource/queries: increase the odds of querying the latest height diff --git a/go/oasis-node/cmd/debug/txsource/workload/queries.go b/go/oasis-node/cmd/debug/txsource/workload/queries.go index 168dadf03d3..9d0465f58d3 100644 --- a/go/oasis-node/cmd/debug/txsource/workload/queries.go +++ b/go/oasis-node/cmd/debug/txsource/workload/queries.go @@ -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. @@ -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)) @@ -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