Skip to content

Commit

Permalink
feat(bin/oli): implement oli bench (#5443)
Browse files Browse the repository at this point in the history
Co-authored-by: Yu Lei <[email protected]>
  • Loading branch information
tisonkun and leiysky authored Dec 24, 2024
1 parent 1bf1578 commit 260fcd4
Show file tree
Hide file tree
Showing 19 changed files with 667 additions and 42 deletions.
43 changes: 43 additions & 0 deletions bin/oli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion bin/oli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ anyhow = { version = "1.0" }
clap = { version = "4.5", features = ["cargo", "string", "derive"] }
dirs = { version = "5.0" }
futures = { version = "0.3" }
humansize = { version = "2.1" }
humantime = { version = "2.1" }
humantime-serde = { version = "1.1" }
indicatif = { version = "0.17" }
opendal = { version = "0.51.0", path = "../../core", features = [
"services-azblob",
Expand All @@ -44,18 +47,20 @@ opendal = { version = "0.51.0", path = "../../core", features = [
"services-ghac",
"services-http",
"services-ipmfs",
"services-memory",
"services-obs",
"services-oss",
"services-s3",
"services-webdav",
"services-webhdfs",
"services-azfile",
] }
pollster = { version = "0.4" }
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.42", features = ["full"] }
toml = { version = "0.8" }
url = { version = "2.5" }
uuid = { version = "1.11" }
parse-size = { version = "1.1" }

[dev-dependencies]
assert_cmd = { version = "2.0" }
Expand Down
22 changes: 11 additions & 11 deletions bin/oli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
`oli` could be installed by `cargo`:

```bash
cargo install oli --all-features
cargo install oli
```

> `cargo` is the Rust package manager. `cargo` could be installed by following the [Installation](https://www.rust-lang.org/tools/install) from Rust official website.
Expand Down Expand Up @@ -67,23 +67,23 @@ access_key_id = "<access_key_id>"
secret_access_key = "<secret_access_key>"
```

For different services, you could find the configuration keys in the corresponding [service document](https://opendal.apache.org/docs/services/).
For different services, you could find the configuration keys in the corresponding [service document](https://docs.rs/opendal/0.50.2/opendal/services/index.html).

### Example: use `oli` to upload file to AWS S3

```text
$ oli cp ./update-ecs-loadbalancer.json s3:/update-ecs-loadbalancer.json
$ oli ls s3:/
fleet.png
update-ecs-loadbalancer.json
```shell
oli cp ./update-ecs-loadbalancer.json s3:/update-ecs-loadbalancer.json
oli ls s3:/
# fleet.png
# update-ecs-loadbalancer.json
```

### Example: use `oli` copy file from S3 to R2

```text
$ oli cp s3:/fleet.png r2:/fleet.png
$ oli ls r2:/
fleet.png
```shell
oli cp s3:/fleet.png r2:/fleet.png
oli ls r2:/
# fleet.png
```

## Contribute to `oli`
Expand Down
26 changes: 26 additions & 0 deletions bin/oli/dev/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

[profiles.demo]
type = "s3"
root = "/benchmarks"
bucket = "test-bucket"
region = "us-east-1"
endpoint = "http://127.0.0.1:9000"
access_key_id = "minioadmin"
secret_access_key = "minioadmin"
virtual_host_style = "false"
21 changes: 21 additions & 0 deletions bin/oli/dev/suite.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

workload = "upload"
parallelism = 4
file_size = "64MiB"
timeout = "60s"
28 changes: 16 additions & 12 deletions bin/oli/src/bin/oli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::env;
use std::ffi::OsStr;
use std::path::PathBuf;

use anyhow::anyhow;
use anyhow::bail;
use anyhow::Result;
use oli::commands::OliSubcommand;

Expand All @@ -37,8 +37,7 @@ pub struct Oli {
subcommand: OliSubcommand,
}

#[tokio::main]
async fn main() -> Result<()> {
fn main() -> Result<()> {
// Guard against infinite proxy recursion. This mostly happens due to
// bugs in oli.
do_recursion_guard()?;
Expand All @@ -52,36 +51,40 @@ async fn main() -> Result<()> {
{
Some("oli") => {
let cmd: Oli = clap::Parser::parse();
cmd.subcommand.run().await?;
cmd.subcommand.run()?;
}
Some("obench") => {
let cmd: oli::commands::bench::BenchCmd = clap::Parser::parse();
cmd.run()?;
}
Some("ocat") => {
let cmd: oli::commands::cat::CatCmd = clap::Parser::parse();
cmd.run().await?;
cmd.run()?;
}
Some("ocp") => {
let cmd: oli::commands::cp::CopyCmd = clap::Parser::parse();
cmd.run().await?;
cmd.run()?;
}
Some("ols") => {
let cmd: oli::commands::ls::LsCmd = clap::Parser::parse();
cmd.run().await?;
cmd.run()?;
}
Some("orm") => {
let cmd: oli::commands::rm::RmCmd = clap::Parser::parse();
cmd.run().await?;
cmd.run()?;
}
Some("ostat") => {
let cmd: oli::commands::stat::StatCmd = clap::Parser::parse();
cmd.run().await?;
cmd.run()?;
}
Some("omv") => {
let cmd: oli::commands::mv::MoveCmd = clap::Parser::parse();
cmd.run().await?;
cmd.run()?;
}
Some(v) => {
println!("{v} is not supported")
}
None => return Err(anyhow!("couldn't determine self executable name")),
None => bail!("couldn't determine self executable name"),
}

Ok(())
Expand All @@ -94,8 +97,9 @@ fn do_recursion_guard() -> Result<()> {
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(0);

if recursion_count > OLI_RECURSION_COUNT_MAX {
return Err(anyhow!("infinite recursion detected"));
bail!("infinite recursion detected");
}

Ok(())
Expand Down
53 changes: 53 additions & 0 deletions bin/oli/src/commands/bench/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

use crate::config::Config;
use crate::params::config::ConfigParams;
use anyhow::Result;
use std::path::PathBuf;

mod report;
mod suite;

#[derive(Debug, clap::Parser)]
#[command(
name = "bench",
about = "Run benchmark against the storage backend",
disable_version_flag = true
)]
pub struct BenchCmd {
#[command(flatten)]
pub config_params: ConfigParams,
/// Name of the profile to use.
#[arg()]
pub profile: String,
/// Path to the benchmark config.
#[arg(
value_parser = clap::value_parser!(PathBuf),
)]
pub bench: PathBuf,
}

impl BenchCmd {
pub fn run(self) -> Result<()> {
let cfg = Config::load(&self.config_params.config)?;
let suite = suite::BenchSuite::load(&self.bench)?;
let op = cfg.operator(&self.profile)?;
suite.run(op)?;
Ok(())
}
}
Loading

0 comments on commit 260fcd4

Please sign in to comment.