Skip to content

Commit

Permalink
g3bench: add option to ignore fatal error
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-jq-b committed Oct 20, 2023
1 parent 8c545b3 commit e21bc6c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
13 changes: 13 additions & 0 deletions g3bench/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const GLOBAL_ARG_TIME_LIMIT: &str = "time-limit";
const GLOBAL_ARG_REQUESTS: &str = "requests";
const GLOBAL_ARG_RESOLVE: &str = "resolve";
const GLOBAL_ARG_LOG_ERROR: &str = "log-error";
const GLOBAL_ARG_IGNORE_FATAL_ERROR: &str = "ignore-fatal-error";
const GLOBAL_ARG_EMIT_METRICS: &str = "emit-metrics";
const GLOBAL_ARG_STATSD_TARGET_UDP: &str = "statsd-target-udp";
const GLOBAL_ARG_STATSD_TARGET_UNIX: &str = "statsd-target-unix";
Expand All @@ -62,6 +63,7 @@ pub struct ProcArgs {
pub(super) requests: Option<usize>,
pub(super) time_limit: Option<Duration>,
pub(super) log_error_count: usize,
pub(super) ignore_fatal_error: bool,
pub(super) task_unconstrained: bool,
resolver: AHashMap<UpstreamAddr, IpAddr>,
pub(super) use_unaided_worker: bool,
Expand All @@ -84,6 +86,7 @@ impl Default for ProcArgs {
requests: None,
time_limit: None,
log_error_count: 0,
ignore_fatal_error: false,
task_unconstrained: false,
resolver: AHashMap::new(),
use_unaided_worker: false,
Expand Down Expand Up @@ -322,6 +325,13 @@ pub fn add_global_args(app: Command) -> Command {
.num_args(1)
.value_parser(value_parser!(usize)),
)
.arg(
Arg::new(GLOBAL_ARG_IGNORE_FATAL_ERROR)
.help("Continue even if fatal error occurred")
.long(GLOBAL_ARG_IGNORE_FATAL_ERROR)
.global(true)
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(GLOBAL_ARG_EMIT_METRICS)
.help("Set if we need to emit metrics to statsd")
Expand Down Expand Up @@ -435,6 +445,9 @@ pub fn parse_global_args(args: &ArgMatches) -> anyhow::Result<ProcArgs> {
if let Some(n) = args.get_one::<usize>(GLOBAL_ARG_LOG_ERROR) {
proc_args.log_error_count = *n;
}
if args.get_flag(GLOBAL_ARG_IGNORE_FATAL_ERROR) {
proc_args.ignore_fatal_error = true;
}

if args.get_flag(GLOBAL_ARG_EMIT_METRICS) {
let mut config =
Expand Down
13 changes: 10 additions & 3 deletions g3bench/src/target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ where

let task_unconstrained = proc_args.task_unconstrained;
let latency = proc_args.latency;
let ignore_fatal_error = proc_args.ignore_fatal_error;
let rt = super::worker::select_handle(i).unwrap_or_else(tokio::runtime::Handle::current);
rt.spawn(async move {
sem.add_permits(1);
Expand Down Expand Up @@ -217,15 +218,21 @@ where
Err(BenchError::Fatal(e)) => {
context.mark_task_failed();
global_state.add_failed();
eprintln!("!! Fatal error with task context {i}: {e:?}");
break;
if ignore_fatal_error {
if global_state.check_log_error() {
eprintln!("! request {task_id} failed: {e:?}\n");
}
} else {
eprintln!("!! Fatal error with task context {i}: {e:?}");
break;
}
}
Err(BenchError::Task(e)) => {
context.mark_task_failed();
global_state.add_failed();
if global_state.check_log_error() {
eprintln!("! request {task_id} failed: {e:?}\n");
}
global_state.add_failed();
}
}
req_count += 1;
Expand Down

0 comments on commit e21bc6c

Please sign in to comment.