Skip to content

Commit

Permalink
c/producer_state: keep producer inflight requests queue bounded
Browse files Browse the repository at this point in the history
Idempotent producers are allowed to produce up to 5 at a time, the five
requests outcome is cached in the producer for deduplication. Previously
the `_inflight_requests` list might grow unbounded if state machine
apply was lagging. This causes performance issues and unnecessary memory
pressure. Since the max inflight requests count is limited by producer
it is enough to keep only last 5 inflight requests in the
`_inflight_requests` list.

Signed-off-by: Michał Maślanka <michal@redpanda.com>
  • Loading branch information
mmaslankaprv committed Oct 10, 2024
1 parent dc252d7 commit 755a890
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/v/cluster/producer_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,17 @@ result<request_ptr> requests::try_emplace(
// All invariants satisfied, enqueue the request.
_inflight_requests.emplace_back(
ss::make_lw_shared<request>(first, last, current, result_promise_t{}));
// if there are more than max cached requests inflight start dropping the
// oldest of them
while (_inflight_requests.size() > requests_cached_max
&& _inflight_requests.front()->has_completed()) {
_inflight_requests.pop_front();
// clear finished requests as the producer will not be interested in
// them anymore
if (!_finished_requests.empty()) {
_finished_requests.clear();
}
}

return _inflight_requests.back();
}
Expand Down

0 comments on commit 755a890

Please sign in to comment.