Skip to content

Commit

Permalink
[Chttp2Transport] Flush data out over the transport quickly under hig…
Browse files Browse the repository at this point in the history
…h memory pressure. The change is protected under an experiment: disable_buffer_hint_on_high_memory_pressure

PiperOrigin-RevId: 694625426
  • Loading branch information
Vignesh2208 authored and copybara-github committed Nov 8, 2024
1 parent 740d219 commit 5fcc5f8
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions bazel/experiments.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion src/core/ext/transport/chttp2/transport/chttp2_transport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <algorithm>
#include <atomic>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <memory>
#include <new>
Expand Down Expand Up @@ -1470,7 +1471,7 @@ static void send_message_locked(
op->payload->send_message.send_message->Length());
on_complete->next_data.scratch |= t->closure_barrier_may_cover_write;
s->send_message_finished = add_closure_barrier(op->on_complete);
const uint32_t flags = op_payload->send_message.flags;
uint32_t flags = 0;
if (s->write_closed) {
op->payload->send_message.stream_write_closed = true;
// We should NOT return an error here, so as to avoid a cancel OP being
Expand All @@ -1480,6 +1481,19 @@ static void send_message_locked(
absl::OkStatus(),
"fetching_send_message_finished");
} else {
// Buffer hint is used to buffer the message in the transport until the
// write buffer size (specified through GRPC_ARG_HTTP2_WRITE_BUFFER_SIZE) is
// reached. This is to batch writes sent down to tcp. However, if the memory
// pressure is high, disable the buffer hint to flush data down to tcp as
// soon as possible to avoid OOM.
if (grpc_core::IsDisableBufferHintOnHighMemoryPressureEnabled() &&
t->memory_owner.GetPressureInfo().pressure_control_value >= 0.8) {
// Disable write buffer hint if memory pressure is high. The value of 0.8
// is chosen to match the threshold used by the tcp endpoint (in
// allocating memory for socket reads).
op_payload->send_message.flags &= ~GRPC_WRITE_BUFFER_HINT;
}
flags = op_payload->send_message.flags;
uint8_t* frame_hdr = grpc_slice_buffer_tiny_add(&s->flow_controlled_buffer,
GRPC_HEADER_SIZE_IN_BYTES);
frame_hdr[0] = (flags & GRPC_WRITE_INTERNAL_COMPRESS) != 0;
Expand Down
27 changes: 27 additions & 0 deletions src/core/lib/experiments/experiments.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/core/lib/experiments/experiments.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/core/lib/experiments/experiments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
owner: [email protected]
test_tags: []
allow_in_fuzzing_config: false
- name: disable_buffer_hint_on_high_memory_pressure
description:
Disable buffer hint flag parsing in the transport under high memory pressure.
expiry: 2025/03/01
owner: [email protected]
test_tags: []
- name: event_engine_application_callbacks
description: Run application callbacks in EventEngine threads, instead of on the thread-local ApplicationCallbackExecCtx
expiry: 2025/03/01
Expand Down
2 changes: 2 additions & 0 deletions src/core/lib/experiments/rollouts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
windows: broken
- name: client_privacy
default: false
- name: disable_buffer_hint_on_high_memory_pressure
default: false
- name: event_engine_application_callbacks
default: true
- name: event_engine_callback_cq
Expand Down

0 comments on commit 5fcc5f8

Please sign in to comment.