Skip to content
Snippets Groups Projects
Commit e1330ff4 authored by Sree Kuchibhotla's avatar Sree Kuchibhotla
Browse files

Add multiple channels to each server

parent e7790845
No related branches found
No related tags found
No related merge requests found
...@@ -38,10 +38,10 @@ ...@@ -38,10 +38,10 @@
#include <vector> #include <vector>
#include <gflags/gflags.h> #include <gflags/gflags.h>
#include <grpc/support/time.h>
#include <grpc++/create_channel.h> #include <grpc++/create_channel.h>
#include <grpc++/grpc++.h> #include <grpc++/grpc++.h>
#include <grpc++/impl/thd.h> #include <grpc++/impl/thd.h>
#include <grpc/support/time.h>
#include "test/cpp/interop/interop_client.h" #include "test/cpp/interop/interop_client.h"
#include "test/cpp/interop/stress_interop_client.h" #include "test/cpp/interop/stress_interop_client.h"
...@@ -70,6 +70,8 @@ DEFINE_string(server_addresses, "localhost:8080", ...@@ -70,6 +70,8 @@ DEFINE_string(server_addresses, "localhost:8080",
" \"<name_1>:<port_1>,<name_2>:<port_1>...<name_N>:<port_N>\"\n" " \"<name_1>:<port_1>,<name_2>:<port_1>...<name_N>:<port_N>\"\n"
" Note: <name> can be servername or IP address."); " Note: <name> can be servername or IP address.");
DEFINE_int32(num_channels_per_server, 1, "Number of channels for each server");
DEFINE_int32(num_stubs_per_channel, 1, DEFINE_int32(num_stubs_per_channel, 1,
"Number of stubs per each channels to server. This number also " "Number of stubs per each channels to server. This number also "
"indicates the max number of parallel RPC calls on each channel " "indicates the max number of parallel RPC calls on each channel "
...@@ -216,30 +218,46 @@ int main(int argc, char** argv) { ...@@ -216,30 +218,46 @@ int main(int argc, char** argv) {
std::vector<grpc::thread> test_threads; std::vector<grpc::thread> test_threads;
// Create and start the test threads.
// Note that:
// - Each server can have multiple channels (as configured by
// FLAGS_num_channels_per_server).
//
// - Each channel can have multiple stubs (as configured by
// FLAGS_num_stubs_per_channel). This is to test calling multiple RPCs in
// parallel on the same channel.
int thread_idx = 0; int thread_idx = 0;
int server_idx = -1;
char buffer[256];
for (auto it = server_addresses.begin(); it != server_addresses.end(); it++) { for (auto it = server_addresses.begin(); it != server_addresses.end(); it++) {
// TODO(sreek): This will change once we add support for other tests ++server_idx;
// that won't work with InsecureChannelCredentials() // Create channel(s) for each server
std::shared_ptr<grpc::Channel> channel( for (int channel_idx = 0; channel_idx < FLAGS_num_channels_per_server;
grpc::CreateChannel(*it, grpc::InsecureChannelCredentials())); channel_idx++) {
// TODO (sreek). This won't work for tests that require Authentication
// Make multiple stubs (as defined by num_stubs_per_channel flag) to use the std::shared_ptr<grpc::Channel> channel(
// same channel. This is to test calling multiple RPC calls in parallel on grpc::CreateChannel(*it, grpc::InsecureChannelCredentials()));
// each channel.
for (int i = 0; i < FLAGS_num_stubs_per_channel; i++) { // Create stub(s) for each channel
StressTestInteropClient* client = new StressTestInteropClient( for (int stub_idx = 0; stub_idx < FLAGS_num_stubs_per_channel;
++thread_idx, *it, channel, test_selector, FLAGS_test_duration_secs, stub_idx++) {
FLAGS_sleep_duration_ms, FLAGS_metrics_collection_interval_secs); StressTestInteropClient* client = new StressTestInteropClient(
++thread_idx, *it, channel, test_selector, FLAGS_test_duration_secs,
bool is_already_created; FLAGS_sleep_duration_ms, FLAGS_metrics_collection_interval_secs);
grpc::string metricName =
"/stress_test/qps/thread/" + std::to_string(thread_idx); bool is_already_created;
test_threads.emplace_back( // Gauge name
grpc::thread(&StressTestInteropClient::MainLoop, client, std::snprintf(buffer, sizeof(buffer),
metrics_service.CreateGauge(metricName, &is_already_created))); "/stress_test/server_%d/channel_%d/stub_%d/qps",
server_idx, channel_idx, stub_idx);
// The Gauge should not have been already created
GPR_ASSERT(!is_already_created); test_threads.emplace_back(grpc::thread(
&StressTestInteropClient::MainLoop, client,
metrics_service.CreateGauge(buffer, &is_already_created)));
// The Gauge should not have been already created
GPR_ASSERT(!is_already_created);
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment