nginx gzip
nginx gzip
The ngx_http_gzip_module module is a filter that compresses responses using the “gzip” method. This often helps to reduce the size of transmitted data by half or even more.
根据官网文档说明,通过开启nginx gzip压缩,数据传输量可以减少一半甚至更多。在网络带宽成为瓶颈的情况下,gzip带来的提升无疑是相当有诱惑力的。
未开启gzip:
1 | ./wrk -t10 -c200 -d30s http://120.25.176.131/testMysql |
惨不忍睹,基本上是把服务器压死了。
开启gzip:
按照官网示例,在nginx.conf添加下面的配置
1 | gzip on; |
压测结果
1 | ./wrk -t10 -c200 -d30s http://120.25.176.131/testMysql |
好吧,从压测结果来看,并没有什么明显的改善。。。没办法,这台服务器配置实在够差。
但是,通过chrome浏览器提供的调试工具,可以看到API的返回数据两压缩了6倍左右,从用户的角度来说就是接口响应变快了,用户体验当然更好。
| - | 数据长度 | Waiting(TTFB) | Content Download |
|---|---|---|---|
| 关闭gzip | 734KB | 20.67ms | 4.56s |
| 开启gzip | 229KB | 29.58ms | 699.19ms |
