Skip to content

Commit

Permalink
Merge github.com:grpc/grpc into cereal-is-bad-for-your-health
Browse files Browse the repository at this point in the history
  • Loading branch information
ctiller committed Jun 8, 2015
2 parents 250e96d + b32c082 commit 52d646e
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 909 deletions.
90 changes: 2 additions & 88 deletions Makefile

Large diffs are not rendered by default.

40 changes: 1 addition & 39 deletions build.json
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@
"language": "c++",
"headers": [
"test/cpp/qps/driver.h",
"test/cpp/qps/interarrival.h",
"test/cpp/qps/qps_worker.h",
"test/cpp/qps/report.h",
"test/cpp/qps/timer.h"
Expand Down Expand Up @@ -2074,27 +2073,9 @@
"grpc++_benchmark_config"
]
},
{
"name": "qps_interarrival_test",
"build": "test",
"run": false,
"language": "c++",
"src": [
"test/cpp/qps/qps_interarrival_test.cc"
],
"deps": [
"qps",
"grpc++_test_util",
"grpc_test_util",
"grpc++",
"grpc",
"gpr_test_util",
"gpr"
]
},
{
"name": "qps_test",
"build": "test",
"build": "benchmark",
"language": "c++",
"src": [
"test/cpp/qps/qps_test.cc"
Expand All @@ -2111,25 +2092,6 @@
"grpc++_test_config"
]
},
{
"name": "qps_test_openloop",
"build": "test",
"language": "c++",
"src": [
"test/cpp/qps/qps_test_openloop.cc"
],
"deps": [
"qps",
"grpc++_test_util",
"grpc++_benchmark_config",
"grpc_test_util",
"grpc++",
"grpc",
"gpr_test_util",
"gpr",
"grpc++_test_config"
]
},
{
"name": "qps_worker",
"build": "benchmark",
Expand Down
24 changes: 10 additions & 14 deletions include/grpc++/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#define GRPC_CXX0X_NO_OVERRIDE 1
#define GRPC_CXX0X_NO_CHRONO 1
#define GRPC_CXX0X_NO_THREAD 1
#endif
#endif
#endif // Visual Studio

#ifndef __clang__
Expand Down Expand Up @@ -99,28 +99,24 @@
::google::protobuf::io::ZeroCopyOutputStream
#define GRPC_CUSTOM_ZEROCOPYINPUTSTREAM \
::google::protobuf::io::ZeroCopyInputStream
#define GRPC_CUSTOM_CODEDINPUTSTREAM ::google::protobuf::io::CodedInputStream
#define GRPC_CUSTOM_CODEDINPUTSTREAM \
::google::protobuf::io::CodedInputStream
#endif


#ifdef GRPC_CXX0X_NO_NULLPTR
#include <memory>
const class {
public:
template <class T>
operator T *() const {
return static_cast<T *>(0);
}
template <class T>
operator std::unique_ptr<T>() const {
public:
template <class T> operator T*() const {return static_cast<T *>(0);}
template <class T> operator std::unique_ptr<T>() const {
return std::unique_ptr<T>(static_cast<T *>(0));
}
template <class T>
operator std::shared_ptr<T>() const {
template <class T> operator std::shared_ptr<T>() const {
return std::shared_ptr<T>(static_cast<T *>(0));
}
operator bool() const { return false; }

private:
operator bool() const {return false;}
private:
void operator&() const = delete;
} nullptr = {};
#endif
Expand Down
16 changes: 6 additions & 10 deletions include/grpc++/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ namespace grpc {
template <typename T>
class TimePoint {
public:
TimePoint(const T& time) { you_need_a_specialization_of_TimePoint(); }
TimePoint(const T& time) {
you_need_a_specialization_of_TimePoint();
}
gpr_timespec raw_time() {
gpr_timespec t;
return t;
}

private:
void you_need_a_specialization_of_TimePoint();
};

template <>
template<>
class TimePoint<gpr_timespec> {
public:
TimePoint(const gpr_timespec& time) : time_(time) {}
TimePoint(const gpr_timespec& time) : time_(time) { }
gpr_timespec raw_time() { return time_; }

private:
gpr_timespec time_;
};
Expand All @@ -85,20 +85,16 @@ namespace grpc {
// from and to should be absolute time.
void Timepoint2Timespec(const std::chrono::system_clock::time_point& from,
gpr_timespec* to);
void TimepointHR2Timespec(
const std::chrono::high_resolution_clock::time_point& from,
gpr_timespec* to);

std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t);

template <>
class TimePoint<std::chrono::system_clock::time_point> {
public:
TimePoint(const std::chrono::system_clock::time_point& time) {
Timepoint2Timespec(time, &time_);
Timepoint2Timespec(time, &time_);
}
gpr_timespec raw_time() const { return time_; }

private:
gpr_timespec time_;
};
Expand Down
15 changes: 0 additions & 15 deletions src/cpp/util/time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ using std::chrono::duration_cast;
using std::chrono::nanoseconds;
using std::chrono::seconds;
using std::chrono::system_clock;
using std::chrono::high_resolution_clock;

namespace grpc {

Expand All @@ -60,20 +59,6 @@ void Timepoint2Timespec(const system_clock::time_point& from,
to->tv_nsec = nsecs.count();
}

void TimepointHR2Timespec(const high_resolution_clock::time_point& from,
gpr_timespec* to) {
high_resolution_clock::duration deadline = from.time_since_epoch();
seconds secs = duration_cast<seconds>(deadline);
if (from == high_resolution_clock::time_point::max() ||
secs.count() >= gpr_inf_future.tv_sec || secs.count() < 0) {
*to = gpr_inf_future;
return;
}
nanoseconds nsecs = duration_cast<nanoseconds>(deadline - secs);
to->tv_sec = secs.count();
to->tv_nsec = nsecs.count();
}

system_clock::time_point Timespec2Timepoint(gpr_timespec t) {
if (gpr_time_cmp(t, gpr_inf_future) == 0) {
return system_clock::time_point::max();
Expand Down
82 changes: 1 addition & 81 deletions test/cpp/qps/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,18 @@
#define TEST_QPS_CLIENT_H

#include "test/cpp/qps/histogram.h"
#include "test/cpp/qps/interarrival.h"
#include "test/cpp/qps/timer.h"
#include "test/cpp/qps/qpstest.grpc.pb.h"

#include <condition_variable>
#include <mutex>

namespace grpc {

#if defined(__APPLE__)
// Specialize Timepoint for high res clock as we need that
template <>
class TimePoint<std::chrono::high_resolution_clock::time_point> {
public:
TimePoint(const std::chrono::high_resolution_clock::time_point& time) {
TimepointHR2Timespec(time, &time_);
}
gpr_timespec raw_time() const { return time_; }

private:
gpr_timespec time_;
};
#endif

namespace testing {

typedef std::chrono::high_resolution_clock grpc_time_source;
typedef std::chrono::time_point<grpc_time_source> grpc_time;

class Client {
public:
explicit Client(const ClientConfig& config)
: timer_(new Timer), interarrival_timer_() {
explicit Client(const ClientConfig& config) : timer_(new Timer) {
for (int i = 0; i < config.client_channels(); i++) {
channels_.push_back(ClientChannelInfo(
config.server_targets(i % config.server_targets_size()), config));
Expand Down Expand Up @@ -102,7 +81,6 @@ class Client {

protected:
SimpleRequest request_;
bool closed_loop_;

class ClientChannelInfo {
public:
Expand All @@ -128,61 +106,6 @@ class Client {

virtual bool ThreadFunc(Histogram* histogram, size_t thread_idx) = 0;

void SetupLoadTest(const ClientConfig& config, size_t num_threads) {
// Set up the load distribution based on the number of threads
if (config.load_type() == CLOSED_LOOP) {
closed_loop_ = true;
} else {
closed_loop_ = false;

std::unique_ptr<RandomDist> random_dist;
const auto& load = config.load_params();
switch (config.load_type()) {
case POISSON:
random_dist.reset(
new ExpDist(load.poisson().offered_load() / num_threads));
break;
case UNIFORM:
random_dist.reset(
new UniformDist(load.uniform().interarrival_lo() * num_threads,
load.uniform().interarrival_hi() * num_threads));
break;
case DETERMINISTIC:
random_dist.reset(
new DetDist(num_threads / load.determ().offered_load()));
break;
case PARETO:
random_dist.reset(
new ParetoDist(load.pareto().interarrival_base() * num_threads,
load.pareto().alpha()));
break;
default:
GPR_ASSERT(false);
break;
}

interarrival_timer_.init(*random_dist, num_threads);
for (size_t i = 0; i < num_threads; i++) {
next_time_.push_back(
grpc_time_source::now() +
std::chrono::duration_cast<grpc_time_source::duration>(
interarrival_timer_(i)));
}
}
}

bool NextIssueTime(int thread_idx, grpc_time* time_delay) {
if (closed_loop_) {
return false;
} else {
*time_delay = next_time_[thread_idx];
next_time_[thread_idx] +=
std::chrono::duration_cast<grpc_time_source::duration>(
interarrival_timer_(thread_idx));
return true;
}
}

private:
class Thread {
public:
Expand Down Expand Up @@ -245,9 +168,6 @@ class Client {

std::vector<std::unique_ptr<Thread>> threads_;
std::unique_ptr<Timer> timer_;

InterarrivalTimer interarrival_timer_;
std::vector<grpc_time> next_time_;
};

std::unique_ptr<Client> CreateSynchronousUnaryClient(const ClientConfig& args);
Expand Down
Loading

0 comments on commit 52d646e

Please sign in to comment.