Skip to content
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

Only create composite bytebufs if there is more than one incoming gRPC frame. #1167

Merged
merged 1 commit into from
Apr 30, 2018

Conversation

anuraaga
Copy link
Collaborator

@anuraaga anuraaga commented Apr 27, 2018

Currently, we use a CompositeByteBuf to collect incoming frames, and we read required bytes into another CompositeByteBuf as data is available. This causes a lot of overhead for the common case where the message fits in one frame. There also doesn't seem to be a good reason to read into a nextFrame as we get bytes, instead of when we have enough bytes (I had copied the pattern in this code pretty much verbatim from upstream without thinking too much about it).

Now, a CompositeByteBuf for incoming frames is only created on the second one. If the stream is finished with a single frame, no composites will ever be allocated. Also, incoming bytes are only read when we have enough bytes to deliver a message - this means we don't need to allocate a composite to keep track of read bytes pre-delivery.

After

# Run complete. Total time: 00:01:13

Benchmark                        (clientType)   Mode  Cnt      Score     Error  Units
DownstreamSimpleBenchmark.empty        NORMAL  thrpt   20  13314.558 ± 223.515  ops/s

Benchmark result is saved to /home/anuraag/git/armeria/benchmarks/build/reports/jmh/results.txt

Before

# Run complete. Total time: 00:01:13

Benchmark                        (clientType)   Mode  Cnt      Score     Error  Units
DownstreamSimpleBenchmark.empty        NORMAL  thrpt   20  12508.147 ± 180.084  ops/s

Benchmark result is saved to /home/anuraag/git/armeria/benchmarks/build/reports/jmh/results.txt
`

@codecov
Copy link

codecov bot commented Apr 27, 2018

Codecov Report

Merging #1167 into master will decrease coverage by 0.04%.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1167      +/-   ##
==========================================
- Coverage   72.72%   72.68%   -0.05%     
==========================================
  Files         517      517              
  Lines       23192    23203      +11     
  Branches     2898     2900       +2     
==========================================
- Hits        16866    16864       -2     
- Misses       4789     4797       +8     
- Partials     1537     1542       +5
Impacted Files Coverage Δ
.../armeria/internal/grpc/ArmeriaMessageDeframer.java 62.92% <50%> (-8.34%) ⬇️
...om/linecorp/armeria/client/HttpClientDelegate.java 77.77% <0%> (-2.23%) ⬇️
...corp/armeria/common/logging/DefaultRequestLog.java 79.94% <0%> (+0.25%) ⬆️
...com/linecorp/armeria/server/HttpServerHandler.java 77.77% <0%> (+1.04%) ⬆️
...p/armeria/common/stream/DeferredStreamMessage.java 87.06% <0%> (+1.72%) ⬆️
...linecorp/armeria/internal/Http2GoAwayListener.java 80% <0%> (+4%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4be1bf5...f45da34. Read the comment docs.

@trustin trustin merged commit c51d05f into line:master Apr 30, 2018
@trustin
Copy link
Member

trustin commented Apr 30, 2018

Thanks, @anuraaga!

trustin pushed a commit that referenced this pull request Oct 18, 2018
Actually, `firstFrame` was never set because I forgot to remove line 197 >< I guess the optimization previously in #1167 was just from the removal of `nextFrame`.

I tried finishing the `firstFrame` optimization but there was no difference so just getting rid of it.
fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this pull request Sep 19, 2020
…me. (line#1167)

Currently, we use a `CompositeByteBuf` to collect incoming frames, and we read required bytes into another `CompositeByteBuf` as data is available. This causes a lot of overhead for the common case where the message fits in one frame. There also doesn't seem to be a good reason to read into a `nextFrame` as we get bytes, instead of when we have enough bytes (I had copied the pattern in this code pretty much verbatim from upstream without thinking too much about it).

Now, a `CompositeByteBuf` for incoming frames is only created on the second one. If the stream is finished with a single frame, no composites will ever be allocated. Also, incoming bytes are only read when we have enough bytes to deliver a message - this means we don't need to allocate a composite to keep track of read bytes pre-delivery.

After
```
# Run complete. Total time: 00:01:13

Benchmark                        (clientType)   Mode  Cnt      Score     Error  Units
DownstreamSimpleBenchmark.empty        NORMAL  thrpt   20  13314.558 ± 223.515  ops/s

Benchmark result is saved to /home/anuraag/git/armeria/benchmarks/build/reports/jmh/results.txt
```

Before
```
# Run complete. Total time: 00:01:13

Benchmark                        (clientType)   Mode  Cnt      Score     Error  Units
DownstreamSimpleBenchmark.empty        NORMAL  thrpt   20  12508.147 ± 180.084  ops/s

Benchmark result is saved to /home/anuraag/git/armeria/benchmarks/build/reports/jmh/results.txt
```
fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this pull request Sep 19, 2020
Actually, `firstFrame` was never set because I forgot to remove line 197 >< I guess the optimization previously in line#1167 was just from the removal of `nextFrame`.

I tried finishing the `firstFrame` optimization but there was no difference so just getting rid of it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants