Skip to content

Commit

Permalink
Merge pull request grpc#3905 from vjpai/protosplit
Browse files Browse the repository at this point in the history
Overhaul benchmark control protos and tests themselves
  • Loading branch information
jtattermusch committed Nov 5, 2015
2 parents afa0b2f + fba20c9 commit d67b356
Show file tree
Hide file tree
Showing 42 changed files with 896 additions and 478 deletions.
140 changes: 116 additions & 24 deletions Makefile

Large diffs are not rendered by default.

23 changes: 22 additions & 1 deletion build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,11 @@ libs:
- test/cpp/qps/timer.h
- test/cpp/util/benchmark_config.h
src:
- test/proto/qpstest.proto
- test/proto/messages.proto
- test/proto/benchmarks/control.proto
- test/proto/benchmarks/payloads.proto
- test/proto/benchmarks/services.proto
- test/proto/benchmarks/stats.proto
- test/cpp/qps/perf_db.proto
- test/cpp/qps/client_async.cc
- test/cpp/qps/client_sync.cc
Expand Down Expand Up @@ -2038,6 +2042,23 @@ targets:
- grpc
- gpr_test_util
- gpr
- name: secure_sync_unary_ping_pong_test
build: test
language: c++
src:
- test/cpp/qps/secure_sync_unary_ping_pong_test.cc
deps:
- qps
- grpc++_test_util
- grpc_test_util
- grpc++
- grpc
- gpr_test_util
- gpr
platforms:
- mac
- linux
- posix
- name: server_crash_test
build: test
language: c++
Expand Down
2 changes: 1 addition & 1 deletion include/grpc/support/histogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void gpr_histogram_add(gpr_histogram *h, double x);
/* The following merges the second histogram into the first. It only works
if they have the same buckets and resolution. Returns 0 on failure, 1
on success */
int gpr_histogram_merge(gpr_histogram *dst, gpr_histogram *src);
int gpr_histogram_merge(gpr_histogram *dst, const gpr_histogram *src);

double gpr_histogram_percentile(gpr_histogram *histogram, double percentile);
double gpr_histogram_mean(gpr_histogram *histogram);
Expand Down
2 changes: 1 addition & 1 deletion src/core/support/histogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void gpr_histogram_add(gpr_histogram *h, double x) {
h->buckets[bucket_for(h, x)]++;
}

int gpr_histogram_merge(gpr_histogram *dst, gpr_histogram *src) {
int gpr_histogram_merge(gpr_histogram *dst, const gpr_histogram *src) {
if ((dst->num_buckets != src->num_buckets) ||
(dst->multiplier != src->multiplier)) {
/* Fail because these histograms don't match */
Expand Down
65 changes: 34 additions & 31 deletions test/core/network_benchmarks/low_level_ping_pong.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ typedef struct thread_args {
/* Basic call to read() */
static int read_bytes(int fd, char *buf, size_t read_size, int spin) {
size_t bytes_read = 0;
int err;
ssize_t err;
do {
err = read(fd, buf + bytes_read, read_size - bytes_read);
if (err < 0) {
Expand All @@ -96,7 +96,7 @@ static int read_bytes(int fd, char *buf, size_t read_size, int spin) {
return -1;
}
} else {
bytes_read += err;
bytes_read += (size_t)err;
}
} while (bytes_read < read_size);
return 0;
Expand All @@ -115,6 +115,7 @@ static int poll_read_bytes(int fd, char *buf, size_t read_size, int spin) {
struct pollfd pfd;
size_t bytes_read = 0;
int err;
ssize_t err2;

pfd.fd = fd;
pfd.events = POLLIN;
Expand All @@ -132,13 +133,13 @@ static int poll_read_bytes(int fd, char *buf, size_t read_size, int spin) {
GPR_ASSERT(err == 1);
GPR_ASSERT(pfd.revents == POLLIN);
do {
err = read(fd, buf + bytes_read, read_size - bytes_read);
} while (err < 0 && errno == EINTR);
if (err < 0 && errno != EAGAIN) {
err2 = read(fd, buf + bytes_read, read_size - bytes_read);
} while (err2 < 0 && errno == EINTR);
if (err2 < 0 && errno != EAGAIN) {
gpr_log(GPR_ERROR, "Read failed: %s", strerror(errno));
return -1;
}
bytes_read += err;
bytes_read += (size_t) err2;
} while (bytes_read < read_size);
return 0;
}
Expand All @@ -157,6 +158,7 @@ static int epoll_read_bytes(struct thread_args *args, char *buf, int spin) {
struct epoll_event ev;
size_t bytes_read = 0;
int err;
ssize_t err2;
size_t read_size = args->msg_size;

do {
Expand All @@ -172,10 +174,11 @@ static int epoll_read_bytes(struct thread_args *args, char *buf, int spin) {
GPR_ASSERT(ev.data.fd == args->fds.read_fd);
do {
do {
err = read(args->fds.read_fd, buf + bytes_read, read_size - bytes_read);
} while (err < 0 && errno == EINTR);
err2 = read(args->fds.read_fd, buf + bytes_read,
read_size - bytes_read);
} while (err2 < 0 && errno == EINTR);
if (errno == EAGAIN) break;
bytes_read += err;
bytes_read += (size_t) err2;
/* TODO(klempner): This should really be doing an extra call after we are
done to ensure we see an EAGAIN */
} while (bytes_read < read_size);
Expand All @@ -199,7 +202,7 @@ static int epoll_read_bytes_spin(struct thread_args *args, char *buf) {
*/
static int blocking_write_bytes(struct thread_args *args, char *buf) {
size_t bytes_written = 0;
int err;
ssize_t err;
size_t write_size = args->msg_size;
do {
err = write(args->fds.write_fd, buf + bytes_written,
Expand All @@ -212,7 +215,7 @@ static int blocking_write_bytes(struct thread_args *args, char *buf) {
return -1;
}
} else {
bytes_written += err;
bytes_written += (size_t)err;
}
} while (bytes_written < write_size);
return 0;
Expand Down Expand Up @@ -297,7 +300,7 @@ static void print_histogram(gpr_histogram *histogram) {

static double now(void) {
gpr_timespec tv = gpr_now(GPR_CLOCK_REALTIME);
return 1e9 * tv.tv_sec + tv.tv_nsec;
return 1e9 * (double)tv.tv_sec + (double)tv.tv_nsec;
}

static void client_thread(thread_args *args) {
Expand Down Expand Up @@ -373,7 +376,7 @@ static int create_listening_socket(struct sockaddr *port, socklen_t len) {
return -1;
}

static int connect_client(struct sockaddr *addr, int len) {
static int connect_client(struct sockaddr *addr, socklen_t len) {
int fd = socket(addr->sa_family, SOCK_STREAM, 0);
int err;
if (fd < 0) {
Expand Down Expand Up @@ -586,27 +589,27 @@ static int run_benchmark(char *socket_type, thread_args *client_args,
return 0;
}

static int run_all_benchmarks(int msg_size) {
static int run_all_benchmarks(size_t msg_size) {
int error = 0;
size_t i;
for (i = 0; i < GPR_ARRAY_SIZE(test_strategies); ++i) {
test_strategy *test_strategy = &test_strategies[i];
test_strategy *strategy = &test_strategies[i];
size_t j;
for (j = 0; j < GPR_ARRAY_SIZE(socket_types); ++j) {
thread_args *client_args = malloc(sizeof(thread_args));
thread_args *server_args = malloc(sizeof(thread_args));
char *socket_type = socket_types[j];

client_args->read_bytes = test_strategy->read_strategy;
client_args->read_bytes = strategy->read_strategy;
client_args->write_bytes = blocking_write_bytes;
client_args->setup = test_strategy->setup;
client_args->setup = strategy->setup;
client_args->msg_size = msg_size;
client_args->strategy_name = test_strategy->name;
server_args->read_bytes = test_strategy->read_strategy;
client_args->strategy_name = strategy->name;
server_args->read_bytes = strategy->read_strategy;
server_args->write_bytes = blocking_write_bytes;
server_args->setup = test_strategy->setup;
server_args->setup = strategy->setup;
server_args->msg_size = msg_size;
server_args->strategy_name = test_strategy->name;
server_args->strategy_name = strategy->name;
error = run_benchmark(socket_type, client_args, server_args);
if (error < 0) {
return error;
Expand All @@ -623,7 +626,7 @@ int main(int argc, char **argv) {
char *read_strategy = NULL;
char *socket_type = NULL;
size_t i;
const test_strategy *test_strategy = NULL;
const test_strategy *strategy = NULL;
int error = 0;

gpr_cmdline *cmdline =
Expand All @@ -643,7 +646,7 @@ int main(int argc, char **argv) {

if (read_strategy == NULL) {
gpr_log(GPR_INFO, "No strategy specified, running all benchmarks");
return run_all_benchmarks(msg_size);
return run_all_benchmarks((size_t)msg_size);
}

if (socket_type == NULL) {
Expand All @@ -657,23 +660,23 @@ int main(int argc, char **argv) {

for (i = 0; i < GPR_ARRAY_SIZE(test_strategies); ++i) {
if (strcmp(test_strategies[i].name, read_strategy) == 0) {
test_strategy = &test_strategies[i];
strategy = &test_strategies[i];
}
}
if (test_strategy == NULL) {
if (strategy == NULL) {
fprintf(stderr, "Invalid read strategy %s\n", read_strategy);
return -1;
}

client_args->read_bytes = test_strategy->read_strategy;
client_args->read_bytes = strategy->read_strategy;
client_args->write_bytes = blocking_write_bytes;
client_args->setup = test_strategy->setup;
client_args->msg_size = msg_size;
client_args->setup = strategy->setup;
client_args->msg_size = (size_t)msg_size;
client_args->strategy_name = read_strategy;
server_args->read_bytes = test_strategy->read_strategy;
server_args->read_bytes = strategy->read_strategy;
server_args->write_bytes = blocking_write_bytes;
server_args->setup = test_strategy->setup;
server_args->msg_size = msg_size;
server_args->setup = strategy->setup;
server_args->msg_size = (size_t)msg_size;
server_args->strategy_name = read_strategy;

error = run_benchmark(socket_type, client_args, server_args);
Expand Down
9 changes: 2 additions & 7 deletions test/cpp/qps/async_streaming_ping_pong_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@

#include <grpc/support/log.h>

#include <signal.h>

#include "test/cpp/qps/driver.h"
#include "test/cpp/qps/report.h"
#include "test/cpp/util/benchmark_config.h"
Expand All @@ -52,17 +50,15 @@ static void RunAsyncStreamingPingPong() {

ClientConfig client_config;
client_config.set_client_type(ASYNC_CLIENT);
client_config.set_enable_ssl(false);
client_config.set_outstanding_rpcs_per_channel(1);
client_config.set_client_channels(1);
client_config.set_payload_size(1);
client_config.set_async_client_threads(1);
client_config.set_rpc_type(STREAMING);
client_config.mutable_load_params()->mutable_closed_loop();

ServerConfig server_config;
server_config.set_server_type(ASYNC_SERVER);
server_config.set_enable_ssl(false);
server_config.set_threads(1);
server_config.set_async_server_threads(1);

const auto result =
RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2);
Expand All @@ -77,7 +73,6 @@ static void RunAsyncStreamingPingPong() {
int main(int argc, char** argv) {
grpc::testing::InitBenchmark(&argc, &argv, true);

signal(SIGPIPE, SIG_IGN);
grpc::testing::RunAsyncStreamingPingPong();
return 0;
}
9 changes: 2 additions & 7 deletions test/cpp/qps/async_unary_ping_pong_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@

#include <grpc/support/log.h>

#include <signal.h>

#include "test/cpp/qps/driver.h"
#include "test/cpp/qps/report.h"
#include "test/cpp/util/benchmark_config.h"
Expand All @@ -52,17 +50,15 @@ static void RunAsyncUnaryPingPong() {

ClientConfig client_config;
client_config.set_client_type(ASYNC_CLIENT);
client_config.set_enable_ssl(false);
client_config.set_outstanding_rpcs_per_channel(1);
client_config.set_client_channels(1);
client_config.set_payload_size(1);
client_config.set_async_client_threads(1);
client_config.set_rpc_type(UNARY);
client_config.mutable_load_params()->mutable_closed_loop();

ServerConfig server_config;
server_config.set_server_type(ASYNC_SERVER);
server_config.set_enable_ssl(false);
server_config.set_threads(1);
server_config.set_async_server_threads(1);

const auto result =
RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2);
Expand All @@ -75,7 +71,6 @@ static void RunAsyncUnaryPingPong() {

int main(int argc, char** argv) {
grpc::testing::InitBenchmark(&argc, &argv, true);
signal(SIGPIPE, SIG_IGN);

grpc::testing::RunAsyncUnaryPingPong();
return 0;
Expand Down
Loading

0 comments on commit d67b356

Please sign in to comment.