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

Automatically gzip large responses #1661

Open
jaulz opened this issue Oct 11, 2023 · 5 comments
Open

Automatically gzip large responses #1661

jaulz opened this issue Oct 11, 2023 · 5 comments

Comments

@jaulz
Copy link

jaulz commented Oct 11, 2023

I wonder if Bref could automatically try to gzip the response if it's bigger than the 6MB limit. I gave it a try and at least this approach works for me (removed the Vapor header):
https://bannister.me/blog/gzip-compression-on-laravel-vapor/

Since it's already possible via (Laravel) middleware, it's not urgent but maybe a nice addition.

@mnapoli
Copy link
Member

mnapoli commented Oct 11, 2023

Hey @jaulz, that is interesting! Do you have any numbers on bigger payloads that you are able to return that way?

@jaulz
Copy link
Author

jaulz commented Oct 12, 2023

Yeah, for the one critical response I was dealing with it's a factor of 24 (from 8MB of text to 300KB):
image

I used this code:

      $content = $response->getContent();
      $compressedContent = gzencode($content, 9);

      $response->setContent($compressedContent);
      $response->headers->add([
        'Content-Encoding' => 'gzip',
        'X-Original-Size' => mb_strlen($content, '8bit'),
        'X-Compressed-Size' => mb_strlen($compressedContent, '8bit'),
      ]);

@kevincerro
Copy link
Contributor

kevincerro commented Oct 24, 2023

Now AWS supports response streaming to bypass 6MB limit

  • additional cost if you pass 6MB and with a soft limit of 20MB (maybe ampliable on request)

Its supported on NodeJS official runtime but AWS allows to support on custom runtimes too.

Maybe this will be interesting also in combination with gzip encoding, because GZIP works great on text responses but on binary responses maybe not

https://aws.amazon.com/es/blogs/compute/introducing-aws-lambda-response-streaming/
https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html

@kevincerro
Copy link
Contributor

In my case from 87,6kB to 5,8kB on a simple SF project using GZIP

Captura de pantalla 2023-10-24 a las 14 11 49

@mnapoli
Copy link
Member

mnapoli commented Oct 24, 2023

@kevincerro FYI #1503

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

No branches or pull requests

3 participants