-
Notifications
You must be signed in to change notification settings - Fork 164
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
Serialization benchmarks. #808
Draft
arsh
wants to merge
2
commits into
awslabs:main
Choose a base branch
from
arsh:serialization-benches
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+246
−21
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,121 @@ | ||
use std::{fs, io::Write, path::PathBuf, sync::Arc}; | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
|
||
use mountpoint_s3::data_cache::{ | ||
Bincode2DiskBlockFileReader, Bincode2DiskBlockFileWriter, ChecksummedBytes, DataCache, DiskDataCache, | ||
DiskDataCacheConfig, ObjectId, | ||
}; | ||
use mountpoint_s3_client::types::ETag; | ||
use rand::Rng; | ||
const BLOCK_SIZE: u64 = 1024 * 1024; | ||
|
||
#[inline] | ||
fn read_cache_bincode() { | ||
let config = DiskDataCacheConfig { | ||
block_size: BLOCK_SIZE, | ||
limit: mountpoint_s3::data_cache::CacheLimit::Unbounded, | ||
..Default::default() | ||
}; | ||
let cache_directory = PathBuf::from("/tmp/mp-cache1/"); | ||
let cache = DiskDataCache::new(cache_directory, config); | ||
let cache_key = ObjectId::new("a".into(), ETag::for_tests()); | ||
let _data = cache | ||
.get_block(&cache_key, 0, 0) | ||
.expect("is able to read") | ||
.expect("data is there"); | ||
} | ||
|
||
#[inline] | ||
fn read_cache_bincode2() { | ||
let config = DiskDataCacheConfig { | ||
block_size: BLOCK_SIZE, | ||
limit: mountpoint_s3::data_cache::CacheLimit::Unbounded, | ||
reader: Arc::new(Bincode2DiskBlockFileReader {}), | ||
writer: Arc::new(Bincode2DiskBlockFileWriter {}), | ||
}; | ||
let cache_directory = PathBuf::from("/tmp/mp-cache2/"); | ||
let cache = DiskDataCache::new(cache_directory, config); | ||
let cache_key = ObjectId::new("a".into(), ETag::for_tests()); | ||
let _data = cache | ||
.get_block(&cache_key, 0, 0) | ||
.expect("is able to read") | ||
.expect("data is there"); | ||
} | ||
|
||
#[inline] | ||
fn read_file() { | ||
let _read = fs::read("/tmp/mp-file/file").expect("is able to read file"); | ||
} | ||
|
||
fn random_bytes(length: usize) -> Vec<u8> { | ||
let mut rng = rand::thread_rng(); | ||
let random_bytes: Vec<u8> = (0..length).map(|_| rng.gen()).collect(); | ||
random_bytes | ||
} | ||
|
||
fn write_file(data: &Vec<u8>) { | ||
fs::create_dir("/tmp/mp-file").expect("is able to create temp dir"); | ||
let file_path = "/tmp/mp-file/file"; | ||
let mut file = fs::File::create(file_path).expect("is able to create file"); | ||
file.write_all(data.as_slice()).expect("is able to write file"); | ||
} | ||
|
||
fn write_cache_bincode(data: &[u8]) { | ||
let config = DiskDataCacheConfig { | ||
block_size: BLOCK_SIZE, | ||
limit: mountpoint_s3::data_cache::CacheLimit::Unbounded, | ||
..Default::default() | ||
}; | ||
fs::create_dir("/tmp/mp-cache1").expect("is able to create dir 1"); | ||
let cache_dir = PathBuf::from("/tmp/mp-cache1/"); | ||
let cache = DiskDataCache::new(cache_dir, config); | ||
let cache_key = ObjectId::new("a".into(), ETag::for_tests()); | ||
let data = ChecksummedBytes::new(data.to_owned().into()); | ||
cache | ||
.put_block(cache_key.clone(), 0, 0, data) | ||
.expect("is able to write to cache"); | ||
} | ||
|
||
fn write_cache_bincode2(data: &[u8]) { | ||
let config = DiskDataCacheConfig { | ||
block_size: BLOCK_SIZE, | ||
limit: mountpoint_s3::data_cache::CacheLimit::Unbounded, | ||
reader: Arc::new(Bincode2DiskBlockFileReader {}), | ||
writer: Arc::new(Bincode2DiskBlockFileWriter {}), | ||
}; | ||
fs::create_dir("/tmp/mp-cache2").expect("is able to create dir 1"); | ||
let cache_dir = PathBuf::from("/tmp/mp-cache2/"); | ||
let cache = DiskDataCache::new(cache_dir, config); | ||
let cache_key = ObjectId::new("a".into(), ETag::for_tests()); | ||
let data = ChecksummedBytes::new(data.to_owned().into()); | ||
cache | ||
.put_block(cache_key.clone(), 0, 0, data) | ||
.expect("is able to write to cache"); | ||
} | ||
|
||
fn cleanup() { | ||
let _ = fs::remove_dir_all("/tmp/mp-file"); | ||
let _ = fs::remove_dir_all("/tmp/mp-cache1"); | ||
let _ = fs::remove_dir_all("/tmp/mp-cache2"); | ||
} | ||
|
||
fn setup() { | ||
let data = random_bytes(BLOCK_SIZE.try_into().unwrap()); | ||
write_file(&data); | ||
write_cache_bincode(&data); | ||
write_cache_bincode2(&data); | ||
} | ||
|
||
pub fn criterion_benchmark(c: &mut Criterion) { | ||
setup(); | ||
|
||
c.bench_function("read_cache_bincode", |b| b.iter(read_cache_bincode)); | ||
c.bench_function("read_cache_bincode2", |b| b.iter(read_cache_bincode2)); | ||
c.bench_function("read_file", |b| b.iter(read_file)); | ||
|
||
cleanup(); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that we have to take a non-dev-dependency on "all the versions we want to benchmark" here. I'd rather put it behind a feature flag, or just not commit the versions we're not using.