tirkarthi commented on code in PR #43707:
URL: https://github.com/apache/airflow/pull/43707#discussion_r1830963980
##########
airflow/api_fastapi/core_api/app.py:
##########
@@ -113,4 +114,5 @@ def init_config(app: FastAPI) -> None:
allow_headers=allow_headers,
)
+ app.add_middleware(GZipMiddleware, minimum_size=1000, compresslevel=5)
Review Comment:
Thanks, added a comment. I got 1000 value from the fastapi docs. I feel
values between 1kB to 4kB are good enough since users won't have much benefit
from compressing responses less than 1kB to becomes bytes. compression level of
5 felt like middle ground between levels 1 and 9 to compress it at optimal size
without taking too much time.
compression takes effect only when http clients send `Accept-Encoding: gzip`
which Firefox and probably Chrome too does automatically with `Accept-Encoding:
gzip, deflate, br, zstd` . Brotli and zstd are better implementations in terms
of speed of compression/decompression and size but they don't have inbuilt
support in fastapi/starlette requiring third party packages. Some numbers
comparing time and size for different levels as below. I couldn't measure CPU
overhead but I guess it will be minimal and worth it compared to savings in
size and download time especially with endpoints like logs once they get added.
We are using flask-compress in production with `airflow webserver` for couple
of years and didn't notice any issues related to CPU/memory.
https://paulcalvano.com/2024-03-19-choosing-between-gzip-brotli-and-zstandard-compression/
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]