Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReWrk 0.5 #34

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
[package]
name = "rewrk"
version = "0.3.2"
authors = ["Harrison Burt <[email protected].com>", "Programatik <[email protected]>"]
version = "0.4.0"
authors = ["Harrison Burt <hburt2003@gmail.com>", "Programatik <[email protected]>"]
edition = "2018"

[dependencies]
anyhow = "1"
clap = "2"
colored = "2"
futures-util = "0.3"
http = "0.2"
hyper = { version = "0.14", features = ["runtime", "client", "http1", "http2"] }
native-tls = { version = "0.2", features = ["alpn"] }
pin-project-lite = "0.2"
regex = "1"
rand = "0.8"
serde_json = "1"
tokio = { version = "1", features = ["rt", "rt-multi-thread", "net", "macros"] }
tokio-native-tls = "0.3"
tower = { version = "0.4", features = ["util"] }
url = "1.7.2"
humantime = "2.1.0"
http = "0.2.8"

clap = { version = "3", features = ["derive", "env"] }


[workspace]
members = [
"rewrk-bench",
"rewrk-connection",
"rewrk-results",
"rewrk-setup",
]
8 changes: 8 additions & 0 deletions rewrk-bench/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "rewrk-bench"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
8 changes: 8 additions & 0 deletions rewrk-bench/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
}
9 changes: 9 additions & 0 deletions rewrk-connection/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "rewrk-connection"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
thiserror = "1.0.31"
8 changes: 8 additions & 0 deletions rewrk-connection/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
}
8 changes: 8 additions & 0 deletions rewrk-results/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "rewrk-results"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
8 changes: 8 additions & 0 deletions rewrk-results/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
}
10 changes: 10 additions & 0 deletions rewrk-setup/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "rewrk-setup"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rhai = "1.8.0"
tracing = "0.1.35"
Empty file added rewrk-setup/src/builtins.rs
Empty file.
33 changes: 33 additions & 0 deletions rewrk-setup/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#[macro_use]
extern crate tracing;

use std::fmt::Display;
use rhai::{Dynamic, EvalAltResult, ImmutableString};

mod builtins;


fn register_builtins(engine: &mut rhai::Engine) {
engine
.register_fn("log_info", log_info)
.register_fn("log_warn", log_warn)
.register_fn("log_error", log_error)
.register_fn("fetch", fetch);
}


fn log_info(t: &Dynamic) {
info!("{}", t)
}

fn log_warn(t: &Dynamic) {
warn!("{}", t)
}

fn log_error(t: &Dynamic) {
error!("{}", t)
}

fn fetch(method: &str, ) -> Result<(), Box<EvalAltResult>> {
todo!()
}
Empty file added scripting.md
Empty file.
75 changes: 75 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use std::path::PathBuf;
use std::time::Duration;
use clap::Parser;
use url::Url;


#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
/// A more modern http framework benchmarker supporting HTTP/1 and HTTP/2 benchmarks.
pub struct Args {
#[clap(short, long, env, default_value_t = 1)]
/// The number of runtime threads to use during the benchmark.
pub threads: usize,

#[clap(short, long, env, default_value_t = 64)]
/// The number of concurrent connections during the benchmark.
pub concurrency: usize,

#[clap(short, long, env, value_parser = check_address)]
/// The server host address.
pub address: Url,

#[clap(long, env)]
/// Set the benchmarker client to use HTTP2 only.
pub http2_only: bool,

#[clap(short, long, env, value_parser = parse_duration)]
/// The duration to run the benchmark for, this can be
/// passed in the format `12h 5min 2ns` etc...
pub duration: Duration,

#[clap(long, env, value_parser = parse_duration, default_value = "0s")]
/// The duration to run a warmup benchmark which is ran before the sample are taken,
/// this can be passed in the format `12h 5min 2ns` etc...
pub warmup: Duration,

#[clap(long, env, default_value_t = 1)]
/// The number of times to repeat the benchmark and sample taking.
pub rounds: usize,

#[clap(long, env, default_value_t = http::Method::GET)]
/// The HTTP method to use during requests.
pub method: http::Method,

#[clap(long, env)]
/// The body of the HTTP requests. This can either be the raw body, or a path to a file.
pub body: Option<String>,

#[clap(long, env, value_parser = parse_duration)]
/// An optional setup script to run which is executed at the start of each round.
///
/// This must be a `rhai` script. See `scripting.md` for more.
pub setup: Option<PathBuf>,
}

fn check_address(s: &str) -> Result<Url, String> {
Url::parse(s).map_err(|e| e.to_string())
}

fn parse_duration(s: &str) -> Result<Duration, String> {
humantime::parse_duration(s).map_err(|e| e.to_string())
}

fn parse_file_path(s: &str) -> Result<PathBuf, String> {
let path = PathBuf::from(s);

if !path.exists() {
return Err(format!(
"Cannot find setup script file @ {:?}",
path.canonicalize().unwrap_or_else(|_| path),
))
}

Ok(path)
}
Loading