Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 655314110
  • Loading branch information
ksteuck authored and copybara-github committed Jul 23, 2024
1 parent f012ca5 commit 5d58ffa
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions centipede/centipede_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,15 @@ void SetSignalHandlers(absl::Time stop_at) {
const absl::Duration stop_in = stop_at - absl::Now();
// Setting an alarm works only if the delay is longer than 1 second.
if (stop_in >= absl::Seconds(1)) {
unsigned int seed = GetRandomSeed(0);
// Desynchronize Centipede tasks by adding a random delay of up to 10
// seconds to avoid traffic spikes caused by multiple tasks exiting
// simultaneously.
absl::Duration jitter = absl::Seconds(rand_r(&seed) % 10);
LOG(INFO) << "Setting alarm for --stop_at time " << stop_at << " (in "
<< stop_in << ")";
PCHECK(alarm(absl::ToInt64Seconds(stop_in)) == 0) << "Alarm already set";
<< stop_in << ") + " << jitter << "s of jitter";
PCHECK(alarm(absl::ToInt64Seconds(stop_in + jitter)) == 0)
<< "Alarm already set";
} else {
LOG(WARNING) << "Already reached --stop_at time " << stop_at
<< " upon starting: winding down immediately";
Expand Down

0 comments on commit 5d58ffa

Please sign in to comment.