From badd53b32b152cb4689f4e67ca9e075551f5db98 Mon Sep 17 00:00:00 2001 From: htuch Date: Tue, 9 Jun 2020 19:27:30 -0400 Subject: [PATCH] eds_speed_test: support v2/v3 variants of config. (#11505) This shows that the EDS onConfigUpdate() is 2-3x slower when working with v2 config and doing version conversion with original version recovery. Followup PRs will optimize. Relates to #11362 and #10875. Risk level: Low Testing: Ran benchmark with -c opt binary. Signed-off-by: Harvey Tuch Signed-off-by: yashwant121 --- test/common/upstream/eds_speed_test.cc | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/test/common/upstream/eds_speed_test.cc b/test/common/upstream/eds_speed_test.cc index e02f16a086f8..f79e037e8bf7 100644 --- a/test/common/upstream/eds_speed_test.cc +++ b/test/common/upstream/eds_speed_test.cc @@ -30,7 +30,7 @@ namespace Upstream { class EdsSpeedTest { public: - EdsSpeedTest() : api_(Api::createApiForTest(stats_)) {} + EdsSpeedTest(benchmark::State& state) : state_(state), api_(Api::createApiForTest(stats_)) {} void resetCluster(const std::string& yaml_config, Cluster::InitializePhase initialize_phase) { local_info_.node_.mutable_locality()->set_zone("us-east-1a"); @@ -54,7 +54,9 @@ class EdsSpeedTest { // Set up an EDS config with multiple priorities, localities, weights and make sure // they are loaded and reloaded as expected. - void priorityAndLocalityWeightedHelper(bool ignore_unknown_dynamic_fields, int num_hosts) { + void priorityAndLocalityWeightedHelper(bool v2_config, bool ignore_unknown_dynamic_fields, + int num_hosts) { + state_.PauseTiming(); envoy::config::endpoint::v3::ClusterLoadAssignment cluster_load_assignment; cluster_load_assignment.set_cluster_name("fare"); resetCluster(R"EOF( @@ -95,11 +97,20 @@ class EdsSpeedTest { initialize(); Protobuf::RepeatedPtrField resources; - resources.Add()->PackFrom(cluster_load_assignment); + auto* resource = resources.Add(); + resource->PackFrom(cluster_load_assignment); + if (v2_config) { + RELEASE_ASSERT(resource->type_url() == + "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", + ""); + resource->set_type_url("type.googleapis.com/envoy.api.v2.ClusterLoadAssignment"); + } + state_.ResumeTiming(); eds_callbacks_->onConfigUpdate(resources, ""); ASSERT(initialized_); } + benchmark::State& state_; bool initialized_{}; Stats::IsolatedStoreImpl stats_; Ssl::MockContextManager ssl_context_manager_; @@ -126,9 +137,9 @@ static void priorityAndLocalityWeighted(benchmark::State& state) { Envoy::Logger::Context logging_state(spdlog::level::warn, Envoy::Logger::Logger::DEFAULT_LOG_FORMAT, lock, false); for (auto _ : state) { - Envoy::Upstream::EdsSpeedTest speed_test; - speed_test.priorityAndLocalityWeightedHelper(state.range(0), state.range(1)); + Envoy::Upstream::EdsSpeedTest speed_test(state); + speed_test.priorityAndLocalityWeightedHelper(state.range(0), state.range(1), state.range(2)); } } -BENCHMARK(priorityAndLocalityWeighted)->Ranges({{false, true}, {2000, 100000}}); +BENCHMARK(priorityAndLocalityWeighted)->Ranges({{false, true}, {false, true}, {2000, 100000}});