Optimize simulator RNG usage (#590)

This causes instructions for `basic_request.cpp` to drop from 281 million to 28 million
This commit is contained in:
Tyler Neely 2022-10-12 18:19:06 +02:00 committed by GitHub
parent 4cb3b064c4
commit 4634ac484a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -73,8 +73,7 @@ bool SimulatorHandle::MaybeTickSimulator() {
// We tick the clock forward when all servers are blocked but
// there are no in-flight messages to schedule delivery of.
std::poisson_distribution<> time_distrib(50);
Duration clock_advance = std::chrono::microseconds{time_distrib(rng_)};
const Duration clock_advance = std::chrono::microseconds{time_distrib_(rng_)};
cluster_wide_time_microseconds_ += clock_advance;
MG_ASSERT(cluster_wide_time_microseconds_ < config_.abort_time,
@ -93,8 +92,7 @@ bool SimulatorHandle::MaybeTickSimulator() {
auto [to_address, opaque_message] = std::move(in_flight_.back());
in_flight_.pop_back();
std::uniform_int_distribution<int> drop_distrib(0, 99);
const int drop_threshold = drop_distrib(rng_);
const int drop_threshold = drop_distrib_(rng_);
const bool should_drop = drop_threshold < config_.drop_percent;
if (should_drop) {

View File

@ -51,6 +51,8 @@ class SimulatorHandle {
std::set<Address> blocked_on_receive_;
std::set<Address> server_addresses_;
std::mt19937 rng_;
std::uniform_int_distribution<int> time_distrib_{5, 50};
std::uniform_int_distribution<int> drop_distrib_{0, 99};
SimulatorConfig config_;
void TimeoutPromisesPastDeadline() {