Skip to content

Commit

Permalink
use Bytes instead of static slice
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 committed Aug 12, 2024
1 parent 4d60f41 commit 6e34bff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions runners/s3-benchrunner-rust/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 runners/s3-benchrunner-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ serde_json = "1.0.120"
thiserror = "1.0.62"
tokio = { version = "1.38.1", features = ["io-util"] }
rand = "0.8.4"
bytes = "1"
17 changes: 12 additions & 5 deletions runners/s3-benchrunner-rust/src/transfer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ use tokio::task::JoinSet;

use crate::{
BenchmarkConfig, Result, RunBenchmark, RunnerError, TaskAction, TaskConfig, PART_SIZE,

};
use bytes::Bytes;


/// Benchmark runner using aws-s3-transfer-manager
#[derive(Clone)]
Expand All @@ -24,7 +27,7 @@ pub struct TransferManagerRunner {
struct Handle {
config: BenchmarkConfig,
transfer_manager: aws_s3_transfer_manager::Client,
random_data_for_upload:&'static [u8]
random_data_for_upload: Bytes,
}

impl TransferManagerRunner {
Expand Down Expand Up @@ -52,8 +55,11 @@ impl TransferManagerRunner {
.try_into()
.unwrap()
};
let mut random_data_for_upload = Vec::new();
random_data_for_upload.resize_with(upload_data_size, rand::random::<u8>);
let random_data_for_upload: Bytes = {
let mut data = Vec::new();
data.resize_with(upload_data_size, rand::random::<u8>);
data.into()
};

let s3_client = aws_sdk_s3::Client::new(&sdk_config);
let tm_config = aws_s3_transfer_manager::Config::builder()
Expand All @@ -68,7 +74,7 @@ impl TransferManagerRunner {
handle: Arc::new(Handle {
config,
transfer_manager,
random_data_for_upload: Box::leak(random_data_for_upload.into_boxed_slice()),
random_data_for_upload,
}),
}
}
Expand Down Expand Up @@ -139,9 +145,10 @@ impl TransferManagerRunner {

let stream = match self.config().workload.files_on_disk {
true => InputStream::from_path(key).with_context(|| "Failed to create stream")?,
false => InputStream::from_static(self.handle.random_data_for_upload),
false => self.handle.random_data_for_upload.clone().into(),
};


self.handle
.transfer_manager
.upload()
Expand Down

0 comments on commit 6e34bff

Please sign in to comment.