Skip to content

Commit

Permalink
connect: Use klauspost/compress/gzip decompression (#3314)
Browse files Browse the repository at this point in the history
* Fix missing parameter in makefile

* connect: Use klauspost/compress/gzip decompression

At the same time this make sures that all handlers and clients use the
same compressor pool. Otherwise every new handler and client maintains
its own pool.
  • Loading branch information
simonswine authored May 24, 2024
1 parent 53f7de2 commit cf55c09
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ docker-image/pyroscope/build: frontend/build go/bin
docker-image/pyroscope/push: GOOS=linux
docker-image/pyroscope/push: GOARCH=amd64
docker-image/pyroscope/push: frontend/build go/bin
$(call docker_buildx,--push)
$(call docker_buildx,--push,)

define UPDATER_CONFIG_JSON
{
Expand Down
33 changes: 33 additions & 0 deletions pkg/api/connect/compression.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package connectapi

import (
"io"

"connectrpc.com/connect"
"github.com/klauspost/compress/gzip"
)

const (
compressionGzip = "gzip"
)

var (
gzipPoolHandler = connect.WithCompression(
compressionGzip,
func() connect.Decompressor { return &gzip.Reader{} },
func() connect.Compressor { return gzip.NewWriter(io.Discard) },
)
gzipPoolClient = connect.WithAcceptCompression(
compressionGzip,
func() connect.Decompressor { return &gzip.Reader{} },
func() connect.Compressor { return gzip.NewWriter(io.Discard) },
)
)

func WithGzipHandler() connect.HandlerOption {
return gzipPoolHandler
}

func WithGzipClient() connect.ClientOption {
return gzipPoolClient
}
2 changes: 2 additions & 0 deletions pkg/api/connect/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
func DefaultClientOptions() []connect.ClientOption {
return []connect.ClientOption{
connect.WithCodec(ProtoCodec),
WithGzipClient(),
}
}

func DefaultHandlerOptions() []connect.HandlerOption {
return []connect.HandlerOption{
connect.WithCodec(ProtoCodec),
WithGzipHandler(),
}
}

0 comments on commit cf55c09

Please sign in to comment.