Skip to content

Commit

Permalink
Merge pull request #70 from eigerco/feat/63/benchmarks-for-the-mater-…
Browse files Browse the repository at this point in the history
…library

feat/36/add benchmarks
  • Loading branch information
serg-temchenko authored Jun 18, 2024
2 parents 88c6662 + eb14e59 commit d5afa03
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 13 deletions.
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 @@ -40,6 +40,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
40 changes: 40 additions & 0 deletions storage/mater/BENCHMARK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
### How to run

Execute the benchmarks with `cargo bench`.

### Results

The benchmarks below use Median times after 100 runs. The duplication
percentages show the proportion of duplicated content in the file. The
benchmarks were performed on a machine with a `Ryzen 9 5950X` processor and
`64GB DDR4` memory.

#### 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

0 comments on commit d5afa03

Please sign in to comment.