Skip to content

Core: Use Stream overload for reading response in HTTPClient#15648

Open
alpbeysir wants to merge 3 commits intoapache:mainfrom
alpbeysir:http-client-input-stream
Open

Core: Use Stream overload for reading response in HTTPClient#15648
alpbeysir wants to merge 3 commits intoapache:mainfrom
alpbeysir:http-client-input-stream

Conversation

@alpbeysir
Copy link

For tables with big metadata files loadTable was allocating a lot of char[]

image image

@github-actions github-actions bot added the core label Mar 16, 2026
@nastra nastra requested review from nastra March 16, 2026 12:03
@nastra
Copy link
Contributor

nastra commented Mar 16, 2026

@alpbeysir can you please share how the stacktrace + allocations look like with the fix?

@alpbeysir
Copy link
Author

@nastra yep here it is
CPU:
image
RAM:
image
Most time is now spent in jackson code. Allocations from HTTPClient take less total heap as well.

@alpbeysir alpbeysir marked this pull request as ready for review March 16, 2026 14:28
Copy link
Contributor

@nastra nastra left a comment

Choose a reason for hiding this comment

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

@danielcweeks or @amogh-jahagirdar can you guys also take a look at this please?

Copy link
Contributor

@singhpk234 singhpk234 left a comment

Choose a reason for hiding this comment

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

Nice find !

if (parserContext != null && !parserContext.isEmpty()) {
reader = reader.with(parserContext.toInjectableValues());
}
return reader.readValue(response.getEntity().getContent());
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like Jackson takes the responsibility here of closing the input stream internally (which is fine and expected). Just wanted to make sure this doesn't break any assumptions at the HTTPClient level around connection reuse but don't think it does , so I think this solution is strictly better!

}

if (responseBody == null) {
if (response.getEntity() == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure this is the right behavior? There are a number of valid return codes (e.g. 204) that I believe result in a null entity, but are valid.

I'm a little concerned that we're not properly handling all response codes.

Copy link
Author

Choose a reason for hiding this comment

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

I think before extractResponseBodyAsString(CloseableHttpResponse response) would also call getEntity() and do the same check so should be ok now

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

would fail here on main:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants