make grpc_passthru_endpoint_stats refcounted

pull/14236/head
Jan Tattermusch 7 years ago
parent e6cf0aeff4
commit 12ba4b1e05
  1. 26
      test/core/util/passthru_endpoint.cc
  2. 5
      test/core/util/passthru_endpoint.h
  3. 13
      test/cpp/microbenchmarks/bm_fullstack_trickle.cc
  4. 13
      test/cpp/microbenchmarks/fullstack_fixtures.h
  5. 13
      test/cpp/performance/writes_per_rpc_test.cc

@ -48,8 +48,6 @@ struct passthru_endpoint {
gpr_mu mu;
int halves;
grpc_passthru_endpoint_stats* stats;
grpc_passthru_endpoint_stats
dummy_stats; // used if constructor stats == nullptr
bool shutdown;
half client;
half server;
@ -137,6 +135,7 @@ static void me_destroy(grpc_endpoint* ep) {
if (0 == --p->halves) {
gpr_mu_unlock(&p->mu);
gpr_mu_destroy(&p->mu);
grpc_passthru_endpoint_stats_destroy(p->stats);
grpc_slice_buffer_destroy_internal(&p->client.read_buffer);
grpc_slice_buffer_destroy_internal(&p->server.read_buffer);
grpc_resource_user_unref(p->client.resource_user);
@ -194,11 +193,30 @@ void grpc_passthru_endpoint_create(grpc_endpoint** client,
passthru_endpoint* m = (passthru_endpoint*)gpr_malloc(sizeof(*m));
m->halves = 2;
m->shutdown = 0;
m->stats = stats == nullptr ? &m->dummy_stats : stats;
memset(m->stats, 0, sizeof(*m->stats));
if (stats == nullptr) {
m->stats = grpc_passthru_endpoint_stats_create();
} else {
gpr_ref(&stats->refs);
m->stats = stats;
}
half_init(&m->client, m, resource_quota, "client");
half_init(&m->server, m, resource_quota, "server");
gpr_mu_init(&m->mu);
*client = &m->client.base;
*server = &m->server.base;
}
grpc_passthru_endpoint_stats* grpc_passthru_endpoint_stats_create() {
grpc_passthru_endpoint_stats* stats =
(grpc_passthru_endpoint_stats*)gpr_malloc(
sizeof(grpc_passthru_endpoint_stats));
memset(stats, 0, sizeof(*stats));
gpr_ref_init(&stats->refs, 1);
return stats;
}
void grpc_passthru_endpoint_stats_destroy(grpc_passthru_endpoint_stats* stats) {
if (gpr_unref(&stats->refs)) {
gpr_free(stats);
}
}

@ -24,6 +24,7 @@
#include "src/core/lib/iomgr/endpoint.h"
typedef struct {
gpr_refcount refs;
gpr_atm num_writes;
} grpc_passthru_endpoint_stats;
@ -32,4 +33,8 @@ void grpc_passthru_endpoint_create(grpc_endpoint** client,
grpc_resource_quota* resource_quota,
grpc_passthru_endpoint_stats* stats);
grpc_passthru_endpoint_stats* grpc_passthru_endpoint_stats_create();
void grpc_passthru_endpoint_stats_destroy(grpc_passthru_endpoint_stats* stats);
#endif

@ -101,9 +101,11 @@ class TrickledCHTTP2 : public EndpointPairFixture {
}
}
virtual ~TrickledCHTTP2() { grpc_passthru_endpoint_stats_destroy(stats_); }
void AddToLabel(std::ostream& out, benchmark::State& state) {
out << " writes/iter:"
<< ((double)stats_.num_writes / (double)state.iterations())
<< ((double)stats_->num_writes / (double)state.iterations())
<< " cli_transport_stalls/iter:"
<< ((double)
client_stats_.streams_stalled_due_to_transport_flow_control /
@ -193,7 +195,7 @@ class TrickledCHTTP2 : public EndpointPairFixture {
}
private:
grpc_passthru_endpoint_stats stats_;
grpc_passthru_endpoint_stats* stats_;
struct Stats {
int streams_stalled_due_to_stream_flow_control = 0;
int streams_stalled_due_to_transport_flow_control = 0;
@ -204,9 +206,14 @@ class TrickledCHTTP2 : public EndpointPairFixture {
gpr_timespec start_ = gpr_now(GPR_CLOCK_MONOTONIC);
grpc_endpoint_pair MakeEndpoints(size_t kilobits) {
stats_ = grpc_passthru_endpoint_stats_create(); // is there a better way to
// initialize stats_ and
// pass MakeEndpoints's
// return value to base
// constructor?
grpc_endpoint_pair p;
grpc_passthru_endpoint_create(&p.client, &p.server, Library::get().rq(),
&stats_);
stats_);
double bytes_per_second = 125.0 * kilobits;
p.client = grpc_trickle_endpoint_create(p.client, bytes_per_second);
p.server = grpc_trickle_endpoint_create(p.server, bytes_per_second);

@ -252,20 +252,27 @@ class InProcessCHTTP2 : public EndpointPairFixture {
FixtureConfiguration())
: EndpointPairFixture(service, MakeEndpoints(), fixture_configuration) {}
virtual ~InProcessCHTTP2() { grpc_passthru_endpoint_stats_destroy(stats_); }
void AddToLabel(std::ostream& out, benchmark::State& state) {
EndpointPairFixture::AddToLabel(out, state);
out << " writes/iter:"
<< static_cast<double>(gpr_atm_no_barrier_load(&stats_.num_writes)) /
<< static_cast<double>(gpr_atm_no_barrier_load(&stats_->num_writes)) /
static_cast<double>(state.iterations());
}
private:
grpc_passthru_endpoint_stats stats_;
grpc_passthru_endpoint_stats* stats_;
grpc_endpoint_pair MakeEndpoints() {
stats_ = grpc_passthru_endpoint_stats_create(); // is there a better way to
// initialize stats_ and
// pass MakeEndpoints's
// return value to base
// constructor?
grpc_endpoint_pair p;
grpc_passthru_endpoint_create(&p.client, &p.server, Library::get().rq(),
&stats_);
stats_);
return p;
}
};

@ -145,15 +145,22 @@ class InProcessCHTTP2 : public EndpointPairFixture {
InProcessCHTTP2(Service* service)
: EndpointPairFixture(service, MakeEndpoints()) {}
int writes_performed() const { return stats_.num_writes; }
virtual ~InProcessCHTTP2() { grpc_passthru_endpoint_stats_destroy(stats_); }
int writes_performed() const { return stats_->num_writes; }
private:
grpc_passthru_endpoint_stats stats_;
grpc_passthru_endpoint_stats* stats_;
grpc_endpoint_pair MakeEndpoints() {
stats_ = grpc_passthru_endpoint_stats_create(); // is there a better way to
// initialize stats_ and
// pass MakeEndpoints's
// return value to base
// constructor?
grpc_endpoint_pair p;
grpc_passthru_endpoint_create(&p.client, &p.server, initialize_stuff.rq(),
&stats_);
stats_);
return p;
}
};

Loading…
Cancel
Save