Should I use Jetty's or NGINX's gzip capab

2019-08-25 02:46发布

问题:

I am running a Jetty-based Web Service behind an NGINX reverse proxy. Both Jetty and NGINX can handle the gzip compression/decompression for responses and requests. The typical payload is JSON, ranging from a few kilobytes up to tens of megabytes. Especially for larger payloads, the compression significantly impacts overall throughput.

What would be the most efficient point to handle the compression part - the JAVA service (Jetty) or the proxy (NGINX) if both sit on the same server?

Since NGINX uses a C-based gzip library, which is a lot more efficient and faster than JAVA's internal gzip, I would assume that NGINX should do the job. On the other hand, transferring bigger volumes of data between Jetty and NGINX has its own overhead. So I am not sure that the obvious choice is correct.

回答1:

The only way to be sure would be to measure. However, I've done the same thing with .NET Core and Nginx and in that case compressing the JSON in Nginx was more efficient. Microsoft says as much.

Use server-based response compression technologies in IIS, Apache, or Nginx. The performance of the middleware probably won't match that of the server modules

I would assume that the same holds for Java/Jetty and Nginx.