Add comments describing various random distributions

Also remove the parameterized constructor for InterarrivalTimer
and only keep the init function.
pull/1948/head
Vijay Pai 10 years ago
parent fcedc15082
commit 92b7f872fd
  1. 53
      test/cpp/qps/interarrival.h
  2. 19
      test/cpp/qps/qps_interarrival_test.cc

@ -60,18 +60,13 @@ class RandomDist {
inline RandomDist::~RandomDist() {}
class UniformDist GRPC_FINAL : public RandomDist {
public:
UniformDist(double lo, double hi) : lo_(lo), range_(hi - lo) {}
~UniformDist() GRPC_OVERRIDE {}
double operator()(double uni) const GRPC_OVERRIDE {
return uni * range_ + lo_;
}
private:
double lo_;
double range_;
};
// ExpDist implements an exponential distribution, which is the
// interarrival distribution for a Poisson process. The parameter
// lambda is the mean rate of arrivals. This is the
// most useful distribution since it is actually additive and
// memoryless. It is a good representation of activity coming in from
// independent identical stationary sources. For more information,
// see http://en.wikipedia.org/wiki/Exponential_distribution
class ExpDist GRPC_FINAL : public RandomDist {
public:
@ -86,6 +81,30 @@ class ExpDist GRPC_FINAL : public RandomDist {
double lambda_recip_;
};
// UniformDist implements a random distribution that has
// interarrival time uniformly spread between [lo,hi). The
// mean interarrival time is (lo+hi)/2. For more information,
// see http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29
class UniformDist GRPC_FINAL : public RandomDist {
public:
UniformDist(double lo, double hi) : lo_(lo), range_(hi - lo) {}
~UniformDist() GRPC_OVERRIDE {}
double operator()(double uni) const GRPC_OVERRIDE {
return uni * range_ + lo_;
}
private:
double lo_;
double range_;
};
// DetDist provides a random distribution with interarrival time
// of val. Note that this is not additive, so using this on multiple
// flows of control (threads within the same client or separate
// clients) will not preserve any deterministic interarrival gap across
// requests.
class DetDist GRPC_FINAL : public RandomDist {
public:
explicit DetDist(double val) : val_(val) {}
@ -96,6 +115,13 @@ class DetDist GRPC_FINAL : public RandomDist {
double val_;
};
// ParetoDist provides a random distribution with interarrival time
// spread according to a Pareto (heavy-tailed) distribution. In this
// model, many interarrival times are close to the base, but a sufficient
// number will be high (up to infinity) as to disturb the mean. It is a
// good representation of the response times of data center jobs. See
// http://en.wikipedia.org/wiki/Pareto_distribution
class ParetoDist GRPC_FINAL : public RandomDist {
public:
ParetoDist(double base, double alpha)
@ -120,9 +146,6 @@ typedef std::default_random_engine qps_random_engine;
class InterarrivalTimer {
public:
InterarrivalTimer() {}
InterarrivalTimer(const RandomDist& r, int threads, int entries = 1000000) {
init(r, threads, entries);
}
void init(const RandomDist& r, int threads, int entries = 1000000) {
qps_random_engine gen;
std::uniform_real_distribution<double> uniform(0.0, 1.0);

@ -39,14 +39,16 @@
#include <grpc/support/histogram.h>
#include <grpc++/config.h>
using grpc::testing::ExpDist;
using grpc::testing::RandomDist;
using grpc::testing::InterarrivalTimer;
void RunTest(InterarrivalTimer &&timer, std::string title) {
void RunTest(RandomDist&& r, int threads, std::string title) {
InterarrivalTimer timer;
timer.init(r, threads);
gpr_histogram *h(gpr_histogram_create(0.01, 60e9));
for (int i = 0; i < 10000000; i++) {
for (int j = 0; j < 5; j++) {
for (int j = 0; j < threads; j++) {
gpr_histogram_add(h, timer(j).count());
}
}
@ -66,12 +68,9 @@ using grpc::testing::UniformDist;
using grpc::testing::ParetoDist;
int main(int argc, char **argv) {
RunTest(InterarrivalTimer(ExpDist(10.0), 5), std::string("Exponential(10)"));
RunTest(InterarrivalTimer(DetDist(5.0), 5), std::string("Det(5)"));
RunTest(InterarrivalTimer(UniformDist(0.0, 10.0), 5),
std::string("Uniform(1,10)"));
RunTest(InterarrivalTimer(ParetoDist(1.0, 1.0), 5),
std::string("Pareto(1,1)"));
RunTest(ExpDist(10.0), 5, std::string("Exponential(10)"));
RunTest(DetDist(5.0), 5, std::string("Det(5)"));
RunTest(UniformDist(0.0, 10.0), 5, std::string("Uniform(1,10)"));
RunTest(ParetoDist(1.0, 1.0), 5, std::string("Pareto(1,1)"));
return 0;
}

Loading…
Cancel
Save