-
Notifications
You must be signed in to change notification settings - Fork 184
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
Optimize HTTP messages with empty payload body #1479
Conversation
Motivation: In many cases users do not set payload body when they create an HTTP request (like `GET`) or response (like, 204). We can optimize flush strategy and HTTP/1.1 encoding in these cases. Modification: - Introduce `PayloadInfo#isEmpty()` flag that tells internal layers when an HTTP message contains payload body; - Use this flag to choose flush strategy and set `content-length` header; - Adjust existing `content-length` tests to verify new use-cases with empty payload body; - Enhance existing `FlushStrategyOnServerTest` to verify empty responses flush on end; Result: Less flushes + non-chunked HTTP/1.1 encoding when there is no payload body results in better performance for these use-cases.
… new `Buffer` instead of using `EMPTY_BUFFER`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a quite worthwhile improvement!
servicetalk-http-api/src/main/java/io/servicetalk/http/api/HttpApiConversions.java
Show resolved
Hide resolved
* Returns {@code true} if and only if, the payload body {@link Publisher} was never assigned, changed, or modified, | ||
* and therefore remains empty. | ||
* | ||
* @return {@code true} if and only if, the payload body {@link Publisher} was never assigned, changed, or modified |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be result for an explicitly empty payload such as empty String or empty byte array?
I am thinking of the case were app has their own empty payload response and they use it as the payload for a response they intend to be empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, in order to support this use-case, we can not apply the optimization in the scenarios you highlighted, because users can expand it later. If in future we will agree to drop support for this way, we will be able to optimize any empty payload body.
However, if users set a read-only empty buffer, we can support it. Fixed: 69e962f
Motivation:
In many cases users do not set payload body when they create an HTTP
request (like
GET
) or response (like, 204). We can optimize flushstrategy and HTTP/1.1 encoding in these cases.
Modifications:
PayloadInfo#isEmpty()
flag that tells internal layers whenan HTTP message contains payload body;
content-length
header;content-length
tests to verify new use-cases withempty payload body;
FlushStrategyOnServerTest
to verify empty responsesflush on end;
Behavior changes:
Buffer
of newrequest/response objects after types conversion:
encoded with
content-length: 0
instead oftransfer-encoding: chunked
;Result:
Less flushes + non-chunked HTTP/1.1 encoding when there is no payload body
results in better throughput (+30% RPS) for these use-cases, latency improves
by ~15%.