Skip to content

Commit

Permalink
admin: lazy-init host stats and run with/without host stats for Json-…
Browse files Browse the repository at this point in the history
…histograms (envoyproxy#32197)

Commit Message: Works around n^2 issue when destructing hundreds of thousands of mocks in the benchmark context. It does thi s by:

only initializing the hosts when per-host stats are enabled in the cluster config
adding a 'disabled' and 'enabled' variant to the histogram-json test so that it's easy to filter using --benchmark_filter=disabled to avoid initializing the hosts.
See also: envoyproxy#32198 -- this doesn't fix that bug but we could in theory revert this PR once that bug is fixed.
Additional Description:
Risk Level: low
Testing: just the one test
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

Signed-off-by: Joshua Marantz <[email protected]>
  • Loading branch information
jmarantz authored Feb 5, 2024
1 parent 8132855 commit bac2ed0
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions test/server/admin/stats_handler_speed_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ class StatsHandlerTest : public Stats::ThreadLocalRealThreadsMixin {
}
}
store_->mergeHistograms([]() {});
}

void initClusterInfo() {
ENVOY_LOG_MISC(error, "Initializing cluster info; slow to construct and destruct...");
endpoint_stats_initialized_ = true;

cm_.store_.fixed_tags_ = Stats::TagVector{{"fixed-tag", "fixed-value"}};
for (uint32_t i = 0; i < NumClusters; i++) {
Expand All @@ -169,7 +174,12 @@ class StatsHandlerTest : public Stats::ThreadLocalRealThreadsMixin {
}
}

void setPerEndpointStats(bool enabled) { cm_.per_endpoint_enabled_ = enabled; }
void setPerEndpointStats(bool enabled) {
if (enabled && !endpoint_stats_initialized_) {
initClusterInfo();
}
cm_.per_endpoint_enabled_ = enabled;
}

/**
* Issues an admin request against the stats saved in store_.
Expand All @@ -196,6 +206,7 @@ class StatsHandlerTest : public Stats::ThreadLocalRealThreadsMixin {
std::vector<Stats::ScopeSharedPtr> scopes_;
Envoy::Stats::CustomStatNamespacesImpl custom_namespaces_;
FastMockClusterManager cm_;
bool endpoint_stats_initialized_{false};
};

} // namespace Server
Expand Down Expand Up @@ -408,8 +419,8 @@ BENCHMARK_CAPTURE(BM_FilteredCountersPrometheus, per_endpoint_stats_enabled, tru
->Unit(benchmark::kMillisecond);

// NOLINTNEXTLINE(readability-identifier-naming)
static void BM_HistogramsJson(benchmark::State& state) {
Envoy::Server::StatsHandlerTest& test_context = testContext(false);
static void BM_HistogramsJson(benchmark::State& state, bool per_endpoint_stats) {
Envoy::Server::StatsHandlerTest& test_context = testContext(per_endpoint_stats);
Envoy::Server::StatsParams params;
Envoy::Buffer::OwnedImpl response;
params.parse("?format=json&type=Histograms&histogram_buckets=detailed", response);
Expand All @@ -424,4 +435,7 @@ static void BM_HistogramsJson(benchmark::State& state) {
auto label = absl::StrCat("output per iteration: ", count);
state.SetLabel(label);
}
BENCHMARK(BM_HistogramsJson)->Unit(benchmark::kMillisecond);
BENCHMARK_CAPTURE(BM_HistogramsJson, per_endpoint_stats_disabled, false)
->Unit(benchmark::kMillisecond);
BENCHMARK_CAPTURE(BM_HistogramsJson, per_endpoint_stats_enabled, true)
->Unit(benchmark::kMillisecond);

0 comments on commit bac2ed0

Please sign in to comment.