-
Notifications
You must be signed in to change notification settings - Fork 887
mempool: make Update/Reap index maintenance incremental #4240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
masih
wants to merge
1
commit into
main
Choose a base branch
from
devin/1789651697-mempool-incremental-compact
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+236
−51
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,71 @@ | ||
| package mempool | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/sei-protocol/sei-chain/sei-tendermint/internal/proxy" | ||
| "github.com/sei-protocol/sei-chain/sei-tendermint/libs/utils" | ||
| "github.com/sei-protocol/sei-chain/sei-tendermint/libs/utils/require" | ||
| ) | ||
|
|
||
| func benchTxStore(b *testing.B, numAccounts, txsPerAccount int) *txStore { | ||
| rng := utils.TestRng() | ||
| app := newEVMNonceApp() | ||
| cfg := TestConfig() | ||
| cfg.Size = numAccounts * txsPerAccount | ||
| cfg.PendingSize = numAccounts * txsPerAccount | ||
| cfg.MaxTxsBytes = 1 << 40 | ||
| cfg.MaxPendingTxsBytes = 1 << 40 | ||
| store := NewTxStore(cfg, proxy.New(app)) | ||
| for range numAccounts { | ||
| addr := genEvmAddress(rng) | ||
| app.setNonce(addr, 0) | ||
| app.setBalance(addr, 1<<30) | ||
| for n := range txsPerAccount { | ||
| wtx := makeEvmTxForTest(rng, addr, uint64(n), int64(rng.Intn(1000)), 1) | ||
| require.NoError(b, store.Insert(wtx)) | ||
| } | ||
| } | ||
| return store | ||
| } | ||
|
|
||
| func BenchmarkTxStore_Update(b *testing.B) { | ||
| for _, tc := range []struct{ accounts, per int }{{10000, 1}, {5000, 4}, {50000, 1}} { | ||
| b.Run(fmt.Sprintf("accounts=%d,per=%d", tc.accounts, tc.per), func(b *testing.B) { | ||
| store := benchTxStore(b, tc.accounts, tc.per) | ||
| b.ResetTimer() | ||
| for range b.N { | ||
| store.Update(updateSpec{Now: time.Now(), Height: 1, Constraints: TxConstraints{MaxGas: -1}}) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func BenchmarkTxStore_InInclusionOrder(b *testing.B) { | ||
| for _, tc := range []struct{ accounts, per int }{{10000, 1}, {5000, 4}, {50000, 1}} { | ||
| b.Run(fmt.Sprintf("accounts=%d,per=%d", tc.accounts, tc.per), func(b *testing.B) { | ||
| store := benchTxStore(b, tc.accounts, tc.per) | ||
| b.ResetTimer() | ||
| for range b.N { | ||
| for inner := range store.inner.Lock() { | ||
| inner.inInclusionOrder() | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func BenchmarkTxStore_ReapRemove(b *testing.B) { | ||
| for _, tc := range []struct{ accounts, per int }{{10000, 1}, {5000, 4}} { | ||
| b.Run(fmt.Sprintf("accounts=%d,per=%d", tc.accounts, tc.per), func(b *testing.B) { | ||
| for range b.N { | ||
| b.StopTimer() | ||
| store := benchTxStore(b, tc.accounts, tc.per) | ||
| b.StartTimer() | ||
| store.Reap(ReapLimits{MaxTxs: utils.Some(uint64(100))}, true) | ||
| } | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[suggestion]
RecentSnapshotcan now escalate fromRLockto the exclusiveLockand run the O(m log m)inInclusionOrdersort inline. Sincerefresh/ReapsetsnapshotStale, the first/unconfirmed_txsrequest after each block pays that sort while holding the write lock, blockingInsert/CheckTx/Reapand the consensusUpdatefor roughly the 9–20 ms the PR description measures at 10k–20k txs. Total work is not higher than before (consensus used to pay it unconditionally), but it is now triggerable at an arbitrary moment by an RPC caller rather than at a point consensus controls.Two cheaper options: keep the snapshot a byproduct of the
inInclusionOrderthatReapalready runs under the lock, or compute the ordering into a local slice and publish it with a short critical section. Worth at least a comment recording the intended trade-off.Separately, this makes
RecentSnapshotunsafe to call from any context already holdinginner.RLock()(sync.RWMutexis not reentrant). No current caller does, but the previous version was safe there.