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: Implement a memoization-based cache #30

Merged
merged 5 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 72 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion car-mirror-benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ anyhow = "1.0"
async-std = { version = "1.11", features = ["attributes"] }
async-trait = "0.1"
bytes = "1.4.0"
car-mirror = { path = "../car-mirror", version = "0.1", features = ["test_utils"] }
car-mirror = { path = "../car-mirror", version = "0.1", features = ["test_utils", "quick_cache"] }
libipld = "0.16.0"
wnfs-common = "0.1.23"

Expand Down
27 changes: 21 additions & 6 deletions car-mirror-benches/benches/artificially_slow_blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use car_mirror::{
common::Config,
pull, push,
test_utils::{arb_ipld_dag, links_to_padded_ipld, setup_blockstore},
traits::InMemoryCache,
};
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use libipld::Cid;
Expand All @@ -27,19 +28,26 @@ pub fn push_throttled(c: &mut Criterion) {
},
|(client_store, root)| {
let client_store = &ThrottledBlockStore(client_store);
let client_cache = &InMemoryCache::new(10_000);
let server_store = &ThrottledBlockStore::new();
let server_cache = &InMemoryCache::new(10_000);
let config = &Config::default();

// Simulate a multi-round protocol run in-memory
async_std::task::block_on(async move {
let mut request = push::request(root, None, config, client_store).await?;
let mut request =
push::request(root, None, config, client_store, client_cache).await?;
loop {
let response = push::response(root, request, config, server_store).await?;
let response =
push::response(root, request, config, server_store, server_cache)
.await?;

if response.indicates_finished() {
break;
}
request = push::request(root, Some(response), config, client_store).await?;
request =
push::request(root, Some(response), config, client_store, client_cache)
.await?;
}

Ok::<(), anyhow::Error>(())
Expand Down Expand Up @@ -67,15 +75,22 @@ pub fn pull_throttled(c: &mut Criterion) {
},
|(server_store, root)| {
let server_store = &ThrottledBlockStore(server_store);
let server_cache = &InMemoryCache::new(10_000);
let client_store = &ThrottledBlockStore::new();
let client_cache = &InMemoryCache::new(10_000);
let config = &Config::default();

// Simulate a multi-round protocol run in-memory
async_std::task::block_on(async move {
let mut request = pull::request(root, None, config, client_store).await?;
let mut request =
pull::request(root, None, config, client_store, client_cache).await?;
loop {
let response = pull::response(root, request, config, server_store).await?;
request = pull::request(root, Some(response), config, client_store).await?;
let response =
pull::response(root, request, config, server_store, server_cache)
.await?;
request =
pull::request(root, Some(response), config, client_store, client_cache)
.await?;

if request.indicates_finished() {
break;
Expand Down
27 changes: 21 additions & 6 deletions car-mirror-benches/benches/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use car_mirror::{
common::Config,
pull, push,
test_utils::{arb_ipld_dag, links_to_padded_ipld, setup_blockstore},
traits::InMemoryCache,
};
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use wnfs_common::MemoryBlockStore;
Expand All @@ -21,19 +22,26 @@ pub fn push(c: &mut Criterion) {
(store, root)
},
|(ref client_store, root)| {
let client_cache = &InMemoryCache::new(10_000);
let server_store = &MemoryBlockStore::new();
let server_cache = &InMemoryCache::new(10_000);
let config = &Config::default();

// Simulate a multi-round protocol run in-memory
async_std::task::block_on(async move {
let mut request = push::request(root, None, config, client_store).await?;
let mut request =
push::request(root, None, config, client_store, client_cache).await?;
loop {
let response = push::response(root, request, config, server_store).await?;
let response =
push::response(root, request, config, server_store, server_cache)
.await?;

if response.indicates_finished() {
break;
}
request = push::request(root, Some(response), config, client_store).await?;
request =
push::request(root, Some(response), config, client_store, client_cache)
.await?;
}

Ok::<(), anyhow::Error>(())
Expand All @@ -60,15 +68,22 @@ pub fn pull(c: &mut Criterion) {
(store, root)
},
|(ref server_store, root)| {
let server_cache = &InMemoryCache::new(10_000);
let client_store = &MemoryBlockStore::new();
let client_cache = &InMemoryCache::new(10_000);
let config = &Config::default();

// Simulate a multi-round protocol run in-memory
async_std::task::block_on(async move {
let mut request = pull::request(root, None, config, client_store).await?;
let mut request =
pull::request(root, None, config, client_store, client_cache).await?;
loop {
let response = pull::response(root, request, config, server_store).await?;
request = pull::request(root, Some(response), config, client_store).await?;
let response =
pull::response(root, request, config, server_store, server_cache)
.await?;
request =
pull::request(root, Some(response), config, client_store, client_cache)
.await?;

if request.indicates_finished() {
break;
Expand Down
3 changes: 3 additions & 0 deletions car-mirror/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ iroh-car = "0.3.0"
libipld = "0.16.0"
libipld-core = "0.16.0"
proptest = { version = "1.1", optional = true }
quick_cache = { version = "0.4.0", optional = true }
roaring-graphs = { version = "0.12", optional = true }
serde = "1.0.183"
serde_ipld_dagcbor = "0.4.0"
thiserror = "1.0.47"
tokio = { version = "^1", default-features = false }
tracing = "0.1"
tracing-subscriber = "0.3"
wnfs-common = "0.1.23"
Expand All @@ -51,6 +53,7 @@ test-strategy = "0.3"
[features]
default = []
test_utils = ["proptest", "roaring-graphs"]
quick_cache = ["dep:quick_cache"]

[package.metadata.docs.rs]
all-features = true
Expand Down
Loading
Loading