0

I enabled gzip on my nginx reverse proxy which is hosted on EC2 free tier (so lightweight server). I noticed that my request latency increased by almost 2x (13+KB compressed to 4+KB). The only issue that I can think of is that the compression on the server is taking a long time for large payloads which is why overall latency is worse, but 1.) I'm not really sure how to verify this and 2.) tuning the parameters seems to have no effect (compression level and # of buffers). Lastly, there isn't a noticeable change in CPU util for my host.

Here is my server block:

server {
    # ....

    gzip on;
    gzip_types text/plain application/xml application/json;
    gzip_comp_level 3;
    gzip_proxied no-cache no-store private expired auth;
    gzip_buffers 2048 4k; # unsure about effect here
    gzip_min_length 1024;


    location / {
        proxy_pass http://localhost:8080;
    }

Does anyone have any pointers on this issue?

Stuart
  • 1
  • 1
  • Do you have anything more specific which makes you believe it's compression? Did you try tuning compression off? Did you do any form of profiling or at least monitoring? Even basics like cpu/memory usage may help. – rvs Jun 23 '22 at 16:35
  • Yeah, turning compression off latency was ~7 seconds for one HTTP request. after turning it on it is 14+ seconds. – Stuart Jun 23 '22 at 17:05
  • CPU util on the host remained relatively unchanged – Stuart Jun 23 '22 at 17:06
  • what does page insight is telling? – djdomi Jun 23 '22 at 17:11
  • Lighthouse performance score went from 57 to 30, I assume this is the same as page insight – Stuart Jun 23 '22 at 17:52
  • I just tested gzip vs non gzip on a different API that transfers half the size and the performance WITH gzip was faster. so I guess its because the payload is so large – Stuart Jun 23 '22 at 18:51
  • Not sure what the solution is here, it feels kind of risky to make the gzip buffer # much higher, no? – Stuart Jun 23 '22 at 18:56
  • @Stuart wait, 7 _seconds_? No way gzip has this sort of impact. Look into what is the actual bottleneck. I suspect you are out of memory and everything is swapping. Do some basic monitoring. – rvs Jun 27 '22 at 09:11
  • yeah the 7-second difference was a mistake in my benchmarking, the main bottleneck I found out was somewhere else on the BE. In the end, I fixed that bottleneck and compressed res payload in the BE code instead of on the nginx server, which gave the best results. Thanks for help – Stuart Jun 28 '22 at 21:56

0 Answers0