Skip to content

[9.0] (backport #17765) pq: reduce read contention when caught up#17791

Merged
yaauie merged 1 commit into9.0from
mergify/bp/9.0/pr-17765
Jul 10, 2025
Merged

[9.0] (backport #17765) pq: reduce read contention when caught up#17791
yaauie merged 1 commit into9.0from
mergify/bp/9.0/pr-17765

Conversation

@mergify
Copy link
Contributor

@mergify mergify bot commented Jul 10, 2025

Release notes

  • Significantly improves throughput of the persisted queue

What does this PR do?

Eliminates per-event overhead from workers consuming from a persisted queue.

By keeping track of the lock-holding reader's demand (a quantity of events and a deadline), we can avoid waking up the reader for each event that is written to the queue, significantly reducing the time that the lock-holding writer is blocked by synchronous read operations. The lock-holding reader is awoken when its demand is met, has expired, or when the writer has rotated pages.

Why is it important/What is the impact to the user?

Significantly improves PQ throughput.

From my local tests (ARM / M3 Pro 12 CPU / SSD) with input { java_generator {} } output { sink {} }:

batch size unpatched this patch
125 260k 498k
2000 219k 516k

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files (and/or docker env variables)
  • [ ] I have added tests that prove my fix is effective or that my feature works

Author's Checklist

  • [ ]

How to test this PR locally

  1. run a generator-to-sink pipeline:
    bin/logstash -e 'input { java_generator {} } output { sink {} }'
    
  2. observe throughput via API:
    curl --silent 'localhost:9600/_node/stats?pretty=true' | jq .flow.output_throughput
    

Related issues


This is an automatic backport of pull request #17765 done by [Mergify](https://mergify.com).
* pq: reduce read contention when caught up

By keeping track of the lock-holding reader's demand (a quantity of events and
a deadline), we can avoid waking up the reader for each event that is written
to the queue, significantly reducing the time that the lock-holding _writer_
is blocked by synchronous read operations. The lock-holding reader is awoken
when its demand is met, has expired, or when the writer has rotated pages.

| batch size | unpatched | this patch |
| ---------- | --------- | ---------- |
|        125 |      260k |       498k |
|       2000 |      219k |       516k |

* remove superfluous volatile flag

(cherry picked from commit ddd519c)
@mergify mergify bot added the backport label Jul 10, 2025
@mergify mergify bot assigned yaauie Jul 10, 2025
@elastic-sonarqube
Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@elasticmachine
Copy link

💚 Build Succeeded

cc @yaauie

Copy link
Member

@yaauie yaauie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Clean and Green 🎉

@yaauie yaauie merged commit b6eb42a into 9.0 Jul 10, 2025
7 checks passed
@yaauie yaauie deleted the mergify/bp/9.0/pr-17765 branch July 10, 2025 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 participants