Skip to content

Commit

Permalink
create one client cache per worker thread (istio#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiwzhang authored Jun 12, 2017
1 parent 90a4127 commit 4c85878
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/envoy/mixer/http_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class Config : public Logger::Loggable<Logger::Id::http> {
Upstream::ClusterManager& cm_;
std::string forward_attributes_;
MixerConfig mixer_config_;
std::shared_ptr<HttpControl> http_control_;
std::mutex map_mutex_;
std::map<std::thread::id, std::shared_ptr<HttpControl>> http_control_map_;

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

http_control_ = std::make_shared<HttpControl>(mixer_config_, cm_);
std::shared_ptr<HttpControl> http_control() {
std::thread::id id = std::this_thread::get_id();
std::lock_guard<std::mutex> lock(map_mutex_);
auto it = http_control_map_.find(id);
if (it != http_control_map_.end()) {
return it->second;
}
auto http_control = std::make_shared<HttpControl>(mixer_config_, cm_);
http_control_map_[id] = http_control;
return http_control;
}

std::shared_ptr<HttpControl> http_control() { return http_control_; }
const std::string& forward_attributes() const { return forward_attributes_; }
};

Expand Down

0 comments on commit 4c85878

Please sign in to comment.