mirror of
https://github.com/nanmu42/gzip.git
synced 2025-12-24 11:51:04 +08:00
doc: acknoledgement and performance correction
This commit is contained in:
@@ -91,7 +91,23 @@ handler := gzip.NewHandler(gzip.Config{
|
||||
|
||||
# 效率
|
||||
|
||||
本中间件经过了性能调优,以确保高效运行,[查看benchmark](https://github.com/nanmu42/gzip/blob/master/docs/benchmarks.md)。
|
||||
* 当返回体积不大时,Handler会智能地跳过压缩,这个过程带来的代价可以忽略不记;
|
||||
* 当返回体积足够大时,Handler会进行gzip压缩,这个过程有着合理的代价。
|
||||
|
||||
```
|
||||
$ go test -benchmem -bench .
|
||||
goos: linux
|
||||
goarch: amd64
|
||||
pkg: github.com/nanmu42/gzip
|
||||
BenchmarkSoleGin_SmallPayload-4 4104684 276 ns/op 64 B/op 2 allocs/op
|
||||
BenchmarkGinWithDefaultHandler_SmallPayload-4 1683307 707 ns/op 96 B/op 3 allocs/op
|
||||
BenchmarkSoleGin_BigPayload-4 4198786 274 ns/op 64 B/op 2 allocs/op
|
||||
BenchmarkGinWithDefaultHandler_BigPayload-4 44780 27636 ns/op 190 B/op 5 allocs/op
|
||||
PASS
|
||||
ok github.com/nanmu42/gzip 6.373s
|
||||
```
|
||||
|
||||
注:由于[一个笨拙的人为错误](https://github.com/nanmu42/gzip/pull/3#issuecomment-735352715),`v1.0.0`以及更早版本的评测指标是错误的,不具有参考意义。
|
||||
|
||||
# 局限性
|
||||
|
||||
@@ -111,6 +127,8 @@ API已经稳定,`1.x`版本中的更新会向前兼容。
|
||||
* https://blog.cloudflare.com/results-experimenting-brotli/
|
||||
* https://support.cloudflare.com/hc/en-us/articles/200168396-What-will-Cloudflare-compress-
|
||||
|
||||
本项目使用[klauspost的compress库](https://github.com/klauspost/compress)中的gzip压缩实现。
|
||||
|
||||
Logo在[Gopherize.me](https://gopherize.me/)生成。
|
||||
|
||||
# License
|
||||
|
||||
20
README.md
20
README.md
@@ -92,7 +92,23 @@ You may define one that specially suits your need.
|
||||
|
||||
# Performance
|
||||
|
||||
This middleware is fine-tuned so that little overhead is added to your program. See [benchmarks](https://github.com/nanmu42/gzip/blob/master/docs/benchmarks.md).
|
||||
* When response payload is small, the handler is smart enough to skip compression automatically, which takes neglectable overhead.
|
||||
* At the time when the payload is big enough, gzip kicks in and there is a reasonable price.
|
||||
|
||||
```
|
||||
$ go test -benchmem -bench .
|
||||
goos: linux
|
||||
goarch: amd64
|
||||
pkg: github.com/nanmu42/gzip
|
||||
BenchmarkSoleGin_SmallPayload-4 4104684 276 ns/op 64 B/op 2 allocs/op
|
||||
BenchmarkGinWithDefaultHandler_SmallPayload-4 1683307 707 ns/op 96 B/op 3 allocs/op
|
||||
BenchmarkSoleGin_BigPayload-4 4198786 274 ns/op 64 B/op 2 allocs/op
|
||||
BenchmarkGinWithDefaultHandler_BigPayload-4 44780 27636 ns/op 190 B/op 5 allocs/op
|
||||
PASS
|
||||
ok github.com/nanmu42/gzip 6.373s
|
||||
```
|
||||
|
||||
Note: due to [an awkward man-mistake](https://github.com/nanmu42/gzip/pull/3#issuecomment-735352715), benchmark of and before `v1.0.0` are not accurate.
|
||||
|
||||
# Limitation
|
||||
|
||||
@@ -112,6 +128,8 @@ During the development of this work, the author took following works/materials a
|
||||
* https://blog.cloudflare.com/results-experimenting-brotli/
|
||||
* https://support.cloudflare.com/hc/en-us/articles/200168396-What-will-Cloudflare-compress-
|
||||
|
||||
This package uses [klauspost's compress package](https://github.com/klauspost/compress) to handle gzip compression.
|
||||
|
||||
Logo generated at [Gopherize.me](https://gopherize.me/).
|
||||
|
||||
# License
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
# Command
|
||||
|
||||
All benchmarks were running on the same machine.
|
||||
|
||||
```bash
|
||||
go test -benchmem -cpuprofile cpu.prof -memprofile mem.prof -bench=.
|
||||
```
|
||||
|
||||
# v0.1.0
|
||||
|
||||
v0.1.0 gets things working.
|
||||
|
||||
go version go1.13.4 linux/amd64
|
||||
|
||||
```
|
||||
goos: linux
|
||||
goarch: amd64
|
||||
pkg: github.com/nanmu42/gzip
|
||||
BenchmarkSoleGin_SmallPayload-12 7222698 244 ns/op 64 B/op 2 allocs/op
|
||||
BenchmarkGinWithDefaultHandler_SmallPayload-12 1000000 1076 ns/op 224 B/op 6 allocs/op
|
||||
BenchmarkSoleGin_BigPayload-12 6688381 265 ns/op 64 B/op 2 allocs/op
|
||||
BenchmarkGinWithDefaultHandler_BigPayload-12 1000000 1063 ns/op 224 B/op 6 allocs/op
|
||||
PASS
|
||||
ok github.com/nanmu42/gzip 6.222s
|
||||
```
|
||||
|
||||
# v0.2.0
|
||||
|
||||
v0.2.0 uses ahocorasick in substring matching.
|
||||
|
||||
go version go1.13.4 linux/amd64
|
||||
|
||||
```
|
||||
goos: linux
|
||||
goarch: amd64
|
||||
pkg: github.com/nanmu42/gzip
|
||||
BenchmarkSoleGin_SmallPayload-12 6769252 182 ns/op 64 B/op 2 allocs/op
|
||||
BenchmarkGinWithDefaultHandler_SmallPayload-12 1410784 740 ns/op 224 B/op 6 allocs/op
|
||||
BenchmarkSoleGin_BigPayload-12 7300908 218 ns/op 64 B/op 2 allocs/op
|
||||
BenchmarkGinWithDefaultHandler_BigPayload-12 2312258 726 ns/op 224 B/op 6 allocs/op
|
||||
PASS
|
||||
ok github.com/nanmu42/gzip 7.428s
|
||||
```
|
||||
|
||||
# v0.3.0
|
||||
|
||||
v0.3.0 reuses writerWrapper to gain less allocations and GC pressure.
|
||||
|
||||
go version go1.13.4 linux/amd64
|
||||
|
||||
```
|
||||
goos: linux
|
||||
goarch: amd64
|
||||
pkg: github.com/nanmu42/gzip
|
||||
BenchmarkSoleGin_SmallPayload-12 7376715 194 ns/op 64 B/op 2 allocs/op
|
||||
BenchmarkGinWithDefaultHandler_SmallPayload-12 2475199 466 ns/op 96 B/op 3 allocs/op
|
||||
BenchmarkSoleGin_BigPayload-12 6572848 191 ns/op 64 B/op 2 allocs/op
|
||||
BenchmarkGinWithDefaultHandler_BigPayload-12 2991879 398 ns/op 96 B/op 3 allocs/op
|
||||
PASS
|
||||
ok github.com/nanmu42/gzip 6.425s
|
||||
```
|
||||
|
||||
# v0.4.0
|
||||
|
||||
v0.4.0 fixes panic on Gin's no route error.
|
||||
|
||||
# v0.5.0
|
||||
|
||||
v0.5.0 fixes panic on second calling to Write().
|
||||
|
||||
```
|
||||
goos: linux
|
||||
goarch: amd64
|
||||
pkg: github.com/nanmu42/gzip
|
||||
BenchmarkSoleGin_SmallPayload-12 7490284 201 ns/op 64 B/op 2 allocs/op
|
||||
BenchmarkGinWithDefaultHandler_SmallPayload-12 2292319 501 ns/op 96 B/op 3 allocs/op
|
||||
BenchmarkSoleGin_BigPayload-12 6403441 190 ns/op 64 B/op 2 allocs/op
|
||||
BenchmarkGinWithDefaultHandler_BigPayload-12 2951451 410 ns/op 96 B/op 3 allocs/op
|
||||
PASS
|
||||
ok github.com/nanmu42/gzip 6.620s
|
||||
```
|
||||
|
||||
# v0.6.0
|
||||
|
||||
v0.6.0 fixes wrong status code handling CORS OPTIONS request by gin's other middleware.
|
||||
|
||||
# v0.7.0
|
||||
|
||||
* writerWrapper: buffer writes to decide whether use gzip or not
|
||||
* writerWrapper: detect Content-Type if there's none
|
||||
* ginGzipWriter: full implementation for gin.ResponseWriter excluding Pusher()
|
||||
|
||||
|
||||
```
|
||||
goos: linux
|
||||
goarch: amd64
|
||||
pkg: github.com/nanmu42/gzip
|
||||
BenchmarkSoleGin_SmallPayload-12 7900057 184 ns/op 64 B/op 2 allocs/op
|
||||
BenchmarkGinWithDefaultHandler_SmallPayload-12 2171088 510 ns/op 96 B/op 3 allocs/op
|
||||
BenchmarkSoleGin_BigPayload-12 7402651 184 ns/op 64 B/op 2 allocs/op
|
||||
BenchmarkGinWithDefaultHandler_BigPayload-12 2911062 404 ns/op 96 B/op 3 allocs/op
|
||||
PASS
|
||||
ok github.com/nanmu42/gzip 6.634s
|
||||
```
|
||||
|
||||
# v0.8.0
|
||||
|
||||
v0.8.0 considers second(and furthermore) calls to writeWrapper's WriteHeader() valid
|
||||
Reference in New Issue
Block a user