Skip to content

Commit

Permalink
fix(forwarder): introduce github.com/klauspost/pgzip (#325)
Browse files Browse the repository at this point in the history
We can improve read performance slightly by ensuring we decompress
GZIP'd objects in larger chunks.

Additionally, this commit fixes a bug whereby the reader was closed
before all data was read. This was a noop when using `compress/gzip`,
but caused deadlocks when replacing the package with `klauspost/pgzip`.
  • Loading branch information
jta authored Jul 29, 2024
1 parent 36b455a commit 8a19ab1
Show file tree
Hide file tree
Showing 34 changed files with 9,982 additions and 3 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.53.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGw
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/pgzip v1.2.6 h1:8RXeL5crjEUFnR2/Sn6GJNWtSQ3Dk8pq4CL3jvdDyjU=
github.com/klauspost/pgzip v1.2.6/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down
14 changes: 11 additions & 3 deletions pkg/handler/forwarder/s3http/internal/decoders/wrapper.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package decoders

import (
"compress/gzip"
"fmt"
"io"

gzip "github.com/klauspost/pgzip"
)

var wrappers = map[string]Wrapper{
Expand All @@ -21,7 +22,14 @@ func GzipWrapper(fn DecoderFactory) DecoderFactory {
if err != nil {
return &errorDecoder{fmt.Errorf("failed to read gzip: %w", err)}
}
defer gr.Close()
return fn(gr, params)

pr, pw := io.Pipe()
go func() {
defer gr.Close()
_, err := io.Copy(pw, gr)
pw.CloseWithError(err)
}()

return fn(pr, params)
}
}
304 changes: 304 additions & 0 deletions vendor/github.com/klauspost/compress/LICENSE

Large diffs are not rendered by default.

Loading

0 comments on commit 8a19ab1

Please sign in to comment.