Skip to content

Commit

Permalink
feat: Replay IO traces on estimator for statistics (near#7445)
Browse files Browse the repository at this point in the history
This introduces the ability to replay IO traces on the estimator.
Example usage in runtime/runtime-params-estimator/README.md.

While it is not used for estimations, yet, it is already a subcommand of
the estimator. The idea is that for near#7440 a lot of code can be reused.
Further, replaying on the estimator is required for near#7058 and near#7059.
  • Loading branch information
jakmeier authored Oct 18, 2022
1 parent e2d6a84 commit 32be8e3
Show file tree
Hide file tree
Showing 39 changed files with 4,657 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions runtime/runtime-params-estimator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ required-features = ["costs_counting"]
[dependencies]
anyhow.workspace = true
borsh.workspace = true
bs58.workspace = true
bytesize.workspace = true
cfg-if.workspace = true
chrono.workspace = true
Expand Down Expand Up @@ -45,6 +46,9 @@ near-vm-runner = {path = "../../runtime/near-vm-runner" }
nearcore = { path = "../../nearcore" }
node-runtime = { path = "../../runtime/runtime" }

[dev-dependencies]
insta.workspace = true

[features]
default = ["costs_counting"]
costs_counting = ["near-vm-logic/costs_counting"]
Expand Down
52 changes: 52 additions & 0 deletions runtime/runtime-params-estimator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,55 @@ Use this tool to measure the running time of elementary runtime operations that
3. **Continuous Estimation**: Take a look at [`continuous-estimation/README.md`](./continuous-estimation/README.md) to learn about the automated setup around the parameter estimator.

Note, if you use the plotting functionality you would need to install [gnuplot](http://gnuplot.info/) to see the graphs.

## Replaying IO traces

Compiling `neard` with `--features=io_trace` and then running it with
`--record-io-trace=my_trace.log` produces a trace of all storage and database
accesses. This trace can be replayed by the estimator. For now only to get
statistics. But the plan is that it will also give gas estimations based on
replaying traces.

Example:
```
cargo run -p runtime-params-estimator -- replay my_trace.log cache-stats
GET 193 Block 193 BlockHeader 101 BlockHeight 100 BlockInfo 2 BlockMisc
11 CachedContractCode 98 ChunkExtra 95 Chunks 4 EpochInfo
98 IncomingReceipts 30092 State
SET 1 CachedContractCode
DB GET 30987 requests for a total of 391093512 B
DB SET 1 requests for a total of 10379357 B
STORAGE READ 153001 requests for a total of 2523227 B
STORAGE WRITE 151412 requests for a total of 2512012 B
TRIE NODES 8878276 /375708 /27383 (chunk-cache/shard-cache/DB)
SHARD CACHE 93.21% hit rate, 93.21% if removing 15 too large nodes from total
CHUNK CACHE 95.66% hit rate, 99.69% if removing 375708 shard cache hits from total
```
For a list of all options, run `cargo run -p runtime-params-estimator -- replay --help`.
### IO trace tests
The test input files `./res/*.io_trace` have been generated based on real mainnet traffic.
```bash
cargo build --release -p neard --features=io_trace
for shard in 0 1 2 3
do
target/release/neard \
--record-io-trace=75220100-75220101.s${shard}.io_trace view-state \
apply-range --start-index 75220100 --end-index 75220101 \
--sequential --shard-id ${shard}
done
```
When running these command, make sure to run with `sequential` and to disable
prefetching is disabled, or else the the replaying modes that match requests to
receipts will not work properly.
```js
// config.json
"store": {
"enable_receipt_prefetching": false
}
```
882 changes: 882 additions & 0 deletions runtime/runtime-params-estimator/res/75220100-75220101.s0.io_trace

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions runtime/runtime-params-estimator/res/75220100-75220101.s1.io_trace
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
GET BlockMisc "fr1UNhF4ZSXeDuai2G7sGkX" size=32
GET BlockMisc "E3m8pHmYBNnATaf99sfuZtSRXG" size=36
GET EpochInfo "4fiLcy6fEtiSYH" size=16400
GET EpochInfo "11111111111111111111111111111111" size=2266
GET BlockHeight "PD1eH7fghtT" size=32
GET Block "2zB2oBqRj8dFECSaBeGP6hGGDs7KowYBVwcVfq8Ukjf9" size=7706
GET EpochInfo "7XciHBpUitLPSu8QBrsWp6sghvVhwXj7nzjm5FxNZbjn" size=28482
GET ChunkExtra "2U2dQ3wKvcDfVSJnqQ8GsSS11BJZ2Tynpp2a3eEDkxW1aMoyFmDiuCB" size=101
GET Chunks "4hpzBA6CJtipJqWz9vxW9M24BW6cWh9sQE9sLBXcYRAN" size=521
GET Block "DwSdhqzB18RJAew3XoMKrjHpHyWJdetAbrKFt2AJgSt8" size=6796
GET BlockHeader "2zB2oBqRj8dFECSaBeGP6hGGDs7KowYBVwcVfq8Ukjf9" size=6293
GET IncomingReceipts "2U2dQ3wKvcDfVSJnqQ8GsSS11BJZ2Tynpp2a3eEDkxW1aMoyFmCEuuq" size=364
GET BlockHeader "DwSdhqzB18RJAew3XoMKrjHpHyWJdetAbrKFt2AJgSt8" size=5383
GET BlockInfo "DwSdhqzB18RJAew3XoMKrjHpHyWJdetAbrKFt2AJgSt8" size=221
GET BlockInfo "9TxV9KzgAaxqVcQPmh6tce9Dy1XQXWgDNyatRG3HBS9" size=302
GET BlockInfo "FhsQS1zgTLpZjYitRKevStmzJfUgweUTjQA1rUeNW6QR" size=221
GET EpochInfo "235gTuzMxiALmnyykDmZmhoK1JKgoNkUyegQMjirTVwM" size=36184
apply_transactions shard_id=1
process_state_update
apply num_transactions=0 shard_cache_miss=4 shard_cache_hit=9
GET State "3t9dCZX5c6JZCqPPMVq4StTv264foNSkh9bAcGCetZS3MKSWSM6p7d" size=46
GET State "3t9dCZX5c6K7z6VyJmzVno3bCQWcVjDS8aKkDEY32rXSWiTqPnEavn" size=171
GET State "3t9dCZX5c6S742LyU1qityVdvoZKT61FEoPNhxJonSu6GzTwsatxTw" size=50
GET State "3t9dCZX5c6FJGMi9WRfEMyu7hx3MrT6zLRoFo4y6RHnAQRDett8uMG" size=16
GET BlockHeight "PNiKHvVBK9y" size=32
GET Block "B4epTA1V54DmRbFhFEaLyyzLBQuqq688bHNq3sNRDnTF" size=7771
GET ChunkExtra "8RtauJyfdSSVxVCuV67T1d9bfmnUbLdw472QCs2hVcNbAdzY3iJ2FAf" size=101
GET Chunks "C9mtizUsXRLGy9KG7voyLsshWxuJHXPkQdD6wWinModM" size=368
GET Block "2zB2oBqRj8dFECSaBeGP6hGGDs7KowYBVwcVfq8Ukjf9" size=7706
GET BlockHeader "B4epTA1V54DmRbFhFEaLyyzLBQuqq688bHNq3sNRDnTF" size=6358
GET IncomingReceipts "8RtauJyfdSSVxVCuV67T1d9bfmnUbLdw472QCs2hVcNbAdzY3iGYFtK" size=364
GET BlockHeader "2zB2oBqRj8dFECSaBeGP6hGGDs7KowYBVwcVfq8Ukjf9" size=6293
GET BlockInfo "2zB2oBqRj8dFECSaBeGP6hGGDs7KowYBVwcVfq8Ukjf9" size=221
apply_transactions shard_id=1
process_state_update
apply num_transactions=0 shard_cache_hit=13
Loading

0 comments on commit 32be8e3

Please sign in to comment.