forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize EDS stream allocation (envoyproxy#22419)
Signed-off-by: Kateryna Nezdolii <[email protected]>
- Loading branch information
Kateryna Nezdolii
authored
Jan 18, 2023
1 parent
38ced99
commit 97a7f00
Showing
27 changed files
with
1,481 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
source/common/upstream/multiplexed_subscription_factory.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "source/common/upstream/multiplexed_subscription_factory.h" | ||
|
||
#include "source/common/common/hash.h" | ||
#include "source/common/config/utility.h" | ||
|
||
namespace Envoy { | ||
namespace Upstream { | ||
|
||
MultiplexedSubscriptionFactory::MultiplexedSubscriptionFactory( | ||
const LocalInfo::LocalInfo& local_info, Event::Dispatcher& dispatcher, | ||
Upstream::ClusterManager& cm, ProtobufMessage::ValidationVisitor& validation_visitor, | ||
Api::Api& api, const Server::Instance& server, | ||
Config::XdsResourcesDelegateOptRef xds_resources_delegate, | ||
Config::XdsConfigTrackerOptRef xds_config_tracker) | ||
: Config::SubscriptionFactoryImpl(local_info, dispatcher, cm, validation_visitor, api, server, | ||
xds_resources_delegate, xds_config_tracker){}; | ||
|
||
Config::GrpcMuxSharedPtr MultiplexedSubscriptionFactory::getOrCreateMux( | ||
const envoy::config::core::v3::ApiConfigSource& config_source, absl::string_view type_url, | ||
Stats::Scope& scope, Config::CustomConfigValidatorsPtr& custom_config_validators) { | ||
if (config_source.api_type() == envoy::config::core::v3::ApiConfigSource::GRPC || | ||
config_source.api_type() == envoy::config::core::v3::ApiConfigSource::DELTA_GRPC) { | ||
const uint64_t xds_server_hash = MessageUtil::hash(config_source.grpc_services(0)); | ||
const uint64_t xds_type_hash = HashUtil::xxHash64(type_url); | ||
const uint64_t mux_key = xds_server_hash ^ xds_type_hash; | ||
if (muxes_.find(mux_key) == muxes_.end()) { | ||
muxes_.emplace( | ||
std::make_pair(mux_key, Config::SubscriptionFactoryImpl::getOrCreateMux( | ||
config_source, type_url, scope, custom_config_validators))); | ||
} | ||
return muxes_.at(mux_key); | ||
} else { | ||
return Config::SubscriptionFactoryImpl::getOrCreateMux(config_source, type_url, scope, | ||
custom_config_validators); | ||
} | ||
} | ||
|
||
} // namespace Upstream | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#pragma once | ||
|
||
#include "envoy/config/core/v3/base.pb.h" | ||
#include "envoy/config/subscription.h" | ||
#include "envoy/stats/scope.h" | ||
|
||
#include "source/common/common/assert.h" | ||
#include "source/common/config/custom_config_validators_impl.h" | ||
#include "source/common/config/grpc_mux_impl.h" | ||
#include "source/common/config/grpc_subscription_impl.h" | ||
#include "source/common/config/subscription_factory_impl.h" | ||
#include "source/common/config/utility.h" | ||
#include "source/common/protobuf/protobuf.h" | ||
#include "source/server/transport_socket_config_impl.h" | ||
|
||
/** | ||
* MultiplexedSubscriptionFactory is used for instantiation of XDS subscriptions so as to minimize | ||
* the number of open grpc connections used by these subscriptions. This is done by sharing a grpc | ||
* multiplexer between subscriptions handled per subscription server and xds resource type. Please | ||
* see https://github.com/envoyproxy/envoy/issues/2943 for additional information and related | ||
* issues. | ||
* | ||
*/ | ||
|
||
namespace Envoy { | ||
namespace Upstream { | ||
|
||
class MultiplexedSubscriptionFactory : public Config::SubscriptionFactoryImpl { | ||
public: | ||
~MultiplexedSubscriptionFactory() override = default; | ||
|
||
MultiplexedSubscriptionFactory(const LocalInfo::LocalInfo& local_info, | ||
Event::Dispatcher& dispatcher, Upstream::ClusterManager& cm, | ||
ProtobufMessage::ValidationVisitor& validation_visitor, | ||
Api::Api& api, const Server::Instance& server, | ||
Config::XdsResourcesDelegateOptRef xds_resources_delegate, | ||
Config::XdsConfigTrackerOptRef xds_config_tracker); | ||
|
||
protected: | ||
// Config::SubscriptionFactoryImpl | ||
Config::GrpcMuxSharedPtr | ||
getOrCreateMux(const envoy::config::core::v3::ApiConfigSource& api_config_source, | ||
absl::string_view type_url, Stats::Scope& scope, | ||
Config::CustomConfigValidatorsPtr& custom_config_validators) override; | ||
|
||
private: | ||
absl::flat_hash_map<uint64_t, Config::GrpcMuxSharedPtr> muxes_; | ||
friend class MultiplexedSubscriptionFactoryPeer; | ||
}; | ||
} // namespace Upstream | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.