Skip to content

Commit 8bf14eb

Browse files
Vignesh2208copybara-github
authored andcommitted
[chttp2] Prioritize sending out finished requests over other in flight requests in the transport (grpc#39897)
To debug b/377705482 Closes grpc#39897 COPYBARA_INTEGRATE_REVIEW=grpc#39897 from Vignesh2208:prioritize-finished-requests a0f50f0 PiperOrigin-RevId: 772570354
1 parent fd59c51 commit 8bf14eb

File tree

6 files changed

+77
-1
lines changed

6 files changed

+77
-1
lines changed

bazel/experiments.bzl

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/ext/transport/chttp2/transport/stream_lists.cc

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,26 @@ static void stream_list_add_tail(grpc_chttp2_transport* t,
128128
<< "]: add to " << stream_list_id_string(id);
129129
}
130130

131+
static void stream_list_add_head(grpc_chttp2_transport* t,
132+
grpc_chttp2_stream* s,
133+
grpc_chttp2_stream_list_id id) {
134+
grpc_chttp2_stream* old_head;
135+
CHECK(!s->included.is_set(id));
136+
old_head = t->lists[id].head;
137+
s->links[id].next = old_head;
138+
s->links[id].prev = nullptr;
139+
if (old_head) {
140+
old_head->links[id].prev = s;
141+
} else {
142+
t->lists[id].tail = s;
143+
}
144+
t->lists[id].head = s;
145+
s->included.set(id);
146+
GRPC_TRACE_LOG(http2_stream_state, INFO)
147+
<< t << "[" << s->id << "][" << (t->is_client ? "cli" : "svr")
148+
<< "]: add to " << stream_list_id_string(id);
149+
}
150+
131151
static bool stream_list_add(grpc_chttp2_transport* t, grpc_chttp2_stream* s,
132152
grpc_chttp2_stream_list_id id) {
133153
if (s->included.is_set(id)) {
@@ -137,11 +157,24 @@ static bool stream_list_add(grpc_chttp2_transport* t, grpc_chttp2_stream* s,
137157
return true;
138158
}
139159

160+
static bool stream_list_prepend(grpc_chttp2_transport* t, grpc_chttp2_stream* s,
161+
grpc_chttp2_stream_list_id id) {
162+
if (s->included.is_set(id)) {
163+
return false;
164+
}
165+
stream_list_add_head(t, s, id);
166+
return true;
167+
}
168+
140169
// wrappers for specializations
141170

142171
bool grpc_chttp2_list_add_writable_stream(grpc_chttp2_transport* t,
143172
grpc_chttp2_stream* s) {
144173
CHECK_NE(s->id, 0u);
174+
if (grpc_core::IsPrioritizeFinishedRequestsEnabled() &&
175+
s->send_trailing_metadata != nullptr) {
176+
return stream_list_prepend(t, s, GRPC_CHTTP2_LIST_WRITABLE);
177+
}
145178
return stream_list_add(t, s, GRPC_CHTTP2_LIST_WRITABLE);
146179
}
147180

@@ -186,7 +219,12 @@ void grpc_chttp2_list_remove_waiting_for_concurrency(grpc_chttp2_transport* t,
186219

187220
void grpc_chttp2_list_add_stalled_by_transport(grpc_chttp2_transport* t,
188221
grpc_chttp2_stream* s) {
189-
stream_list_add(t, s, GRPC_CHTTP2_LIST_STALLED_BY_TRANSPORT);
222+
if (grpc_core::IsPrioritizeFinishedRequestsEnabled() &&
223+
s->send_trailing_metadata != nullptr) {
224+
stream_list_prepend(t, s, GRPC_CHTTP2_LIST_STALLED_BY_TRANSPORT);
225+
} else {
226+
stream_list_add(t, s, GRPC_CHTTP2_LIST_STALLED_BY_TRANSPORT);
227+
}
190228
}
191229

192230
bool grpc_chttp2_list_pop_stalled_by_transport(grpc_chttp2_transport* t,

src/core/lib/experiments/experiments.cc

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/lib/experiments/experiments.h

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/lib/experiments/experiments.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@
171171
test_tags: ["core_end2end_test"]
172172
requires: ["event_engine_client", "event_engine_listener"]
173173
allow_in_fuzzing_config: false
174+
- name: prioritize_finished_requests
175+
description: Prioritize flushing out finished requests over other in-flight
176+
requests during transport writes.
177+
expiry: 2025/09/01
178+
179+
test_tags: []
174180
- name: promise_based_http2_client_transport
175181
description:
176182
Use promises for the http2 client transport. We have kept client and

src/core/lib/experiments/rollouts.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
default: true
7575
- name: pollset_alternative
7676
default: false
77+
- name: prioritize_finished_requests
78+
default: false
7779
- name: promise_based_http2_client_transport
7880
default: false
7981
- name: promise_based_http2_server_transport

0 commit comments

Comments
 (0)