-
Notifications
You must be signed in to change notification settings - Fork 113
EVM-373 : Investigate FeeHistory performance optimizations #781
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
abdulazeem-tk4vr
wants to merge
3
commits into
cosmos:main
Choose a base branch
from
abdulazeem-tk4vr:feehistory-caching
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.
+172
−25
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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,25 @@ | ||
| param( | ||
| [string]$Endpoint = "http://127.0.0.1:8545", | ||
| [string]$Blocks = "0x40", | ||
| [int]$Rounds = 8, | ||
| [int[]]$Percentiles = @(25,50,75) | ||
| ) | ||
|
|
||
| $body = @{ jsonrpc = "2.0"; id = 1; method = "eth_feeHistory"; params = @($Blocks, "latest", $Percentiles) } | ConvertTo-Json -Compress | ||
| $times = @() | ||
| Write-Host ("eth_feeHistory {0}, percentiles=[{1}], rounds={2}" -f $Blocks, ($Percentiles -join ","), $Rounds) | ||
| for ($i=1; $i -le $Rounds; $i++) { | ||
| $sw = [System.Diagnostics.Stopwatch]::StartNew() | ||
| try { Invoke-RestMethod -Uri $Endpoint -Method Post -ContentType "application/json" -Body $body | Out-Null } catch {} | ||
| $sw.Stop() | ||
| $ms = [int][Math]::Round($sw.Elapsed.TotalMilliseconds) | ||
| Write-Host ("Run {0}: {1} ms" -f $i, $ms) | ||
| $times += $ms | ||
| Start-Sleep -Milliseconds 150 | ||
| } | ||
| $avg = [Math]::Round(($times | Measure-Object -Average).Average,0) | ||
| $min = ($times | Measure-Object -Minimum).Minimum | ||
| $max = ($times | Measure-Object -Maximum).Maximum | ||
| Write-Host ("Avg: {0} ms Min: {1} ms Max: {2} ms" -f $avg, $min, $max) | ||
|
|
||
|
|
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,25 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| ENDPOINT=${1:-http://127.0.0.1:8545} | ||
| BLOCKS=${2:-0x40} | ||
| ROUNDS=${3:-8} | ||
| PCTS=${4:-[25,50,75]} | ||
|
|
||
| BODY='{"jsonrpc":"2.0","id":1,"method":"eth_feeHistory","params":["'"$BLOCKS"'","latest",'"$PCTS"']}' | ||
|
|
||
| sum=0; min=999999; max=0 | ||
| echo "eth_feeHistory $BLOCKS, percentiles=$PCTS, rounds=$ROUNDS" | ||
| for i in $(seq 1 "$ROUNDS"); do | ||
| t=$(curl -s -o /dev/null -w '%{time_total}\n' -H 'Content-Type: application/json' -d "$BODY" "$ENDPOINT") | ||
| t_ms=$(awk -v t="$t" 'BEGIN { printf("%.0f", t*1000) }') | ||
| echo "Run $i: ${t_ms} ms" | ||
| sum=$((sum + t_ms)) | ||
| (( t_ms < min )) && min=$t_ms | ||
| (( t_ms > max )) && max=$t_ms | ||
| sleep 0.15 | ||
| done | ||
| avg=$((sum / ROUNDS)) | ||
| printf "Avg: %d ms Min: %d ms Max: %d ms\n" "$avg" "$min" "$max" | ||
|
|
||
|
|
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.
why do we multiply the cap by 2 here?
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.
tl;dr it gives better hit rates for overlapping requests where max no. of blocks are called for a reasonable cap size.
Well I noticed that FeeHistoryCap limits a single eth_feeHistory call to a default of 100 blocks. So in a possible worst case scenario where a user is indexing the network for details, consecutive requests often overlap because "latest" moves forward.
FeeHistoryCap = 100
Cache size = 200 entries
Request 1: blocks 1000-1099
Cache stores: blocks 1000-1099 (100 entries)
Request 2 (few seconds later): blocks 1050-1149
Cache hits: blocks 1050-1099 (50 hits)
Cache stores: blocks 1100-1149 (50 new entries)
Total cached: 150 entries (well within the 200 limit)
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.
If a user keeps making a request for 100 entries in a random range, we will lose the previous context. Then this isnt that helpful.
I was just thinking that if there were requests x and y in completely different ranges, y would override the cache with just
FeeHistoryCap. But if again somehow, x was requested because y was a mistake, then there is a warm cache withFeeHistoryCap *2.this is more like a safety check, so that we provide some leeway for older entries to be there. I think either way is good enough to get the job done.
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.
@technicallyty please do let me know what you think about this
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.
i will try to carve out time to look at this this week
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.
Thanks, I appreciate it. If it makes your job any easier, the existing RPC unit tests are working with the added features. I dont think it breaks anything.