Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zstd decoder #948

Merged
merged 16 commits into from
Sep 15, 2021
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* [ENHANCEMENT] Include additional detail when searching for traces [#916](https://github.com/grafana/tempo/pull/916) (@zalegrala)
* [ENHANCEMENT] Add `gen index` and `gen bloom` commands to tempo-cli. [#903](https://github.com/grafana/tempo/pull/903) (@annanay25)
* [ENHANCEMENT] Implement trace comparison in Vulture [#904](https://github.com/grafana/tempo/pull/904) (@zalegrala)
* [ENHANCEMENT] Improve zstd read throughput using zstd.Decoder [#948](https://github.com/grafana/tempo/pull/948) (@joe-elliott)
* [ENHANCEMENT] Dedupe search records while replaying WAL [#940](https://github.com/grafana/tempo/pull/940) (@annanay25)
* [ENHANCEMENT] Add status endpoint to list the available endpoints [#938](https://github.com/grafana/tempo/pull/938) (@zalegrala)
* [CHANGE] Renamed CLI flag from `--storage.trace.maintenance-cycle` to `--storage.trace.blocklist_poll`. This is a **breaking change** [#897](https://github.com/grafana/tempo/pull/897) (@mritunjaysharma394)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/jaegertracing/jaeger v1.21.0
github.com/jedib0t/go-pretty/v6 v6.2.4
github.com/jsternberg/zap-logfmt v1.2.0
github.com/klauspost/compress v1.13.1
github.com/klauspost/compress v1.13.5
github.com/minio/minio-go/v7 v7.0.10
github.com/olekukonko/tablewriter v0.0.2
github.com/opentracing-contrib/go-grpc v0.0.0-20210225150812-73cb765af46e
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1261,8 +1261,9 @@ github.com/klauspost/compress v1.11.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYs
github.com/klauspost/compress v1.11.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.11.12/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.11.13/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.13.1 h1:wXr2uRxZTJXHLly6qhJabee5JqIhTRoLBhDOA74hDEQ=
github.com/klauspost/compress v1.13.1/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
github.com/klauspost/compress v1.13.5 h1:9O69jUPDcsT9fEm74W92rZL9FQY7rCdaXVneq+yyzl4=
github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s=
Expand Down
32 changes: 28 additions & 4 deletions tempodb/encoding/v2/data_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import (
tempo_io "github.com/grafana/tempo/pkg/io"
"github.com/grafana/tempo/tempodb/backend"
"github.com/grafana/tempo/tempodb/encoding/common"
"github.com/klauspost/compress/zstd"
)

type dataReader struct {
contextReader backend.ContextReader

pageBuffer []byte

encoding backend.Encoding
pool ReaderPool
compressedReader io.Reader
}
Expand All @@ -33,6 +35,7 @@ func NewDataReader(r backend.ContextReader, encoding backend.Encoding) (common.D
}

return &dataReader{
encoding: encoding,
contextReader: r,
pool: pool,
}, nil
Expand Down Expand Up @@ -105,7 +108,13 @@ func (r *dataReader) Read(ctx context.Context, records []common.Record, pagesBuf
return nil, nil, err
}

pagesBuffer[i], err = tempo_io.ReadAllWithBuffer(reader, len(page), pagesBuffer[i])
// zstd decoder is ~10-20% faster then the streaming io.Reader interface so prefer that
decoder, ok := reader.(*zstd.Decoder)
if ok {
pagesBuffer[i], err = decoder.DecodeAll(page, pagesBuffer[i][:0])
mdisibio marked this conversation as resolved.
Show resolved Hide resolved
} else {
pagesBuffer[i], err = tempo_io.ReadAllWithBuffer(reader, len(page), pagesBuffer[i])
}
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -138,7 +147,14 @@ func (r *dataReader) NextPage(buffer []byte) ([]byte, uint32, error) {
return nil, 0, err
}

buffer, err = tempo_io.ReadAllWithBuffer(compressedReader, len(page.data), buffer)
// zstd decoder is ~10-20% faster then the streaming io.Reader interface so prefer that
decoder, ok := compressedReader.(*zstd.Decoder)
if ok {
buffer, err = decoder.DecodeAll(page.data, buffer[:0])
} else {
buffer, err = tempo_io.ReadAllWithBuffer(compressedReader, len(page.data), buffer)
}

if err != nil {
return nil, 0, err
}
Expand All @@ -148,10 +164,18 @@ func (r *dataReader) NextPage(buffer []byte) ([]byte, uint32, error) {

func (r *dataReader) getCompressedReader(page []byte) (io.Reader, error) {
var err error
var reader io.Reader
// we are going to use the stateless zstd decoding functionality. if you pass
// a non-nil reader to .GetReader() and then use .DecodeAll() the process hangs
// for unknown reasons. so don't do that.
if r.encoding != backend.EncZstd {
reader = bytes.NewReader(page)
}

if r.compressedReader == nil {
r.compressedReader, err = r.pool.GetReader(bytes.NewReader(page))
r.compressedReader, err = r.pool.GetReader(reader)
} else {
r.compressedReader, err = r.pool.ResetReader(bytes.NewReader(page), r.compressedReader)
r.compressedReader, err = r.pool.ResetReader(reader, r.compressedReader)
}
return r.compressedReader, err
}
2 changes: 2 additions & 0 deletions vendor/github.com/klauspost/compress/.gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions vendor/github.com/klauspost/compress/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

137 changes: 137 additions & 0 deletions vendor/github.com/klauspost/compress/.goreleaser.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading