Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpc: Fix response time grow over time (#3537)
* rpc: store validator info periodly * increase ValidatorSetStoreInterval also - unexpose it - add a comment - refactor code - add a benchmark, which shows that 100000 results in ~ 100ms to get 100 validators * make the change non-breaking * expand comment * rename valSetStoreInterval to valSetCheckpointInterval * change the panic msg * add a test and changelog entry * update changelog entry * update changelog entry * add a link to PR * fix test * Update CHANGELOG_PENDING.md Co-Authored-By: melekes <anton.kalyaev@gmail.com> * update comment * use MaxInt64 func
- Loading branch information
Showing
3 changed files
with
114 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package state | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
cfg "github.com/tendermint/tendermint/config" | ||
dbm "github.com/tendermint/tendermint/libs/db" | ||
"github.com/tendermint/tendermint/types" | ||
) | ||
|
||
func TestSaveValidatorsInfo(t *testing.T) { | ||
// test we persist validators every valSetCheckpointInterval blocks | ||
stateDB := dbm.NewMemDB() | ||
val, _ := types.RandValidator(true, 10) | ||
vals := types.NewValidatorSet([]*types.Validator{val}) | ||
|
||
// TODO(melekes): remove in 0.33 release | ||
// https://github.com/tendermint/tendermint/issues/3543 | ||
saveValidatorsInfo(stateDB, 1, 1, vals) | ||
saveValidatorsInfo(stateDB, 2, 1, vals) | ||
assert.NotPanics(t, func() { | ||
_, err := LoadValidators(stateDB, 2) | ||
if err != nil { | ||
panic(err) | ||
} | ||
}) | ||
//ENDREMOVE | ||
|
||
saveValidatorsInfo(stateDB, valSetCheckpointInterval, 1, vals) | ||
|
||
loadedVals, err := LoadValidators(stateDB, valSetCheckpointInterval) | ||
assert.NoError(t, err) | ||
assert.NotZero(t, loadedVals.Size()) | ||
} | ||
|
||
func BenchmarkLoadValidators(b *testing.B) { | ||
const valSetSize = 100 | ||
|
||
config := cfg.ResetTestRoot("state_") | ||
defer os.RemoveAll(config.RootDir) | ||
dbType := dbm.DBBackendType(config.DBBackend) | ||
stateDB := dbm.NewDB("state", dbType, config.DBDir()) | ||
state, err := LoadStateFromDBOrGenesisFile(stateDB, config.GenesisFile()) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
state.Validators = genValSet(valSetSize) | ||
state.NextValidators = state.Validators.CopyIncrementProposerPriority(1) | ||
SaveState(stateDB, state) | ||
|
||
for i := 10; i < 10000000000; i *= 10 { // 10, 100, 1000, ... | ||
saveValidatorsInfo(stateDB, int64(i), state.LastHeightValidatorsChanged, state.NextValidators) | ||
|
||
b.Run(fmt.Sprintf("height=%d", i), func(b *testing.B) { | ||
for n := 0; n < b.N; n++ { | ||
_, err := LoadValidators(stateDB, int64(i)) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
}) | ||
} | ||
} |