Skip to content

Remove HTTP content copies #117303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Nov 26, 2024
Merged

Remove HTTP content copies #117303

merged 11 commits into from
Nov 26, 2024

Conversation

mhl-b
Copy link
Contributor

@mhl-b mhl-b commented Nov 22, 2024

Remove HTTP content copies entirely from REST handlers. All handlers from now should use RefCounted pooled byte buffers. Handlers that parse x-content in prepareRequest by default will use pooled buffers. Other handlers that move pooled buffer to another thread should use new method ActionListener.withRef(listener, content) for proper reference counting.

In current implementation of ActionListener.withRef buffers are retained till we have a response. It is not optimal since buffers can be released once request is dispatched in transport. But in reality the performance implication might be negligible. Ideally we should bind buffer lifetime to the transport request, not to results listener. But it's a larger code change. For example BytesTransportRequest implements explicit ref counting for the content.

For example:

- return channel -> client.index(indexRequest, new RestToXContentListener<>(channel));
+ return channel -> client.index(indexRequest, ActionListener.withRef(new RestToXContentListener<>(channel), content));

Follow-up for #116115

Closes ES-10140

@mhl-b mhl-b added v8.18.0 >enhancement :Distributed Coordination/Network Http and internode communication implementations Team:Distributed Coordination Meta label for Distributed Coordination team labels Nov 25, 2024
@elasticsearchmachine
Copy link
Collaborator

Hi @mhl-b, I've created a changelog YAML for you.

@mhl-b mhl-b marked this pull request as ready for review November 25, 2024 19:36
@mhl-b mhl-b requested review from a team as code owners November 25, 2024 19:36
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed-coordination (Team:Distributed Coordination)

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +61 to +64
return channel -> client.execute(
TransportPutStoredScriptAction.TYPE,
putRequest,
ActionListener.withRef(new RestToXContentListener<>(channel), content)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is ok but it looks like we only use org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest#content in order to validate its length, we should replace it with a number.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually it's still used in toString(), but not particularly usefully IMO, so I opened #117556 to remove that (and clean things up in this area too). Once that's backported to 8.18 we can safely replace this with a number in 9.0.

Comment on lines +70 to +73
return channel -> client.execute(
PutPipelineTransportAction.TYPE,
request,
ActionListener.withRef(new RestToXContentListener<>(channel), content)
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought this wasn't correct, it looked like we end up putting the source in the cluster state, so it seemed that we need to take a copy. But now that I look closer I see that org.elasticsearch.ingest.PipelineConfiguration#PipelineConfiguration(java.lang.String, org.elasticsearch.common.bytes.BytesReference, org.elasticsearch.xcontent.XContentType) parses the source to a map and stores that. So this seems ok to me.

@mhl-b mhl-b merged commit 1866299 into elastic:main Nov 26, 2024
17 checks passed
mhl-b added a commit to mhl-b/elasticsearch that referenced this pull request Nov 26, 2024
cbuescher pushed a commit to cbuescher/elasticsearch that referenced this pull request Nov 27, 2024
alexey-ivanov-es pushed a commit to alexey-ivanov-es/elasticsearch that referenced this pull request Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Network Http and internode communication implementations >enhancement Team:Distributed Coordination Meta label for Distributed Coordination team v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants