Skip to content
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

feat/36/add benchmarks #70

Merged
merged 13 commits into from
Jun 18, 2024
95 changes: 95 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ cid = { version = "0.11.1" }
clap = { version = "4.5.3" }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
color-print = "0.3.4"
criterion = "0.5.1"
digest = "0.10.7"
futures = "0.3.28"
hex-literal = { version = "0.4.1" }
Expand Down
37 changes: 37 additions & 0 deletions storage/mater/BENCHMARK.md
cernicc marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
### How to run

Execute the benchmarks with `cargo bench`.

### Results

Tested on the machine with `Ryzen 9 5950X` and `64GB DDR4`.

#### read

Benchmark checks what is the time needed to fully read a content buffer into the `BlockStore`

| Size / Duplication | 0% | 10% | 20% | 40% | 80% |
| ------------------ | --------- | --------- | --------- | --------- | --------- |
| 10 MB | 4.6776 ms | 4.5806 ms | 4.6977 ms | 4.5534 ms | 4.5038 ms |
| 100 MB | 62.419 ms | 60.895 ms | 59.461 ms | 55.355 ms | 46.792 ms |
| 1 GB | 632.34 ms | 650.01 ms | 631.49 ms | 600.01 ms | 505.58 ms |

#### write

Checks the time needed to write the CARv2 to the buffer from `BlockStore`.

| Size / Duplication | 0% | 10% | 20% | 40% | 80% |
| ------------------ | --------- | --------- | --------- | --------- | --------- |
| 10 MB | 1.6516 ms | 1.0342 ms | 875.68 µs | 772.26 µs | 354.77 µs |
| 100 MB | 12.689 ms | 10.707 ms | 9.4533 ms | 6.7805 ms | 1.7487 ms |
| 1 GB | 123.34 ms | 102.39 ms | 91.712 ms | 69.273 ms | 23.140 ms |

#### filestore

Converts a source file to the CARv2 and writes it to the output file

| Size / Duplication | 0% | 10% | 20% | 40% | 80% |
| ------------------ | --------- | --------- | --------- | --------- | --------- |
| 10 MB | 15.145 ms | 15.179 ms | 15.162 ms | 14.501 ms | 14.836 ms |
| 100 MB | 203.85 ms | 210.14 ms | 220.38 ms | 216.34 ms | 211.12 ms |
| 1 GB | 1.7674 s | 1.8174 s | 1.8396 s | 1.8496 s | 1.8774 s |
7 changes: 6 additions & 1 deletion storage/mater/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ serde = { workspace = true, features = ["derive"] }
serde_ipld_dagcbor.workspace = true
sha2.workspace = true
thiserror.workspace = true
tokio = { workspace = true, features = ["fs", "macros", "rt"] }
tokio = { workspace = true, features = ["fs", "macros", "rt-multi-thread"] }
tokio-stream.workspace = true
tokio-util = { workspace = true, features = ["io"] }

[dev-dependencies]
criterion = { workspace = true, features = ["async_tokio", "html_reports"] }
rand.workspace = true
tempfile.workspace = true

[lints]
workspace = true

[[bench]]
harness = false
name = "benchmark"
24 changes: 14 additions & 10 deletions storage/mater/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ A Rust library to read and write CAR files.

## Specifications

CARv1 specification: https://ipld.io/specs/transport/car/carv1/
CARv2 specification: https://ipld.io/specs/transport/car/carv2/
UnixFS specification: https://github.com/ipfs/specs/blob/e4e5754ad4a4bfbb2ebe63f4c27631f573703de0/UNIXFS.md
- CARv1 specification: https://ipld.io/specs/transport/car/carv1/
- CARv2 specification: https://ipld.io/specs/transport/car/carv2/
- UnixFS specification: https://github.com/ipfs/specs/blob/e4e5754ad4a4bfbb2ebe63f4c27631f573703de0/UNIXFS.md

## Developing

Expand All @@ -26,19 +26,23 @@ The file was generated and checked-in instead of making `pb-rs` part of the buil
because the definition file ([`unixfs.proto`](src/unixfs/unixfs.proto)) does not
change frequently, hence, there is no need to add complexity to the build process.

### Benchmarks

[Read more](BENCHMARK.md)

## Acknowledgements

We'd like to thank all the people that participated in the projects mentioned in this section.
In a way or another, they were all instrumental in the implementation of the present library.

* [go-car](https://github.com/ipld/go-car) — the original implementation.
* [beetle](https://github.com/n0-computer/beetle) — the library `mater` is based on.
- [go-car](https://github.com/ipld/go-car) — the original implementation.
- [beetle](https://github.com/n0-computer/beetle) — the library `mater` is based on.
We've gutted out the important bits for this project, but without it, this work would've been much harder.
* [ImHex](https://github.com/WerWolv/ImHex) — for saving hours when comparing binary files.
- [ImHex](https://github.com/WerWolv/ImHex) — for saving hours when comparing binary files.

### Similar libraries/sources

* [Forest](https://github.com/ChainSafe/forest/blob/62e55df27a091ba7993a60cc1e72622ad8e25151/src/utils/db/car_stream.rs#L155)
* [rust-car](https://github.com/jaeaster/rust-car)
* [rs-car](https://github.com/dapplion/rs-car)
* [car-utils](https://github.com/blocklessnetwork/car-utils)
- [Forest](https://github.com/ChainSafe/forest/blob/62e55df27a091ba7993a60cc1e72622ad8e25151/src/utils/db/car_stream.rs#L155)
- [rust-car](https://github.com/jaeaster/rust-car)
- [rs-car](https://github.com/dapplion/rs-car)
- [car-utils](https://github.com/blocklessnetwork/car-utils)
Loading
Loading