Skip to content
Snippets Groups Projects

multiple instances for one service; deployment scripts generator

Merged Zhiqiang Xie requested to merge zxie into main
2 files
+ 61
28
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -80,9 +80,16 @@ void set_opentelemetry_enabled(bool is_enabled) {
opentelemetry_enabled = is_enabled;
}
ServerImpl::ServerImpl(ServiceConfig config, std::map<std::string,
AddressInfo> addresses, bool nocompute, std::map<int, float> triggers) : alive(true), clients(),
config(config), addresses(addresses), nocompute_(nocompute) {
ServerImpl::ServerImpl(ServiceConfig config,
std::map<std::string, AddressInfo> addresses,
bool nocompute, std::map<int, float> triggers,
int instance_id)
: alive(true),
clients(),
config(config),
addresses(addresses),
nocompute_(nocompute),
instance_id(instance_id) {
for (auto &p : triggers) {
// trigger probabilities are typically small (e.g. 0.1, 0.01) so
// we don't use, e.g. rand() % p to decide to trigger. instead we
@@ -105,7 +112,7 @@ ServerImpl::~ServerImpl() {
void ServerImpl::Run(int nhandlers) {
AddressInfo info = addresses[config.Name()];
std::string server_address(info.deploy_addr + ":" + info.port);
std::string server_address(info.deploy_addr + ":" + info.ports[instance_id]);
// Build the gRPC server
ServerBuilder builder;
@@ -118,7 +125,7 @@ void ServerImpl::Run(int nhandlers) {
std::cout << "Server listening on " << server_address << std::endl;
std::cout << "Server config " << config << std::endl;
std::string local_address = info.breadcrumb;
std::string local_address = info.breadcrumbs[instance_id];
std::cout << "Using " << local_address
<< " for local breadcrumb" << std::endl;
@@ -366,7 +373,14 @@ void Request::Proceed(bool ok) {
std::vector<Outcall*> child_calls;
for (auto& child : api_info.children) {
if (rand() % 100 < child.probability) {
child_calls.push_back(&child);
if (child.subcalls.size() > 0) {
// randomly choosing an instance of the target services
assert(child.subcalls.size() != 1);
child_calls.push_back(
&child.subcalls[rand() % child.subcalls.size()]);
} else {
child_calls.push_back(&child);
}
}
}
Loading