-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TST] Implement utility functions to instantiate blockfile provider
- Loading branch information
Sicheng Pan
committed
Oct 4, 2024
1 parent
1fc76c8
commit 918b366
Showing
5 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::{fmt::Debug, future::Future}; | ||
|
||
use criterion::{BenchmarkId, Criterion}; | ||
use tokio::runtime::Runtime; | ||
|
||
pub fn tokio_multi_thread() -> Runtime { | ||
tokio::runtime::Builder::new_multi_thread() | ||
.enable_all() | ||
.build() | ||
.expect("Tokio runtime should be set up correctly.") | ||
} | ||
|
||
pub fn bench_group<'t, Arg, Fut>( | ||
name: &'t str, | ||
criterion: &'t mut Criterion, | ||
runtime: &'t Runtime, | ||
inputs: &'t [Arg], | ||
routine: impl Fn(&'t Arg) -> Fut, | ||
) where | ||
Arg: Clone + Debug, | ||
Fut: Future<Output = ()>, | ||
{ | ||
let mut input_cycle = inputs.iter().cycle(); | ||
let mut group = criterion.benchmark_group(name); | ||
group.throughput(criterion::Throughput::Elements(1)); | ||
group.bench_function( | ||
BenchmarkId::from_parameter(format!("{:#?}", inputs)), | ||
|bencher| { | ||
bencher.to_async(runtime).iter_batched( | ||
|| { | ||
input_cycle | ||
.next() | ||
.expect("Cycled inputs should be endless.") | ||
}, | ||
&routine, | ||
criterion::BatchSize::SmallInput, | ||
); | ||
}, | ||
); | ||
group.finish(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
pub mod benchmark; | ||
pub mod storage; | ||
|
||
pub mod datasets; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use chroma_blockstore::{ | ||
arrow::{config::TEST_MAX_BLOCK_SIZE_BYTES, provider::ArrowBlockfileProvider}, | ||
provider::BlockfileProvider, | ||
}; | ||
use chroma_cache::{ | ||
cache::{Cache, Cacheable}, | ||
config::{CacheConfig, UnboundedCacheConfig}, | ||
}; | ||
use chroma_storage::{local::LocalStorage, Storage}; | ||
use chroma_types::{Segment, SegmentScope, SegmentType}; | ||
use std::{collections::HashMap, hash::Hash}; | ||
use tempfile::TempDir; | ||
use uuid::Uuid; | ||
|
||
pub fn tmp_dir() -> TempDir { | ||
TempDir::new().expect("Should be able to create a temporary directory.") | ||
} | ||
|
||
pub fn storage() -> Storage { | ||
Storage::Local(LocalStorage::new(tmp_dir().into_path().to_str().expect( | ||
"Should be able to convert temporary directory path to string", | ||
))) | ||
} | ||
|
||
pub fn unbounded_cache<K, V>() -> Cache<K, V> | ||
where | ||
K: Send + Sync + Clone + Hash + Eq + 'static, | ||
V: Send + Sync + Clone + Cacheable + 'static, | ||
{ | ||
Cache::new(&CacheConfig::Unbounded(UnboundedCacheConfig {})) | ||
} | ||
|
||
pub fn arrow_blockfile_provider() -> BlockfileProvider { | ||
BlockfileProvider::ArrowBlockfileProvider(ArrowBlockfileProvider::new( | ||
storage(), | ||
TEST_MAX_BLOCK_SIZE_BYTES, | ||
unbounded_cache(), | ||
unbounded_cache(), | ||
)) | ||
} | ||
|
||
pub fn segment(scope: SegmentScope) -> Segment { | ||
use SegmentScope::*; | ||
use SegmentType::*; | ||
let r#type = match scope { | ||
METADATA => BlockfileMetadata, | ||
RECORD => BlockfileRecord, | ||
SQLITE | VECTOR => panic!("Unsupported segment scope in testing."), | ||
}; | ||
Segment { | ||
id: Uuid::new_v4(), | ||
r#type, | ||
scope, | ||
collection: Uuid::new_v4(), | ||
metadata: None, | ||
file_path: HashMap::new(), | ||
} | ||
} |