aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/ext
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-07-20 12:52:09 -0700
committerGravatar Craig Tiller <ctiller@google.com>2017-07-20 12:52:09 -0700
commit399515535516cf3bb5c880a78d429580059ab609 (patch)
tree1ee4465adea5bb260fee9a5de6cce854fa3821fb /src/core/ext
parent4f165829394be848f7a08926f67cf038e6c08087 (diff)
Tweak write scheduling rules
Diffstat (limited to 'src/core/ext')
-rw-r--r--src/core/ext/transport/chttp2/transport/chttp2_transport.c15
-rw-r--r--src/core/ext/transport/chttp2/transport/internal.h4
2 files changed, 16 insertions, 3 deletions
diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c
index c2ed2f1bc9..3d7f2f3668 100644
--- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c
+++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c
@@ -844,6 +844,7 @@ void grpc_chttp2_initiate_write(grpc_exec_ctx *exec_ctx,
switch (t->write_state) {
case GRPC_CHTTP2_WRITE_STATE_IDLE:
set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_WRITING, reason);
+ t->is_first_write_in_batch = true;
GRPC_CHTTP2_REF_TRANSPORT(t, "writing");
GRPC_CLOSURE_SCHED(
exec_ctx,
@@ -876,13 +877,20 @@ void grpc_chttp2_become_writable(grpc_exec_ctx *exec_ctx,
static grpc_closure_scheduler *write_scheduler(grpc_chttp2_transport *t,
bool early_results_scheduled) {
+ /* if it's not the first write in a batch, always offload to the executor:
+ we'll probably end up queuing against the kernel anyway, so we'll likely
+ get better latency overall if we switch writing work elsewhere and continue
+ with application work above */
+ if (!t->is_first_write_in_batch) {
+ return grpc_executor_scheduler(GRPC_EXECUTOR_SHORT);
+ }
switch (t->opt_target) {
case GRPC_CHTTP2_OPTIMIZE_FOR_THROUGHPUT:
+ /* executor gives us the largest probability of being able to batch a
+ * write with others on this transport */
return grpc_executor_scheduler(GRPC_EXECUTOR_SHORT);
case GRPC_CHTTP2_OPTIMIZE_FOR_LATENCY:
- return early_results_scheduled
- ? grpc_executor_scheduler(GRPC_EXECUTOR_SHORT)
- : grpc_schedule_on_exec_ctx;
+ return grpc_schedule_on_exec_ctx;
}
GPR_UNREACHABLE_CODE(return NULL);
}
@@ -970,6 +978,7 @@ static void write_action_end_locked(grpc_exec_ctx *exec_ctx, void *tp,
GPR_TIMER_MARK("state=writing_stale_no_poller", 0);
set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_WRITING,
"continue writing");
+ t->is_first_write_in_batch = false;
GRPC_CHTTP2_REF_TRANSPORT(t, "writing");
GRPC_CLOSURE_RUN(
exec_ctx,
diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h
index 17cfe3741f..8d0b455ba9 100644
--- a/src/core/ext/transport/chttp2/transport/internal.h
+++ b/src/core/ext/transport/chttp2/transport/internal.h
@@ -223,6 +223,10 @@ struct grpc_chttp2_transport {
/** write execution state of the transport */
grpc_chttp2_write_state write_state;
+ /** is this the first write in a series of writes?
+ set when we initiate writing from idle, cleared when we
+ initiate writing from writing+more */
+ bool is_first_write_in_batch;
/** is the transport destroying itself? */
uint8_t destroying;