Skip to content

Commit

Permalink
Create one mixerclient for each worker thread. (envoyproxy#326)
Browse files Browse the repository at this point in the history
* Create one mixerclient for each worker thread.

* Use std::thread
  • Loading branch information
qiwzhang authored May 18, 2017
1 parent ba5b0a4 commit 642361a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
21 changes: 17 additions & 4 deletions src/envoy/mixer/http_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include "src/envoy/mixer/http_control.h"
#include "src/envoy/mixer/utils.h"

#include <map>
#include <mutex>
#include <thread>

using ::google::protobuf::util::Status;
using StatusCode = ::google::protobuf::util::error::Code;
using ::istio::mixer_client::DoneFunc;
Expand Down Expand Up @@ -87,10 +91,11 @@ int HttpCode(int code) {

class Config : public Logger::Loggable<Logger::Id::http> {
private:
std::shared_ptr<HttpControl> http_control_;
Upstream::ClusterManager& cm_;
std::string forward_attributes_;
MixerConfig mixer_config_;
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 @@ -112,11 +117,19 @@ 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_);
}

std::shared_ptr<HttpControl>& http_control() { return http_control_; }
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_);
http_control_map_[id] = http_control;
return http_control;
}
const std::string& forward_attributes() const { return forward_attributes_; }
};

Expand Down
2 changes: 1 addition & 1 deletion src/envoy/mixer/integration_test/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func NewEnvoy(conf string, stress bool) (*Envoy, error) {
if stress {
cmd = exec.Command(bin_path, "-c", conf_path, "--concurrency", "10")
} else {
cmd = exec.Command(bin_path, "-c", conf_path, "-l", "debug")
cmd = exec.Command(bin_path, "-c", conf_path, "-l", "debug", "--concurrency", "1")
}
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
Expand Down
2 changes: 1 addition & 1 deletion src/envoy/mixer/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
################################################################################
#

MIXER_CLIENT = "d670be7d5a2427b543a5a128f6c1c2392eacbd37"
MIXER_CLIENT = "c50ee07b669d43df7ec0ea15a2da252fe6459759"

def mixer_client_repositories(bind=True):
native.git_repository(
Expand Down

0 comments on commit 642361a

Please sign in to comment.