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

feat: support gzip & zstd compression #599

Merged
merged 3 commits into from
Nov 18, 2024
Merged

Conversation

kemingy
Copy link
Member

@kemingy kemingy commented Nov 17, 2024

@kemingy kemingy requested a review from lkevinzc November 17, 2024 16:26
@github-actions github-actions bot added the enhancement New feature or request label Nov 17, 2024
@kemingy
Copy link
Member Author

kemingy commented Nov 17, 2024

This passed the test, but I found that there is no "Content-Encoding" in the response headers during the test, while manually running a script can get the full headers as expected:

Headers({'server': 'mosec/0.8.9', 'content-type': 'application/json', 'vary': 'accept-encoding', 'content-encoding': 'gzip', 'transfer-encoding': 'chunked', 'date': 'Sun, 17 Nov 2024 16:29:58 GMT'})

mosec/args.py Outdated

parser.add_argument(
"--compression",
help="Enable Zstd & Gzip compression for the request body",
Copy link
Member

Choose a reason for hiding this comment

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

Zstd & Gzip are enabled together? They are two algorithms as I understand?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. The compression layer will choose the algorithm according to the request headers.

I enabled both since gzip is widely used (included in Python std) and zstd is currently the best. Users can choose the one that better suits their use cases.

Copy link
Member

Choose a reason for hiding this comment

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

Cool! Can we add an example (similar to the test script) and a pointer in README to make this feature more visible?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm still unsure what the best use case for compression is in model serving. Numpy vectors to bytes can benefit a little. Images that are using compression (JPEG) should not be applied again. @aseaday do you have suggestions?

Copy link

Choose a reason for hiding this comment

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

Numpy vectors can benefit a lot in our cases.
We had a feature image translator in our product immersivetranslate.
To fullfill image translator, there is a ML model pipeline: detection, recgonize and inpaint. It is also a common desgin for image OCR.
The variables between step in this pipeline are a msgpack format numpy data such as a image mask. A image mask is [3,1024,1024] array. Before compression, the file size will be 6MB, after compression, the filee size will be 2MB because of Sparsity

Signed-off-by: Keming <[email protected]>
@kemingy kemingy requested a review from lkevinzc November 18, 2024 12:12
Copy link
Member

@lkevinzc lkevinzc left a comment

Choose a reason for hiding this comment

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

LGTM, cool!

@kemingy kemingy merged commit 74f41f6 into mosecorg:main Nov 18, 2024
19 of 20 checks passed
@kemingy kemingy deleted the compression branch November 18, 2024 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Add compression encoding support
3 participants