Skip to content

Commit

Permalink
feat: Implement CacheMissing blockstore wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Feb 15, 2024
1 parent 69de1f3 commit 1b878d5
Show file tree
Hide file tree
Showing 12 changed files with 423 additions and 333 deletions.
20 changes: 10 additions & 10 deletions car-mirror-benches/benches/artificially_slow_blockstore.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use anyhow::Result;
use bytes::Bytes;
use car_mirror::{
cache::{CacheMissing, InMemoryCache},
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 @@ -26,10 +26,10 @@ pub fn push_throttled(c: &mut Criterion) {
(store, root)
},
|(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 client_store = &CacheMissing::new(100_000, ThrottledBlockStore(client_store));
let client_cache = &InMemoryCache::new(100_000);
let server_store = &CacheMissing::new(100_000, ThrottledBlockStore::new());
let server_cache = &InMemoryCache::new(100_000);
let config = &Config::default();

// Simulate a multi-round protocol run in-memory
Expand Down Expand Up @@ -80,10 +80,10 @@ pub fn pull_throttled(c: &mut Criterion) {
(store, root)
},
|(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 server_store = &CacheMissing::new(100_000, ThrottledBlockStore(server_store));
let server_cache = &InMemoryCache::new(100_000);
let client_store = &CacheMissing::new(100_000, ThrottledBlockStore::new());
let client_cache = &InMemoryCache::new(100_000);
let config = &Config::default();

// Simulate a multi-round protocol run in-memory
Expand Down Expand Up @@ -130,7 +130,7 @@ impl BlockStore for ThrottledBlockStore {
}

async fn has_block(&self, cid: &Cid) -> Result<bool> {
// The idea is that has_block would be faster than `get_block`, as it should be managed closer to CPU memory
async_std::task::sleep(Duration::from_micros(50)).await; // Block fetching is artifically slowed by 50 microseconds
self.0.has_block(cid).await
}
}
Expand Down
10 changes: 5 additions & 5 deletions car-mirror-benches/benches/in_memory.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use car_mirror::{
cache::InMemoryCache,
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 @@ -22,9 +22,9 @@ pub fn push(c: &mut Criterion) {
(store, root)
},
|(ref client_store, root)| {
let client_cache = &InMemoryCache::new(10_000);
let client_cache = &InMemoryCache::new(100_000);
let server_store = &MemoryBlockStore::new();
let server_cache = &InMemoryCache::new(10_000);
let server_cache = &InMemoryCache::new(100_000);
let config = &Config::default();

// Simulate a multi-round protocol run in-memory
Expand Down Expand Up @@ -68,9 +68,9 @@ pub fn pull(c: &mut Criterion) {
(store, root)
},
|(ref server_store, root)| {
let server_cache = &InMemoryCache::new(10_000);
let server_cache = &InMemoryCache::new(100_000);
let client_store = &MemoryBlockStore::new();
let client_cache = &InMemoryCache::new(10_000);
let client_cache = &InMemoryCache::new(100_000);
let config = &Config::default();

// Simulate a multi-round protocol run in-memory
Expand Down
10 changes: 5 additions & 5 deletions car-mirror-benches/benches/simulated_latency.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use car_mirror::{
cache::InMemoryCache,
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 std::{ops::Range, time::Duration};
Expand Down Expand Up @@ -68,12 +68,12 @@ pub fn pull_with_simulated_latency(
links_to_padded_ipld(block_padding),
));
let store = async_std::task::block_on(setup_blockstore(blocks)).unwrap();
let cache = InMemoryCache::new(10_000);
let cache = InMemoryCache::new(100_000);
(store, cache, root)
},
|(ref server_store, ref server_cache, root)| {
let client_store = &MemoryBlockStore::new();
let client_cache = &InMemoryCache::new(10_000);
let client_cache = &InMemoryCache::new(100_000);
let config = &Config::default();

// Simulate a multi-round protocol run in-memory
Expand Down Expand Up @@ -145,12 +145,12 @@ pub fn push_with_simulated_latency(
links_to_padded_ipld(block_padding),
));
let store = async_std::task::block_on(setup_blockstore(blocks)).unwrap();
let cache = InMemoryCache::new(10_000);
let cache = InMemoryCache::new(100_000);
(store, cache, root)
},
|(ref client_store, ref client_cache, root)| {
let server_store = &MemoryBlockStore::new();
let server_cache = &InMemoryCache::new(10_000);
let server_cache = &InMemoryCache::new(100_000);
let config = &Config::default();

// Simulate a multi-round protocol run in-memory
Expand Down
Loading

0 comments on commit 1b878d5

Please sign in to comment.