Optimize AsyncClientManager by moving hashing to control plane#29199
Optimize AsyncClientManager by moving hashing to control plane#29199ggreenway merged 9 commits intoenvoyproxy:mainfrom
Conversation
Signed-off-by: AlanDiaz <diazalan@google.com>
Signed-off-by: AlanDiaz <diazalan@google.com>
|
@ggreenway This is a follow up from what we talked about on 28272. This PR wraps the precomputed hash and config and sends that to the async client manager. I haven't changed the other filters yet as I want to get feedback on the initial implementation of this. If this looks good and passes, I'll make a follow up PR for the other filters. |
Signed-off-by: AlanDiaz <diazalan@google.com>
pradeepcrao
left a comment
There was a problem hiding this comment.
Thanks so much for working on this Alan!
| const envoy::config::core::v3::GrpcService& config, Stats::Scope& scope, | ||
| bool skip_cluster_check) { | ||
| RawAsyncClientSharedPtr client = raw_async_client_cache_->getCache(config); | ||
| const GrpcServiceHashKeyWrapper& key_wrapper = GrpcServiceHashKeyWrapper(config); |
There was a problem hiding this comment.
There is a reference to a temporary object here.
There was a problem hiding this comment.
Also, what do you think about replacing key_wrapper with config_with_hash_key?
There was a problem hiding this comment.
Done. Also changed GrpcServiceHashKeyWrapper to GrpcServiceConfigWithHashKey.
| private: | ||
| void evictEntriesAndResetEvictionTimer(); | ||
| struct CacheEntry { | ||
| CacheEntry(const envoy::config::core::v3::GrpcService& config, |
There was a problem hiding this comment.
Why not just have CacheEntry accept a GrpcServiceHashKeyWrapper instead of a GrpcService?
| MessageUtil> | ||
| lru_map_; | ||
| LruList lru_list_; | ||
| absl::flat_hash_map<GrpcServiceHashKeyWrapper, LruList::iterator> lru_map_wrapper_; |
There was a problem hiding this comment.
nit: maybe keep the old name (lru_map_)? The new name made more sense when you had 2 maps in your old implementation.
envoy/grpc/async_client_manager.h
Outdated
| Stats::Scope& scope, bool skip_cluster_check) PURE; | ||
|
|
||
| virtual RawAsyncClientSharedPtr | ||
| getOrCreateRawAsyncClientWithWrapper(const GrpcServiceHashKeyWrapper& grpc_service, |
There was a problem hiding this comment.
Once you've made the change to all filters, it'll be good to deprecate getOrCreateRawAsyncClient without the wrapper, and change the name of this method to getOrCreateRawAsyncClient. Maybe add a comment to that effect?
There was a problem hiding this comment.
I also just added a comment to the new getOrCreateRawAsyncClient that better describes it's use.
envoy/grpc/async_client_manager.h
Outdated
|
|
||
| friend bool operator==(const GrpcServiceHashKeyWrapper& lhs, | ||
| const GrpcServiceHashKeyWrapper& rhs) { | ||
| return Protobuf::util::MessageDifferencer::Equivalent(lhs.config_, rhs.config_); |
There was a problem hiding this comment.
There is scope for optimisation here. Before the call Protobuf::util::MessageDifferencer::Equivalent, short circuit and return false if pre_computed_hash_ values are different.
Signed-off-by: AlanDiaz <diazalan@google.com>
Signed-off-by: AlanDiaz <diazalan@google.com>
|
/assign @pradeepcrao |
|
/retest |
pradeepcrao
left a comment
There was a problem hiding this comment.
Looks great Alan!
Could you please add a unit test for GrpcServiceConfigWithHashKey? Also, I feel it might be easier (and better) to write a performance benchmark that compares getOrCreateRawAsyncClientWithHashKey with getOrCreateRawAsyncClient than try to load test this.
envoy/grpc/async_client_manager.h
Outdated
|
|
||
| class GrpcServiceConfigWithHashKey { | ||
| public: | ||
| GrpcServiceConfigWithHashKey(const envoy::config::core::v3::GrpcService& config) |
There was a problem hiding this comment.
nit: Please mark constructor as explicit.
|
@DiazAlan i think this may be waiting for further iteration /wait |
Signed-off-by: AlanDiaz <diazalan@google.com>
Signed-off-by: AlanDiaz <diazalan@google.com>
|
/retest |
Signed-off-by: AlanDiaz <diazalan@google.com>
|
Made a benchmark test to see the difference. Each test using getOrCreateRawAsyncClient 1000 times for each implementation. Here were the results. |
Signed-off-by: AlanDiaz <diazalan@google.com>
|
/retest |
1 similar comment
|
/retest |
Change API call on ext_proc to more efficient new implementation. Following the PR #29199, we are replacing the API call in ext_proc so it's not hashing the whole config proto on each request. Signed-off-by: AlanDiaz <diazalan@google.com>
Change API call on ext_proc to more efficient new implementation. Following the PR envoyproxy#29199, we are replacing the API call in ext_proc so it's not hashing the whole config proto on each request. Signed-off-by: AlanDiaz <diazalan@google.com>
…proxy#29199) This change removes the hashing of the config away from the data plane on every request to the control plane when the filter callback is created. This is accomplished by creating a wrapper object for the config which precomputes the hash and also serializes it to string ahead of time so that calls to the AsyncClientManager with that wrapper can avoid unnecessary overhead. Signed-off-by: AlanDiaz <diazalan@google.com>
…proxy#29199) This change removes the hashing of the config away from the data plane on every request to the control plane when the filter callback is created. This is accomplished by creating a wrapper object for the config which precomputes the hash and also serializes it to string ahead of time so that calls to the AsyncClientManager with that wrapper can avoid unnecessary overhead. Signed-off-by: AlanDiaz <diazalan@google.com>
Change API call on ext_proc to more efficient new implementation. Following the PR envoyproxy#29199, we are replacing the API call in ext_proc so it's not hashing the whole config proto on each request. Signed-off-by: AlanDiaz <diazalan@google.com>
Commit Message: Optimize AsyncClientManager by moving hashing to control plane
Additional Description: This change removes the hashing of the config away from the data plane on every request to the control plane when the filter callback is created. This is accomplished by creating a wrapper object for the config which precomputes the hash and also serializes it to string ahead of time so that calls to the AsyncClientManager with that wrapper can avoid unnecessary overhead.
Risk Level: Low
Testing: Changed some ext_authz tests to account for changes
Added a benchmark test that observed the following improvement
Benchmark Time CPU Iterations
testGetOrCreateAsyncClientWithConfig 27199 us 27182 us 1
testGetOrCreateAsyncClientWithHashConfig 15943 us 15943 us 1