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

web-server: add compression #2271

Open
syphar opened this issue Oct 14, 2023 · 7 comments
Open

web-server: add compression #2271

syphar opened this issue Oct 14, 2023 · 7 comments
Labels
A-backend Area: Webserver backend E-easy Effort: Should be easy to implement and would make a good first PR mentor This has instructions for getting started

Comments

@syphar
Copy link
Member

syphar commented Oct 14, 2023

In my mind, this could be solved via:

  • adding a reverse proxy to the container (NGINX, Caddy) and enabling compression
  • adding a compression middleware to axum

I assume axum is fine being exposed to the internet and doesn't need to be behind a reverse proxy (?).

Also in our current NGINX config: IP blocks, while it's unclear if we would handle this in AWS / CloudFront, or if we would have to handle this in our webserver (see rust-lang/simpleinfra#353)

@Nemo157
Copy link
Member

Nemo157 commented Oct 14, 2023

We'd also need to have TLS in the container if it is exposed to the internet, but I assume we're still having it only accessed by cloudfront over a private network so that shouldn't be necessary.

@syphar
Copy link
Member Author

syphar commented Oct 14, 2023

Yep, that's my thinking, our webservers would only be accessed through CloudFront, so we don't have to do TLS

@syphar
Copy link
Member Author

syphar commented Oct 14, 2023

And especially between the US & CF POPs in europe / asia compression definitely makes a difference

@syphar syphar added E-easy Effort: Should be easy to implement and would make a good first PR A-backend Area: Webserver backend labels Oct 14, 2023
@tverghis
Copy link

Hi! I'd like to take a stab at solving this by adding a compression layer to the middleware stack in the web server. If that's ok, I have a couple of questions:

  1. Can this compression middleware be applied to all routes served by the web server, or is there a reason to target specific routes?
  2. I'm planning on using tower_http::compression, which supports brotli, deflate, gzip or zstd. I don't know enough about this field to make a really educated decision on which one to choose. Does anyone have advice? I know that gzip is widely supported/used, and performs reasonably well. Should we start there?

@syphar
Copy link
Member Author

syphar commented Oct 17, 2023

Very good question!

  1. yes, all routes is fine
  2. yep, that's the middleware I also had in mind. gzip is fine, this will only compress between the webservers & the CDN. And adding more would probably add more dependencies to the project. You can just use the tower_http default

@syphar
Copy link
Member Author

syphar commented Oct 20, 2023

When using tower-http compression, see the comments / change here : rust-lang/crates.io#7330

@syphar
Copy link
Member Author

syphar commented Oct 24, 2023

Having read a little more about it I would say we should enable brotli, when easily possible.

We first would add this to our webserver, and then probably need to change CloudFront config to support this, or use it between the browser and the CDN POP.

@syphar syphar added the mentor This has instructions for getting started label Feb 14, 2024
@syphar syphar changed the title web-server dockerfile: add compression web-server: add compression Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-backend Area: Webserver backend E-easy Effort: Should be easy to implement and would make a good first PR mentor This has instructions for getting started
Projects
None yet
Development

No branches or pull requests

3 participants