move calculations out of fast path
@@ -50,14 +50,14 @@ pub(crate) async fn user_main(
// If normal tasks are defined, loop launching tasks until parent tells us to stop.
if !thread_task_set.weighted_tasks.is_empty() {
+ // When there is a delay between tasks, wake every second to check for messages.
+ let one_second = tokio::time::Duration::from_secs(1);
+
'launch_tasks: loop {
// Tracks the time it takes to loop through all GooseTasks when Coordinated Omission
// Mitigation is enabled.
thread_user.update_request_cadence(thread_number).await;
- // When there is a delay between tasks, wake every second to check for messages.
- let one_second = tokio::time::Duration::from_secs(1);
-
for (thread_task_index, thread_task_name) in &thread_task_set.weighted_tasks {
// Determine which task we're going to run next.
let function = &thread_task_set.tasks[*thread_task_index].function;
@@ -75,17 +75,17 @@ pub(crate) async fn user_main(
.await;
// Prepare to sleep for a random value from min_wait to max_wait.
- let wait_time = if thread_user.max_wait.as_millis() > 0 {
- rand::thread_rng().gen_range(thread_user.min_wait..thread_user.max_wait)
- } else {
+ let wait_time = if thread_user.max_wait.is_zero() {
tokio::time::Duration::from_secs(0)
+ } else {
+ rand::thread_rng().gen_range(thread_user.min_wait..thread_user.max_wait)
};
// Also convert the duration to milliseconds.
let wait_time_millis = wait_time.as_millis();
+ if wait_time_millis > 0 {
// Counter to track how long we've slept, waking regularly to check for messages.
let mut slept: u128 = 0;
-
// Wake every second to check if the parent thread has told us to exit.
let mut in_sleep_loop = true;
// Track the time slept for Coordinated Omission Mitigation.
@@ -106,7 +106,6 @@ pub(crate) async fn user_main(
message = thread_receiver.try_recv();
}
- if wait_time_millis > 0 {
let sleep_duration = if wait_time_millis - slept >= 1000 {
slept += 1000;
if slept >= wait_time_millis {
@@ -127,9 +126,6 @@ pub(crate) async fn user_main(
);
tokio::time::sleep(sleep_duration).await;
- } else {
- in_sleep_loop = false;
- }
}
// Track how much time the GooseUser sleeps during this loop through all GooseTasks,
// used by Coordinated Omission Mitigation.
@@ -137,6 +133,7 @@ pub(crate) async fn user_main(
}
}
}
+ }
// User is exiting, first invoke the weighted on_stop tasks.
if !thread_task_set.weighted_on_stop_tasks.is_empty() {
