txHandler: applications rate limiter#5734
Merged
algorandskiy merged 33 commits intoalgorand:masterfrom Nov 9, 2023
Merged
Conversation
bbroder-uji
reviewed
Sep 11, 2023
cce
reviewed
Sep 12, 2023
37de57d to
0ba30f7
Compare
Codecov Report
@@ Coverage Diff @@
## master #5734 +/- ##
==========================================
+ Coverage 55.64% 55.69% +0.04%
==========================================
Files 475 476 +1
Lines 66869 67043 +174
==========================================
+ Hits 37209 37339 +130
- Misses 27151 27185 +34
- Partials 2509 2519 +10
... and 8 files with indirect coverage changes 📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today! |
bbroder-uji
reviewed
Sep 12, 2023
bbroder-uji
reviewed
Sep 12, 2023
10582ba to
ac6037f
Compare
ac6037f to
e05d839
Compare
bbroder-uji
reviewed
Sep 18, 2023
bbroder-uji
reviewed
Sep 18, 2023
bbroder-uji
reviewed
Sep 18, 2023
bbroder-uji
reviewed
Sep 18, 2023
Contributor
Author
|
Merged master, moved new config vals to v32 |
cce
reviewed
Nov 3, 2023
jasonpaulos
reviewed
Nov 3, 2023
894188c to
a66abbf
Compare
jasonpaulos
previously approved these changes
Nov 7, 2023
jasonpaulos
reviewed
Nov 7, 2023
gmalouf
reviewed
Nov 8, 2023
gmalouf
reviewed
Nov 8, 2023
jasonpaulos
approved these changes
Nov 9, 2023
Contributor
jasonpaulos
left a comment
There was a problem hiding this comment.
LGTM, thanks for incorporating the app ID changes
gmalouf
reviewed
Nov 9, 2023
gmalouf
approved these changes
Nov 9, 2023
cce
approved these changes
Nov 9, 2023
This was referenced Nov 16, 2023
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Rate limit incoming apps based on app id + sender IP addr. It precedes enqueueing into backlog in
TxHandler.processIncomingTxn. It takes effect only if enabled and the backlog is more than 1/2 full.The implementation uses sharded map with sliding window limiter. The sliding window data is used to for least recently used eviction (list based).
There are two hashes used: 1) memhash64 for app to bucket mapping 2) blake2b for app id + sender caching.
Importantly, the implementation is trying to compromise on memory usage and shrinks 32 bytes blake2b to 8 bytes. It appears OK since blake2b output is uniform, and input data is salted making impossible to censor app + relay pairs.
As benchmark (below) shows there is almost no penalty (5%) on eviction when 94% of operations cause eviction.
Test Plan
Used real recorded transactions and approximated traffic by reported connected peers metric during the last high traffic event on Sep 1st 12:01 pm - 3:28pm. Got about 6M transactions and about 10k unique key pairs (no truncated hash collisions).
Run few benchmarks by using tx messages from the generated data set and got the following data:
Visualized acceptance rate:

Memory overhead:
sync.Poolfor keys/buckets gathering 0.5% alloc_space, 25% alloc_object on a heavy load.go-deadlock.lock()(fixed in fix extra heap allocations when detector is disabled go-deadlock#2):