Skip to content

perf(fill_pipeline): make bufferevent_enable conditional on m_bev_paused - #448

Merged
fcostaoliveira merged 1 commit into
redis:masterfrom
filipecosta90:perf/conditional-bufferevent-enable
Jun 2, 2026
Merged

fcostaoliveira merged 1 commit into
redis:masterfrom
filipecosta90:perf/conditional-bufferevent-enable

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Jun 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

2.4 regression flagged by micro-bench: ~4% ops/sec drop on the canonical SET/GET workload vs 2.3.1.

Root cause: bufferevent_enable(m_bev, EV_READ | EV_WRITE) was added at the top of shard_connection::fill_pipeline() in #390 / #400 to recover from --transaction's hold_pipeline disable. But fill_pipeline runs per response received, so this lock-taking libevent call (it takes BEV_LOCK internally even on a no-op) fires at the request rate.

Fix: Track pause state with a bool m_bev_paused flag. Only call bufferevent_enable when the flag indicates the bufferevent was actually paused.

  • Invariant: m_bev_paused == true iff m_bev is in the EV_READ|EV_WRITE-disabled state.
  • Flag is set at the lone bufferevent_disable site (idle-disable branch in fill_pipeline).
  • Flag is cleared at every existing bufferevent_enable site (fill_pipeline resume branch, handle_event on BEV_EVENT_CONNECTED, schedule_fill), and on bev (re)creation / teardown (setup_event, disconnect).

Validation

Functional (--transaction)

Verified against a manual 3-node OSS cluster with --cluster-mode --transaction --command="MULTI" --command="SET tx_{tag}_key __key__" --command="EXEC" at pipeline=4, clients=4, threads=2:

Binary Multis ops/sec Sets ops/sec Execs ops/sec
master 382.69 382.69 382.69
perffix 428.36 428.18 428.18

1:1:1 Multis:Sets:Execs ratio preserved (no transactions torn apart, no server-side errors).

Performance

Local micro-bench on a 14-core Intel Core Ultra 7 155U against a single localhost Redis 8.6.0. The canonical pipeline=32 clients=50 threads=4 ratio=1:1 run is server-bound on this hardware (~605K-620K ops/sec is the Redis ceiling on one core), so the client-side improvement is masked by Redis saturation:

Run (3 iters mean) Before (master) After (perffix) Delta
--pipeline=32 --clients=50 --threads=4 --requests=300K 617,729 ops/sec 619,599 ops/sec +0.30%
--pipeline=1 --clients=50 --threads=4 --requests=100K 124,999 ops/sec 125,121 ops/sec +0.10%

To exercise the client side, pinned memtier to 2 cores (taskset -c 0,1) to make the client the bottleneck:

Run (3 iters mean) Before (master) After (perffix) Delta
taskset -c 0,1 --pipeline=32 --clients=100 --threads=2 --requests=200K 322,237 ops/sec 363,517 ops/sec +12.81%

The fix recovers the regression on client-bound workloads; the original 4% reported on the benchmark farm corresponds to a setup where the client is closer to the bottleneck than my localhost test rig.

Test plan

  • Clean build, no new warnings (autoreconf -ivf && ./configure && make -j)
  • --transaction smoke against 3-node OSS cluster: 1:1:1 ratio preserved at pipeline=4
  • --transaction smoke against standalone (no-op warning + normal execution)
  • Micro-bench on client-bound workload (taskset -c 0,1): +12.81% recovery
  • Format check passes (make format-check-staged)
  • CI: full transaction RLTest suite (test_cluster_transaction.py, test_transaction_pipeline.py)

Refs: 2.4 review #28 (Review 18 MED finding); regression introduced by #390 / #400.


Note

Low Risk
Localized libevent I/O gating in shard_connection with an explicit pause flag; behavior change is skipping redundant enables on the steady-state path.

Overview
Fixes a ~4% ops/sec regression on high-throughput SET/GET by stopping fill_pipeline() from calling bufferevent_enable() on every response. That unconditional resume was added to undo idle/--transaction hold_pipeline pauses but runs in the hot path and takes libevent’s BEV_LOCK even when I/O was already enabled.

The change adds m_bev_paused, set when fill_pipeline disables read/write on an idle connection and cleared on connect, schedule_fill, and other real enable paths. bufferevent_enable now runs only when the connection was actually paused, preserving transaction and idle-disable behavior without per-response overhead.

Reviewed by Cursor Bugbot for commit 04db221. Bugbot is set up for automated code reviews on this repo. Configure here.

2.4 regression flagged by micro-bench: ~4% ops/sec drop on canonical
SET/GET vs 2.3.1. Root cause: bufferevent_enable at the top of
fill_pipeline was added in redis#390/redis#400 to recover from --transaction's
hold_pipeline disable, but it fires every fill_pipeline invocation
(per response received) -- taking libevent's BEV_LOCK in the hot
path even when no pause/resume is needed.

Track pause state with bool m_bev_paused; only call bufferevent_enable
when the flag indicates the bufferevent was actually paused. Set the
flag at the disable site, clear it at the existing enable sites
(handle_event, schedule_fill, fill_pipeline's resume branch) and on
bev (re)creation/teardown (setup_event, disconnect). Invariant:
m_bev_paused == true iff bufferevent is in EV_READ|EV_WRITE disabled.

Local micro-bench: server-bound runs against a single localhost Redis
on this box stay within noise (~+0.3% on pipeline=32 clients=50
threads=4 ratio=1:1 300K reqs, 3 runs each) because Redis is the
bottleneck. Forcing the client to be the bottleneck (taskset -c 0,1
clients=100 threads=2 pipeline=32 ratio=1:1 200K reqs, 3 runs each)
shows +12.81% ops/sec recovery (322,237 -> 363,517). Functional
parity verified with --transaction MULTI/SET/EXEC against a manual
3-node cluster (1:1:1 Multis:Sets:Execs ratio, no errors).

Refs: 2.4 review redis#28 (Review 18 MED finding).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@jit-ci

jit-ci Bot commented Jun 2, 2026

Copy link
Copy Markdown

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

@fcostaoliveira
fcostaoliveira merged commit 03ef76e into redis:master Jun 2, 2026
77 checks passed
fcostaoliveira added a commit that referenced this pull request Jun 2, 2026
…sed (#448)

2.4 regression flagged by micro-bench: ~4% ops/sec drop on canonical
SET/GET vs 2.3.1. Root cause: bufferevent_enable at the top of
fill_pipeline was added in #390/#400 to recover from --transaction's
hold_pipeline disable, but it fires every fill_pipeline invocation
(per response received) -- taking libevent's BEV_LOCK in the hot
path even when no pause/resume is needed.

Track pause state with bool m_bev_paused; only call bufferevent_enable
when the flag indicates the bufferevent was actually paused. Set the
flag at the disable site, clear it at the existing enable sites
(handle_event, schedule_fill, fill_pipeline's resume branch) and on
bev (re)creation/teardown (setup_event, disconnect). Invariant:
m_bev_paused == true iff bufferevent is in EV_READ|EV_WRITE disabled.

Local micro-bench: server-bound runs against a single localhost Redis
on this box stay within noise (~+0.3% on pipeline=32 clients=50
threads=4 ratio=1:1 300K reqs, 3 runs each) because Redis is the
bottleneck. Forcing the client to be the bottleneck (taskset -c 0,1
clients=100 threads=2 pipeline=32 ratio=1:1 200K reqs, 3 runs each)
shows +12.81% ops/sec recovery (322,237 -> 363,517). Functional
parity verified with --transaction MULTI/SET/EXEC against a manual
3-node cluster (1:1:1 Multis:Sets:Execs ratio, no errors).

Refs: 2.4 review #28 (Review 18 MED finding).

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant