Skip to content

RUST-2004 Benchmark client bulk write#1293

Merged
isabelatkinson merged 8 commits into
mongodb:mainfrom
isabelatkinson:benchmark-bulk-write
Feb 3, 2025
Merged

RUST-2004 Benchmark client bulk write#1293
isabelatkinson merged 8 commits into
mongodb:mainfrom
isabelatkinson:benchmark-bulk-write

Conversation

@isabelatkinson
Copy link
Copy Markdown
Contributor

@isabelatkinson isabelatkinson commented Jan 29, 2025

RUST-2004

This also includes some clippy fixes/general cleanup in the second and third commits.

@isabelatkinson isabelatkinson marked this pull request as ready for review January 30, 2025 20:16
Comment thread benchmarks/src/bench.rs Outdated
.expect("invalid TARGET_ITERATION_COUNT")
});

static SMALL_DOC: OnceCell<Document> = OnceCell::const_new();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think these statics can be moved into the scope of the get_ functions that use them.

Comment thread benchmarks/src/bench.rs Outdated
let data_path = DATA_PATH
.join("single_and_multi_document")
.join("small_doc.json");
let mut file = spawn_blocking_and_await!(std::fs::File::open(data_path))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It might be worth factoring out a utility function like

async fn from_json_file<T: DeserializeOwned>(path: impl AsRef<Path>) -> Result<T>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, added a util function and statics for the other json files we read

Comment thread benchmarks/src/bench.rs Outdated
}

async fn do_task(&self) -> Result<()>;
async fn do_task(&mut self) -> Result<()>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the introduction of mut here is to support copying the write models in before_task rather than do_task (which absolutely makes sense).

Personally, I'd rather avoid the mut on do_task because I think it makes it harder to reason about; how would you feel about, instead, updating the Benchmark trait with

type TaskState = ();
async fn before_task(&mut self) -> Result<TaskState> {
    Ok(())
}
async fn do_task(&self, state: TaskState) -> Result<()>;

That avoids the need for mut and the Option/take ceremony, but might be more type-level complication than it's worth. WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea - I never love an option/take hack like this. updated with your suggestion, it's a bit noisy to add type TaskState = () to all the types but hopefully associated type defaults will be stabilized sometime soon

Copy link
Copy Markdown
Contributor Author

@isabelatkinson isabelatkinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread benchmarks/src/bench.rs Outdated
let data_path = DATA_PATH
.join("single_and_multi_document")
.join("small_doc.json");
let mut file = spawn_blocking_and_await!(std::fs::File::open(data_path))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, added a util function and statics for the other json files we read

Comment thread benchmarks/src/bench.rs Outdated
}

async fn do_task(&self) -> Result<()>;
async fn do_task(&mut self) -> Result<()>;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea - I never love an option/take hack like this. updated with your suggestion, it's a bit noisy to add type TaskState = () to all the types but hopefully associated type defaults will be stabilized sometime soon

@isabelatkinson isabelatkinson merged commit d8fb500 into mongodb:main Feb 3, 2025
@isabelatkinson isabelatkinson deleted the benchmark-bulk-write branch March 17, 2025 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants