Skip to content

Commit 51367e9

Browse files
committed
test: add benchmark for tonbo on s3
1 parent d10083e commit 51367e9

File tree

3 files changed

+113
-5
lines changed

3 files changed

+113
-5
lines changed

benches/common.rs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{
77
};
88

99
use async_stream::stream;
10+
use fusio_dispatch::FsOptions;
1011
use futures_core::Stream;
1112
use futures_util::StreamExt;
1213
use parquet::data_type::AsBytes;
@@ -184,6 +185,97 @@ pub trait BenchReader {
184185
) -> impl Stream<Item = ProjectionResult> + 'a;
185186
}
186187

188+
pub struct TonboS3BenchDataBase {
189+
db: tonbo::DB<Customer, TokioExecutor>,
190+
}
191+
192+
impl TonboS3BenchDataBase {
193+
#[allow(dead_code)]
194+
pub fn new(db: tonbo::DB<Customer, TokioExecutor>) -> Self {
195+
TonboS3BenchDataBase { db }
196+
}
197+
}
198+
199+
impl BenchDatabase for TonboS3BenchDataBase {
200+
type W<'db>
201+
= TonboBenchWriteTransaction<'db>
202+
where
203+
Self: 'db;
204+
type R<'db>
205+
= TonboBenchReadTransaction<'db>
206+
where
207+
Self: 'db;
208+
209+
fn db_type_name() -> &'static str {
210+
"tonbo on s3"
211+
}
212+
213+
async fn write_transaction(&self) -> Self::W<'_> {
214+
TonboBenchWriteTransaction {
215+
txn: self.db.transaction().await,
216+
}
217+
}
218+
219+
async fn read_transaction(&self) -> Self::R<'_> {
220+
TonboBenchReadTransaction {
221+
txn: self.db.transaction().await,
222+
}
223+
}
224+
225+
async fn build(path: impl AsRef<Path>) -> Self {
226+
create_dir_all(path.as_ref()).await.unwrap();
227+
228+
let fs_options = FsOptions::S3 {
229+
bucket: "data".to_string(),
230+
credential: Some(fusio::remotes::aws::credential::AwsCredential {
231+
key_id: "user".to_string(),
232+
secret_key: "password".to_string(),
233+
token: None,
234+
}),
235+
endpoint: Some("http://localhost:9000".to_string()),
236+
sign_payload: None,
237+
checksum: None,
238+
region: None,
239+
};
240+
241+
let path = fusio::path::Path::from_filesystem_path(path.as_ref()).unwrap();
242+
let option = DbOption::from(path.clone())
243+
.level_path(
244+
0,
245+
fusio::path::Path::from_url_path("/l0").unwrap(),
246+
fs_options.clone(),
247+
)
248+
.unwrap()
249+
.level_path(
250+
1,
251+
fusio::path::Path::from_url_path("/l1").unwrap(),
252+
fs_options.clone(),
253+
)
254+
.unwrap()
255+
.level_path(
256+
2,
257+
fusio::path::Path::from_url_path("/l2").unwrap(),
258+
fs_options.clone(),
259+
)
260+
.unwrap()
261+
.level_path(
262+
3,
263+
fusio::path::Path::from_url_path("/l3").unwrap(),
264+
fs_options.clone(),
265+
)
266+
.unwrap()
267+
.level_path(
268+
4,
269+
fusio::path::Path::from_url_path("/l4").unwrap(),
270+
fs_options.clone(),
271+
)
272+
.unwrap()
273+
.disable_wal();
274+
275+
TonboS3BenchDataBase::new(tonbo::DB::new(option, TokioExecutor::new()).await.unwrap())
276+
}
277+
}
278+
187279
pub struct TonboBenchDataBase {
188280
db: tonbo::DB<Customer, TokioExecutor>,
189281
}

benches/read_bench.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use tokio::{fs, io::AsyncWriteExt};
1212

1313
use crate::common::{
1414
read_tbl, BenchDatabase, BenchReadTransaction, BenchReader, RedbBenchDatabase,
15-
RocksdbBenchDatabase, SledBenchDatabase, TonboBenchDataBase, ITERATIONS, NUM_SCAN, READ_TIMES,
15+
RocksdbBenchDatabase, SledBenchDatabase, TonboBenchDataBase, TonboS3BenchDataBase, ITERATIONS,
16+
NUM_SCAN, READ_TIMES,
1617
};
1718

1819
async fn benchmark<T: BenchDatabase + Send + Sync>(
@@ -152,26 +153,33 @@ async fn main() {
152153

153154
load::<TonboBenchDataBase>(&tbl_path, data_dir.join("tonbo")).await;
154155
load::<RocksdbBenchDatabase>(&tbl_path, data_dir.join("rocksdb")).await;
156+
load::<TonboS3BenchDataBase>(&tbl_path, data_dir.join("tonbo_s3")).await;
155157
}
156158

157159
let tonbo_latency_results = { benchmark::<TonboBenchDataBase>(data_dir.join("tonbo")).await };
158160
let rocksdb_results = { benchmark::<RocksdbBenchDatabase>(data_dir.join("rocksdb")).await };
161+
let tonbo_s3_latency_results =
162+
{ benchmark::<TonboS3BenchDataBase>(data_dir.join("tonbo_s3")).await };
159163

160164
let mut rows: Vec<Vec<String>> = Vec::new();
161165

162166
for (benchmark, _duration) in &tonbo_latency_results {
163167
rows.push(vec![benchmark.to_string()]);
164168
}
165169

166-
for results in [tonbo_latency_results, rocksdb_results] {
170+
for results in [
171+
tonbo_latency_results,
172+
rocksdb_results,
173+
tonbo_s3_latency_results,
174+
] {
167175
for (i, (_benchmark, duration)) in results.iter().enumerate() {
168176
rows[i].push(format!("{}ms", duration.as_millis()));
169177
}
170178
}
171179

172180
let mut table = comfy_table::Table::new();
173181
table.set_width(100);
174-
table.set_header(["", "tonbo", "rocksdb"]);
182+
table.set_header(["", "tonbo", "rocksdb", "tonbo_s3"]);
175183
for row in rows {
176184
table.add_row(row);
177185
}

benches/write_bench.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ async fn main() {
201201
let tmp_file: TempDir = tempfile::tempdir_in(&tmpdir).unwrap();
202202
benchmark::<RocksdbBenchDatabase>(tmp_file.path()).await
203203
};
204+
let tonbo_s3_latency_results = {
205+
let tmp_file: TempDir = tempfile::tempdir_in(&tmpdir).unwrap();
206+
benchmark::<TonboS3BenchDataBase>(tmp_file.path()).await
207+
};
204208

205209
let _ = fs::remove_dir_all(&tmpdir);
206210

@@ -210,15 +214,19 @@ async fn main() {
210214
rows.push(vec![benchmark.to_string()]);
211215
}
212216

213-
for results in [tonbo_latency_results, rocksdb_results] {
217+
for results in [
218+
tonbo_latency_results,
219+
rocksdb_results,
220+
tonbo_s3_latency_results,
221+
] {
214222
for (i, (_benchmark, duration)) in results.iter().enumerate() {
215223
rows[i].push(format!("{}ms", duration.as_millis()));
216224
}
217225
}
218226

219227
let mut table = comfy_table::Table::new();
220228
table.set_width(100);
221-
table.set_header(["", "tonbo", "rocksdb"]);
229+
table.set_header(["", "tonbo", "rocksdb", "tonbo_s3"]);
222230
for row in rows {
223231
table.add_row(row);
224232
}

0 commit comments

Comments
 (0)