From 4634ac484a03f88f716429712504e7c354441c0b Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Wed, 12 Oct 2022 18:19:06 +0200 Subject: [PATCH 1/2] Optimize simulator RNG usage (#590) This causes instructions for `basic_request.cpp` to drop from 281 million to 28 million --- src/io/simulator/simulator_handle.cpp | 6 ++---- src/io/simulator/simulator_handle.hpp | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/io/simulator/simulator_handle.cpp b/src/io/simulator/simulator_handle.cpp index fe4bc8c1f..9fa16fae3 100644 --- a/src/io/simulator/simulator_handle.cpp +++ b/src/io/simulator/simulator_handle.cpp @@ -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 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) { diff --git a/src/io/simulator/simulator_handle.hpp b/src/io/simulator/simulator_handle.hpp index 7ad1d795a..3adf2b7b0 100644 --- a/src/io/simulator/simulator_handle.hpp +++ b/src/io/simulator/simulator_handle.hpp @@ -51,6 +51,8 @@ class SimulatorHandle { std::set
blocked_on_receive_; std::set
server_addresses_; std::mt19937 rng_; + std::uniform_int_distribution time_distrib_{5, 50}; + std::uniform_int_distribution drop_distrib_{0, 99}; SimulatorConfig config_; void TimeoutPromisesPastDeadline() { From 5347c06d7614dc13311819aa7e8e2c2c7a66a7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Budiseli=C4=87?= Date: Fri, 14 Oct 2022 11:59:50 +0200 Subject: [PATCH 2/2] Add shutdown of `LocalSystem` during the shutdown process (#592) --- src/memgraph.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/memgraph.cpp b/src/memgraph.cpp index 023135478..7d821b3e6 100644 --- a/src/memgraph.cpp +++ b/src/memgraph.cpp @@ -690,7 +690,7 @@ int main(int argc, char **argv) { std::optional telemetry; // Handler for regular termination signals - auto shutdown = [&server, &interpreter_context] { + auto shutdown = [&server, &interpreter_context, &ls] { // Server needs to be shutdown first and then the database. This prevents // a race condition when a transaction is accepted during server shutdown. server.Shutdown(); @@ -698,6 +698,7 @@ int main(int argc, char **argv) { // connections we tell the execution engine to stop processing all pending // queries. memgraph::query::v2::Shutdown(&interpreter_context); + ls.ShutDown(); }; InitSignalHandlers(shutdown);