mirror of https://github.com/grpc/grpc.git
commit
6e5cbc2095
56 changed files with 1822 additions and 348 deletions
@ -0,0 +1,43 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_CORE_EXT_TRANSPORT_CRONET_TRANSPORT_CRONET_TRANSPORT_H |
||||
#define GRPC_CORE_EXT_TRANSPORT_CRONET_TRANSPORT_CRONET_TRANSPORT_H |
||||
|
||||
#include "src/core/lib/transport/transport.h" |
||||
|
||||
grpc_transport *grpc_create_cronet_transport(void *engine, const char *target, |
||||
const grpc_channel_args *args, |
||||
void *reserved); |
||||
|
||||
#endif /* GRPC_CORE_EXT_TRANSPORT_CRONET_TRANSPORT_CRONET_TRANSPORT_H */ |
@ -0,0 +1,196 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include "test/core/util/passthru_endpoint.h" |
||||
|
||||
#include <inttypes.h> |
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/string_util.h> |
||||
#include <grpc/support/useful.h> |
||||
|
||||
#include "src/core/lib/iomgr/sockaddr.h" |
||||
|
||||
#include "src/core/lib/slice/slice_internal.h" |
||||
|
||||
typedef struct { |
||||
grpc_endpoint base; |
||||
double bytes_per_second; |
||||
grpc_endpoint *wrapped; |
||||
gpr_timespec last_write; |
||||
|
||||
gpr_mu mu; |
||||
grpc_slice_buffer write_buffer; |
||||
grpc_slice_buffer writing_buffer; |
||||
grpc_error *error; |
||||
bool writing; |
||||
} trickle_endpoint; |
||||
|
||||
static void te_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, |
||||
grpc_slice_buffer *slices, grpc_closure *cb) { |
||||
trickle_endpoint *te = (trickle_endpoint *)ep; |
||||
grpc_endpoint_read(exec_ctx, te->wrapped, slices, cb); |
||||
} |
||||
|
||||
static void te_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, |
||||
grpc_slice_buffer *slices, grpc_closure *cb) { |
||||
trickle_endpoint *te = (trickle_endpoint *)ep; |
||||
for (size_t i = 0; i < slices->count; i++) { |
||||
grpc_slice_ref_internal(slices->slices[i]); |
||||
} |
||||
gpr_mu_lock(&te->mu); |
||||
if (te->write_buffer.length == 0) { |
||||
te->last_write = gpr_now(GPR_CLOCK_MONOTONIC); |
||||
} |
||||
grpc_slice_buffer_addn(&te->write_buffer, slices->slices, slices->count); |
||||
grpc_closure_sched(exec_ctx, cb, GRPC_ERROR_REF(te->error)); |
||||
gpr_mu_unlock(&te->mu); |
||||
} |
||||
|
||||
static grpc_workqueue *te_get_workqueue(grpc_endpoint *ep) { |
||||
trickle_endpoint *te = (trickle_endpoint *)ep; |
||||
return grpc_endpoint_get_workqueue(te->wrapped); |
||||
} |
||||
|
||||
static void te_add_to_pollset(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, |
||||
grpc_pollset *pollset) { |
||||
trickle_endpoint *te = (trickle_endpoint *)ep; |
||||
grpc_endpoint_add_to_pollset(exec_ctx, te->wrapped, pollset); |
||||
} |
||||
|
||||
static void te_add_to_pollset_set(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, |
||||
grpc_pollset_set *pollset_set) { |
||||
trickle_endpoint *te = (trickle_endpoint *)ep; |
||||
grpc_endpoint_add_to_pollset_set(exec_ctx, te->wrapped, pollset_set); |
||||
} |
||||
|
||||
static void te_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, |
||||
grpc_error *why) { |
||||
trickle_endpoint *te = (trickle_endpoint *)ep; |
||||
gpr_mu_lock(&te->mu); |
||||
if (te->error == GRPC_ERROR_NONE) { |
||||
te->error = GRPC_ERROR_REF(why); |
||||
} |
||||
gpr_mu_unlock(&te->mu); |
||||
grpc_endpoint_shutdown(exec_ctx, te->wrapped, why); |
||||
} |
||||
|
||||
static void te_destroy(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) { |
||||
trickle_endpoint *te = (trickle_endpoint *)ep; |
||||
grpc_endpoint_destroy(exec_ctx, te->wrapped); |
||||
gpr_mu_destroy(&te->mu); |
||||
grpc_slice_buffer_destroy_internal(exec_ctx, &te->write_buffer); |
||||
grpc_slice_buffer_destroy_internal(exec_ctx, &te->writing_buffer); |
||||
GRPC_ERROR_UNREF(te->error); |
||||
gpr_free(te); |
||||
} |
||||
|
||||
static grpc_resource_user *te_get_resource_user(grpc_endpoint *ep) { |
||||
trickle_endpoint *te = (trickle_endpoint *)ep; |
||||
return grpc_endpoint_get_resource_user(te->wrapped); |
||||
} |
||||
|
||||
static char *te_get_peer(grpc_endpoint *ep) { |
||||
trickle_endpoint *te = (trickle_endpoint *)ep; |
||||
return grpc_endpoint_get_peer(te->wrapped); |
||||
} |
||||
|
||||
static int te_get_fd(grpc_endpoint *ep) { |
||||
trickle_endpoint *te = (trickle_endpoint *)ep; |
||||
return grpc_endpoint_get_fd(te->wrapped); |
||||
} |
||||
|
||||
static void te_finish_write(grpc_exec_ctx *exec_ctx, void *arg, |
||||
grpc_error *error) { |
||||
trickle_endpoint *te = arg; |
||||
gpr_mu_lock(&te->mu); |
||||
te->writing = false; |
||||
grpc_slice_buffer_reset_and_unref(&te->writing_buffer); |
||||
gpr_mu_unlock(&te->mu); |
||||
} |
||||
|
||||
static const grpc_endpoint_vtable vtable = {te_read, |
||||
te_write, |
||||
te_get_workqueue, |
||||
te_add_to_pollset, |
||||
te_add_to_pollset_set, |
||||
te_shutdown, |
||||
te_destroy, |
||||
te_get_resource_user, |
||||
te_get_peer, |
||||
te_get_fd}; |
||||
|
||||
grpc_endpoint *grpc_trickle_endpoint_create(grpc_endpoint *wrap, |
||||
double bytes_per_second) { |
||||
trickle_endpoint *te = gpr_malloc(sizeof(*te)); |
||||
te->base.vtable = &vtable; |
||||
te->wrapped = wrap; |
||||
te->bytes_per_second = bytes_per_second; |
||||
gpr_mu_init(&te->mu); |
||||
grpc_slice_buffer_init(&te->write_buffer); |
||||
grpc_slice_buffer_init(&te->writing_buffer); |
||||
te->error = GRPC_ERROR_NONE; |
||||
te->writing = false; |
||||
return &te->base; |
||||
} |
||||
|
||||
static double ts2dbl(gpr_timespec s) { |
||||
return (double)s.tv_sec + 1e-9 * (double)s.tv_nsec; |
||||
} |
||||
|
||||
size_t grpc_trickle_endpoint_trickle(grpc_exec_ctx *exec_ctx, |
||||
grpc_endpoint *ep) { |
||||
trickle_endpoint *te = (trickle_endpoint *)ep; |
||||
gpr_mu_lock(&te->mu); |
||||
if (!te->writing && te->write_buffer.length > 0) { |
||||
gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); |
||||
double elapsed = ts2dbl(gpr_time_sub(now, te->last_write)); |
||||
size_t bytes = (size_t)(te->bytes_per_second * elapsed); |
||||
// gpr_log(GPR_DEBUG, "%lf elapsed --> %" PRIdPTR " bytes", elapsed, bytes);
|
||||
if (bytes > 0) { |
||||
grpc_slice_buffer_move_first(&te->write_buffer, |
||||
GPR_MIN(bytes, te->write_buffer.length), |
||||
&te->writing_buffer); |
||||
te->writing = true; |
||||
te->last_write = now; |
||||
grpc_endpoint_write( |
||||
exec_ctx, te->wrapped, &te->writing_buffer, |
||||
grpc_closure_create(te_finish_write, te, grpc_schedule_on_exec_ctx)); |
||||
} |
||||
} |
||||
size_t backlog = te->write_buffer.length; |
||||
gpr_mu_unlock(&te->mu); |
||||
return backlog; |
||||
} |
@ -0,0 +1,46 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef TRICKLE_ENDPOINT_H |
||||
#define TRICKLE_ENDPOINT_H |
||||
|
||||
#include "src/core/lib/iomgr/endpoint.h" |
||||
|
||||
grpc_endpoint *grpc_trickle_endpoint_create(grpc_endpoint *wrap, |
||||
double bytes_per_second); |
||||
|
||||
/* Allow up to \a bytes through the endpoint. Returns the new backlog. */ |
||||
size_t grpc_trickle_endpoint_trickle(grpc_exec_ctx *exec_ctx, |
||||
grpc_endpoint *endpoint); |
||||
|
||||
#endif |
@ -0,0 +1,356 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
/* Test various closure related operations */ |
||||
|
||||
#include <grpc/grpc.h> |
||||
|
||||
extern "C" { |
||||
#include "src/core/lib/iomgr/closure.h" |
||||
#include "src/core/lib/iomgr/combiner.h" |
||||
#include "src/core/lib/iomgr/exec_ctx.h" |
||||
} |
||||
|
||||
#include "third_party/benchmark/include/benchmark/benchmark.h" |
||||
|
||||
static class InitializeStuff { |
||||
public: |
||||
InitializeStuff() { grpc_init(); } |
||||
~InitializeStuff() { grpc_shutdown(); } |
||||
} initialize_stuff; |
||||
|
||||
static void BM_NoOpExecCtx(benchmark::State& state) { |
||||
while (state.KeepRunning()) { |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
} |
||||
BENCHMARK(BM_NoOpExecCtx); |
||||
|
||||
static void BM_WellFlushed(benchmark::State& state) { |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
while (state.KeepRunning()) { |
||||
grpc_exec_ctx_flush(&exec_ctx); |
||||
} |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
BENCHMARK(BM_WellFlushed); |
||||
|
||||
static void DoNothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} |
||||
|
||||
static void BM_ClosureInitAgainstExecCtx(benchmark::State& state) { |
||||
grpc_closure c; |
||||
while (state.KeepRunning()) { |
||||
benchmark::DoNotOptimize( |
||||
grpc_closure_init(&c, DoNothing, NULL, grpc_schedule_on_exec_ctx)); |
||||
} |
||||
} |
||||
BENCHMARK(BM_ClosureInitAgainstExecCtx); |
||||
|
||||
static void BM_ClosureInitAgainstCombiner(benchmark::State& state) { |
||||
grpc_combiner* combiner = grpc_combiner_create(NULL); |
||||
grpc_closure c; |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
while (state.KeepRunning()) { |
||||
benchmark::DoNotOptimize(grpc_closure_init( |
||||
&c, DoNothing, NULL, grpc_combiner_scheduler(combiner, false))); |
||||
} |
||||
GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
BENCHMARK(BM_ClosureInitAgainstCombiner); |
||||
|
||||
static void BM_ClosureRunOnExecCtx(benchmark::State& state) { |
||||
grpc_closure c; |
||||
grpc_closure_init(&c, DoNothing, NULL, grpc_schedule_on_exec_ctx); |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
while (state.KeepRunning()) { |
||||
grpc_closure_run(&exec_ctx, &c, GRPC_ERROR_NONE); |
||||
grpc_exec_ctx_flush(&exec_ctx); |
||||
} |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
BENCHMARK(BM_ClosureRunOnExecCtx); |
||||
|
||||
static void BM_ClosureCreateAndRun(benchmark::State& state) { |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
while (state.KeepRunning()) { |
||||
grpc_closure_run(&exec_ctx, grpc_closure_create(DoNothing, NULL, |
||||
grpc_schedule_on_exec_ctx), |
||||
GRPC_ERROR_NONE); |
||||
} |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
BENCHMARK(BM_ClosureCreateAndRun); |
||||
|
||||
static void BM_ClosureInitAndRun(benchmark::State& state) { |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
grpc_closure c; |
||||
while (state.KeepRunning()) { |
||||
grpc_closure_run(&exec_ctx, grpc_closure_init(&c, DoNothing, NULL, |
||||
grpc_schedule_on_exec_ctx), |
||||
GRPC_ERROR_NONE); |
||||
} |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
BENCHMARK(BM_ClosureInitAndRun); |
||||
|
||||
static void BM_ClosureSchedOnExecCtx(benchmark::State& state) { |
||||
grpc_closure c; |
||||
grpc_closure_init(&c, DoNothing, NULL, grpc_schedule_on_exec_ctx); |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
while (state.KeepRunning()) { |
||||
grpc_closure_sched(&exec_ctx, &c, GRPC_ERROR_NONE); |
||||
grpc_exec_ctx_flush(&exec_ctx); |
||||
} |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
BENCHMARK(BM_ClosureSchedOnExecCtx); |
||||
|
||||
static void BM_ClosureSched2OnExecCtx(benchmark::State& state) { |
||||
grpc_closure c1; |
||||
grpc_closure c2; |
||||
grpc_closure_init(&c1, DoNothing, NULL, grpc_schedule_on_exec_ctx); |
||||
grpc_closure_init(&c2, DoNothing, NULL, grpc_schedule_on_exec_ctx); |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
while (state.KeepRunning()) { |
||||
grpc_closure_sched(&exec_ctx, &c1, GRPC_ERROR_NONE); |
||||
grpc_closure_sched(&exec_ctx, &c2, GRPC_ERROR_NONE); |
||||
grpc_exec_ctx_flush(&exec_ctx); |
||||
} |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
BENCHMARK(BM_ClosureSched2OnExecCtx); |
||||
|
||||
static void BM_ClosureSched3OnExecCtx(benchmark::State& state) { |
||||
grpc_closure c1; |
||||
grpc_closure c2; |
||||
grpc_closure c3; |
||||
grpc_closure_init(&c1, DoNothing, NULL, grpc_schedule_on_exec_ctx); |
||||
grpc_closure_init(&c2, DoNothing, NULL, grpc_schedule_on_exec_ctx); |
||||
grpc_closure_init(&c3, DoNothing, NULL, grpc_schedule_on_exec_ctx); |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
while (state.KeepRunning()) { |
||||
grpc_closure_sched(&exec_ctx, &c1, GRPC_ERROR_NONE); |
||||
grpc_closure_sched(&exec_ctx, &c2, GRPC_ERROR_NONE); |
||||
grpc_closure_sched(&exec_ctx, &c3, GRPC_ERROR_NONE); |
||||
grpc_exec_ctx_flush(&exec_ctx); |
||||
} |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
BENCHMARK(BM_ClosureSched3OnExecCtx); |
||||
|
||||
static void BM_AcquireMutex(benchmark::State& state) { |
||||
// for comparison with the combiner stuff below
|
||||
gpr_mu mu; |
||||
gpr_mu_init(&mu); |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
while (state.KeepRunning()) { |
||||
gpr_mu_lock(&mu); |
||||
DoNothing(&exec_ctx, NULL, GRPC_ERROR_NONE); |
||||
gpr_mu_unlock(&mu); |
||||
} |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
BENCHMARK(BM_AcquireMutex); |
||||
|
||||
static void BM_ClosureSchedOnCombiner(benchmark::State& state) { |
||||
grpc_combiner* combiner = grpc_combiner_create(NULL); |
||||
grpc_closure c; |
||||
grpc_closure_init(&c, DoNothing, NULL, |
||||
grpc_combiner_scheduler(combiner, false)); |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
while (state.KeepRunning()) { |
||||
grpc_closure_sched(&exec_ctx, &c, GRPC_ERROR_NONE); |
||||
grpc_exec_ctx_flush(&exec_ctx); |
||||
} |
||||
GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
BENCHMARK(BM_ClosureSchedOnCombiner); |
||||
|
||||
static void BM_ClosureSched2OnCombiner(benchmark::State& state) { |
||||
grpc_combiner* combiner = grpc_combiner_create(NULL); |
||||
grpc_closure c1; |
||||
grpc_closure c2; |
||||
grpc_closure_init(&c1, DoNothing, NULL, |
||||
grpc_combiner_scheduler(combiner, false)); |
||||
grpc_closure_init(&c2, DoNothing, NULL, |
||||
grpc_combiner_scheduler(combiner, false)); |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
while (state.KeepRunning()) { |
||||
grpc_closure_sched(&exec_ctx, &c1, GRPC_ERROR_NONE); |
||||
grpc_closure_sched(&exec_ctx, &c2, GRPC_ERROR_NONE); |
||||
grpc_exec_ctx_flush(&exec_ctx); |
||||
} |
||||
GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
BENCHMARK(BM_ClosureSched2OnCombiner); |
||||
|
||||
static void BM_ClosureSched3OnCombiner(benchmark::State& state) { |
||||
grpc_combiner* combiner = grpc_combiner_create(NULL); |
||||
grpc_closure c1; |
||||
grpc_closure c2; |
||||
grpc_closure c3; |
||||
grpc_closure_init(&c1, DoNothing, NULL, |
||||
grpc_combiner_scheduler(combiner, false)); |
||||
grpc_closure_init(&c2, DoNothing, NULL, |
||||
grpc_combiner_scheduler(combiner, false)); |
||||
grpc_closure_init(&c3, DoNothing, NULL, |
||||
grpc_combiner_scheduler(combiner, false)); |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
while (state.KeepRunning()) { |
||||
grpc_closure_sched(&exec_ctx, &c1, GRPC_ERROR_NONE); |
||||
grpc_closure_sched(&exec_ctx, &c2, GRPC_ERROR_NONE); |
||||
grpc_closure_sched(&exec_ctx, &c3, GRPC_ERROR_NONE); |
||||
grpc_exec_ctx_flush(&exec_ctx); |
||||
} |
||||
GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
BENCHMARK(BM_ClosureSched3OnCombiner); |
||||
|
||||
static void BM_ClosureSched2OnTwoCombiners(benchmark::State& state) { |
||||
grpc_combiner* combiner1 = grpc_combiner_create(NULL); |
||||
grpc_combiner* combiner2 = grpc_combiner_create(NULL); |
||||
grpc_closure c1; |
||||
grpc_closure c2; |
||||
grpc_closure_init(&c1, DoNothing, NULL, |
||||
grpc_combiner_scheduler(combiner1, false)); |
||||
grpc_closure_init(&c2, DoNothing, NULL, |
||||
grpc_combiner_scheduler(combiner2, false)); |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
while (state.KeepRunning()) { |
||||
grpc_closure_sched(&exec_ctx, &c1, GRPC_ERROR_NONE); |
||||
grpc_closure_sched(&exec_ctx, &c2, GRPC_ERROR_NONE); |
||||
grpc_exec_ctx_flush(&exec_ctx); |
||||
} |
||||
GRPC_COMBINER_UNREF(&exec_ctx, combiner1, "finished"); |
||||
GRPC_COMBINER_UNREF(&exec_ctx, combiner2, "finished"); |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
BENCHMARK(BM_ClosureSched2OnTwoCombiners); |
||||
|
||||
static void BM_ClosureSched4OnTwoCombiners(benchmark::State& state) { |
||||
grpc_combiner* combiner1 = grpc_combiner_create(NULL); |
||||
grpc_combiner* combiner2 = grpc_combiner_create(NULL); |
||||
grpc_closure c1; |
||||
grpc_closure c2; |
||||
grpc_closure c3; |
||||
grpc_closure c4; |
||||
grpc_closure_init(&c1, DoNothing, NULL, |
||||
grpc_combiner_scheduler(combiner1, false)); |
||||
grpc_closure_init(&c2, DoNothing, NULL, |
||||
grpc_combiner_scheduler(combiner2, false)); |
||||
grpc_closure_init(&c3, DoNothing, NULL, |
||||
grpc_combiner_scheduler(combiner1, false)); |
||||
grpc_closure_init(&c4, DoNothing, NULL, |
||||
grpc_combiner_scheduler(combiner2, false)); |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
while (state.KeepRunning()) { |
||||
grpc_closure_sched(&exec_ctx, &c1, GRPC_ERROR_NONE); |
||||
grpc_closure_sched(&exec_ctx, &c2, GRPC_ERROR_NONE); |
||||
grpc_closure_sched(&exec_ctx, &c3, GRPC_ERROR_NONE); |
||||
grpc_closure_sched(&exec_ctx, &c4, GRPC_ERROR_NONE); |
||||
grpc_exec_ctx_flush(&exec_ctx); |
||||
} |
||||
GRPC_COMBINER_UNREF(&exec_ctx, combiner1, "finished"); |
||||
GRPC_COMBINER_UNREF(&exec_ctx, combiner2, "finished"); |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
BENCHMARK(BM_ClosureSched4OnTwoCombiners); |
||||
|
||||
// Helper that continuously reschedules the same closure against something until
|
||||
// the benchmark is complete
|
||||
class Rescheduler { |
||||
public: |
||||
Rescheduler(benchmark::State& state, grpc_closure_scheduler* scheduler) |
||||
: state_(state) { |
||||
grpc_closure_init(&closure_, Step, this, scheduler); |
||||
} |
||||
|
||||
void ScheduleFirst(grpc_exec_ctx* exec_ctx) { |
||||
grpc_closure_sched(exec_ctx, &closure_, GRPC_ERROR_NONE); |
||||
} |
||||
|
||||
void ScheduleFirstAgainstDifferentScheduler( |
||||
grpc_exec_ctx* exec_ctx, grpc_closure_scheduler* scheduler) { |
||||
grpc_closure_sched(exec_ctx, grpc_closure_create(Step, this, scheduler), |
||||
GRPC_ERROR_NONE); |
||||
} |
||||
|
||||
private: |
||||
benchmark::State& state_; |
||||
grpc_closure closure_; |
||||
|
||||
static void Step(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { |
||||
Rescheduler* self = static_cast<Rescheduler*>(arg); |
||||
if (self->state_.KeepRunning()) { |
||||
grpc_closure_sched(exec_ctx, &self->closure_, GRPC_ERROR_NONE); |
||||
} |
||||
} |
||||
}; |
||||
|
||||
static void BM_ClosureReschedOnExecCtx(benchmark::State& state) { |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
Rescheduler r(state, grpc_schedule_on_exec_ctx); |
||||
r.ScheduleFirst(&exec_ctx); |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
BENCHMARK(BM_ClosureReschedOnExecCtx); |
||||
|
||||
static void BM_ClosureReschedOnCombiner(benchmark::State& state) { |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
grpc_combiner* combiner = grpc_combiner_create(NULL); |
||||
Rescheduler r(state, grpc_combiner_scheduler(combiner, false)); |
||||
r.ScheduleFirst(&exec_ctx); |
||||
grpc_exec_ctx_flush(&exec_ctx); |
||||
GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
BENCHMARK(BM_ClosureReschedOnCombiner); |
||||
|
||||
static void BM_ClosureReschedOnCombinerFinally(benchmark::State& state) { |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
grpc_combiner* combiner = grpc_combiner_create(NULL); |
||||
Rescheduler r(state, grpc_combiner_finally_scheduler(combiner, false)); |
||||
r.ScheduleFirstAgainstDifferentScheduler( |
||||
&exec_ctx, grpc_combiner_scheduler(combiner, false)); |
||||
grpc_exec_ctx_flush(&exec_ctx); |
||||
GRPC_COMBINER_UNREF(&exec_ctx, combiner, "finished"); |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
BENCHMARK(BM_ClosureReschedOnCombinerFinally); |
||||
|
||||
BENCHMARK_MAIN(); |
@ -0,0 +1,41 @@ |
||||
#!/bin/bash |
||||
# Copyright 2017, Google Inc. |
||||
# All rights reserved. |
||||
# |
||||
# Redistribution and use in source and binary forms, with or without |
||||
# modification, are permitted provided that the following conditions are |
||||
# met: |
||||
# |
||||
# * Redistributions of source code must retain the above copyright |
||||
# notice, this list of conditions and the following disclaimer. |
||||
# * Redistributions in binary form must reproduce the above |
||||
# copyright notice, this list of conditions and the following disclaimer |
||||
# in the documentation and/or other materials provided with the |
||||
# distribution. |
||||
# * Neither the name of Google Inc. nor the names of its |
||||
# contributors may be used to endorse or promote products derived from |
||||
# this software without specific prior written permission. |
||||
# |
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
# Config file for the internal CI (in protobuf text format) |
||||
|
||||
# Location of the continuous shell script in repository. |
||||
build_file: "grpc/tools/internal_ci/linux/grpc_interop.sh" |
||||
# grpc_interop tests can take 6+ hours to complete. |
||||
timeout_mins: 480 |
||||
action { |
||||
define_artifacts { |
||||
regex: "**/sponge_log.xml" |
||||
} |
||||
} |
@ -0,0 +1,42 @@ |
||||
#!/usr/bin/env bash |
||||
# Copyright 2017, Google Inc. |
||||
# All rights reserved. |
||||
# |
||||
# Redistribution and use in source and binary forms, with or without |
||||
# modification, are permitted provided that the following conditions are |
||||
# met: |
||||
# |
||||
# * Redistributions of source code must retain the above copyright |
||||
# notice, this list of conditions and the following disclaimer. |
||||
# * Redistributions in binary form must reproduce the above |
||||
# copyright notice, this list of conditions and the following disclaimer |
||||
# in the documentation and/or other materials provided with the |
||||
# distribution. |
||||
# * Neither the name of Google Inc. nor the names of its |
||||
# contributors may be used to endorse or promote products derived from |
||||
# this software without specific prior written permission. |
||||
# |
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
set -ex |
||||
|
||||
export LANG=en_US.UTF-8 |
||||
|
||||
# Enter the gRPC repo root |
||||
cd $(dirname $0)/../../.. |
||||
|
||||
git submodule update --init |
||||
|
||||
tools/run_tests/run_interop_tests.py -l all -s all --cloud_to_prod --cloud_to_prod_auth --use_docker --http2_interop -t -j 12 $@ || FAILED="true" |
||||
tools/run_tests/run_interop_tests.py -l java --use_docker --http2_badserver_interop $@ || FAILED="true" |
||||
tools/run_tests/run_interop_tests.py -l python --use_docker --http2_badserver_interop $@ || FAILED="true" |
Loading…
Reference in new issue