scuffle-batching
[!WARNING]
This crate is under active development and may not be stable.
A crate designed to batch multiple requests into a single request.
Why do we need this?
Often when we are building applications we need to load multiple items from a database or some other external resource. It is often expensive to load each item individually, and this is typically why most drivers have some form of multi-item loading or executing. This crate provides an improved version of this functionality by combining multiple calls from different scopes into a single batched request.
Tradeoffs
Because we are buffering requests for a short period of time we do see higher latencies when there are not many requests. This is because the overhead from just processing the requests is lower then the time we spend buffering.
However, this is often negated when we have a large number of requests as we see on average lower latencies due to more efficient use of resources. Latency is also more consistent as we are doing fewer requests to the external resource.
Usage
Here is an example of how to use the DataLoader interface to batch multiple reads from a database.
;
let loader = new.build;
// Will only make a single request to the database and load both users
// You can also use `loader.load_many` if you have more then one item to load.
let : = join!;
Another use case might be to batch multiple writes to a database.
;
let batcher = new.build;
// Will only make a single request to the database and insert both users
// You can also use `batcher.execute_many` if you have more then one item to insert.
let = join!;
if success1.is_some_and
if success2.is_some_and
License
This project is licensed under the MIT or Apache-2.0 license. You can choose between one of them if you use this work.
SPDX-License-Identifier: MIT OR Apache-2.0