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

Fix compression for deferred responses #2986

Merged
merged 17 commits into from
Apr 27, 2023
Merged

Fix compression for deferred responses #2986

merged 17 commits into from
Apr 27, 2023

Conversation

Geal
Copy link
Contributor

@Geal Geal commented Apr 24, 2023

Fix #1572

We replace tower-http's CompressionLayer with a custom stram transformation. This is necessary becauyse tower-http uses async-compression, which buffers data until the end of the stream to then write it, ensuring a better compression. This is incompatible with defer's multipart protocol, which requires chunks to be sent as soon as possible. So we need to compress them independently.

This extracts parts of the codec module of async-compression, which so far is not public, and makes the streaming wrapper above it. Most of the PR is made from that code, the interesting parts are in apollo-router/src/axum_factory/axum_http_server_factory.rs and apollo-router/src/axum_factory/compression/mod.rs

Checklist

Complete the checklist (and note appropriate exceptions) before a final PR is raised.

  • Changes are compatible[^1]
  • Documentation[^2] completed
  • Performance impact assessed and acceptable
  • Tests added and passing[^3]
    • Unit Tests
    • Integration Tests
    • Manual Tests

Exceptions

Note any exceptions here

Notes

[^1]. It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this.
[^2]. Configuration is an important part of many changes. Where applicable please try to document configuration examples.
[^3]. Tick whichever testing boxes are applicable. If you are adding Manual Tests:
- please document the manual testing (extensively) in the Exceptions.
- please raise a separate issue to automate the test and label it (or ask for it to be labeled) as manual test

so this will be measured by CI benchmarks and serve as baseline for
upcoming changes
@github-actions

This comment has been minimized.

This integrates the encoders from
https://github.com/Nemo157/async-compression so we can use them other a
stream that flushes data regularly
this makes an assumption that async-commpression cannot make: every
chunk in the body stream has to be compressed and flushed directly, we
should not wait for more data to come and get better compression.
This is due to the multipart protocol for defer: we know each chunk
represent eitehr the primary or a deferred response, and should be sent
as soon as possible
@Geal Geal marked this pull request as ready for review April 24, 2023 16:47
Geal and others added 3 commits April 26, 2023 15:08
@Geal Geal enabled auto-merge April 27, 2023 09:19
@Geal Geal merged commit 56f121e into dev Apr 27, 2023
@Geal Geal deleted the geal/fix-defer-compression branch April 27, 2023 09:29
This was referenced May 3, 2023
abernix pushed a commit that referenced this pull request May 5, 2023
1.17.0 sometimes panicked when doing gzip response encoding. The write
head for the buffer was being extended by the total amount written so
far (instead of the amount written by the current iteration).

Rather than just remove the `+` in `written += ...` I thought it would
be more ergonomic to add the required method to the `PartialBuffer`.

Co-authored-by: Dylan Anthony <dbanty@users.noreply.github.com>
Co-authored-by: Jesse Rosenberger <git@jro.cc>
Co-authored-by: Geoffroy Couprie <apollo@geoffroycouprie.com>

Ref: #2986
garypen pushed a commit that referenced this pull request May 10, 2023
1.17.0 sometimes panicked when doing gzip response encoding. The write
head for the buffer was being extended by the total amount written so
far (instead of the amount written by the current iteration).

Rather than just remove the `+` in `written += ...` I thought it would
be more ergonomic to add the required method to the `PartialBuffer`.

Co-authored-by: Dylan Anthony <dbanty@users.noreply.github.com>
Co-authored-by: Jesse Rosenberger <git@jro.cc>
Co-authored-by: Geoffroy Couprie <apollo@geoffroycouprie.com>

Ref: #2986
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deferred responses should be compressed
3 participants