Skip to content

Commit 4c85878

Browse files
authored
create one client cache per worker thread (istio#364)
1 parent 90a4127 commit 4c85878

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/envoy/mixer/http_filter.cc

+13-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ class Config : public Logger::Loggable<Logger::Id::http> {
9595
Upstream::ClusterManager& cm_;
9696
std::string forward_attributes_;
9797
MixerConfig mixer_config_;
98-
std::shared_ptr<HttpControl> http_control_;
98+
std::mutex map_mutex_;
99+
std::map<std::thread::id, std::shared_ptr<HttpControl>> http_control_map_;
99100

100101
public:
101102
Config(const Json::Object& config, Server::Instance& server)
@@ -108,11 +109,20 @@ class Config : public Logger::Loggable<Logger::Id::http> {
108109
Base64::encode(serialized_str.c_str(), serialized_str.size());
109110
log().debug("Mixer forward attributes set: ", serialized_str);
110111
}
112+
}
111113

112-
http_control_ = std::make_shared<HttpControl>(mixer_config_, cm_);
114+
std::shared_ptr<HttpControl> http_control() {
115+
std::thread::id id = std::this_thread::get_id();
116+
std::lock_guard<std::mutex> lock(map_mutex_);
117+
auto it = http_control_map_.find(id);
118+
if (it != http_control_map_.end()) {
119+
return it->second;
120+
}
121+
auto http_control = std::make_shared<HttpControl>(mixer_config_, cm_);
122+
http_control_map_[id] = http_control;
123+
return http_control;
113124
}
114125

115-
std::shared_ptr<HttpControl> http_control() { return http_control_; }
116126
const std::string& forward_attributes() const { return forward_attributes_; }
117127
};
118128

0 commit comments

Comments
 (0)