Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #190 from libp2p/zstd
Browse files Browse the repository at this point in the history
switch from gzip to zstd for qlog compression
  • Loading branch information
marten-seemann authored Jan 21, 2021
2 parents 0b4a78f + 4fd6c4e commit 0c7a9fb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.14
require (
github.com/golang/mock v1.4.4
github.com/ipfs/go-log v1.0.4
github.com/klauspost/compress v1.11.7
github.com/libp2p/go-libp2p-core v0.8.0
github.com/libp2p/go-libp2p-tls v0.1.3
github.com/libp2p/go-netroute v0.1.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/klauspost/compress v1.11.7 h1:0hzRabrMN4tSTvMfnL3SCv1ZGeAP23ynzodBgaHeMeg=
github.com/klauspost/compress v1.11.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down
13 changes: 9 additions & 4 deletions tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package libp2pquic

import (
"bufio"
"compress/gzip"
"fmt"
"io"
"os"
"time"

"github.com/klauspost/compress/zstd"

"github.com/lucas-clemente/quic-go/logging"
"github.com/lucas-clemente/quic-go/metrics"
"github.com/lucas-clemente/quic-go/qlog"
Expand Down Expand Up @@ -48,14 +49,18 @@ func newQlogger(qlogDir string, role logging.Perspective, connID []byte) io.Writ
if role == logging.PerspectiveClient {
r = "client"
}
finalFilename := fmt.Sprintf("%s%clog_%s_%s_%x.qlog.gz", qlogDir, os.PathSeparator, t, r, connID)
filename := fmt.Sprintf("%s%c.log_%s_%s_%x.qlog.gz.swp", qlogDir, os.PathSeparator, t, r, connID)
finalFilename := fmt.Sprintf("%s%clog_%s_%s_%x.qlog.zst", qlogDir, os.PathSeparator, t, r, connID)
filename := fmt.Sprintf("%s%c.log_%s_%s_%x.qlog.zst.swp", qlogDir, os.PathSeparator, t, r, connID)
f, err := os.Create(filename)
if err != nil {
log.Errorf("unable to create qlog file %s: %s", filename, err)
return nil
}
gz := gzip.NewWriter(f)
gz, err := zstd.NewWriter(f, zstd.WithEncoderLevel(zstd.SpeedFastest))
if err != nil {
log.Errorf("failed to initialize zstd: %s", err)
return nil
}
return &qlogger{
f: f,
filename: finalFilename,
Expand Down
9 changes: 5 additions & 4 deletions tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package libp2pquic

import (
"bytes"
"compress/gzip"
"fmt"
"io/ioutil"
"os"

"github.com/klauspost/compress/zstd"

"github.com/lucas-clemente/quic-go/logging"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -43,12 +44,12 @@ var _ = Describe("qlogger", func() {
logger := newQlogger(qlogDir, logging.PerspectiveServer, []byte{0xde, 0xad, 0xbe, 0xef})
file := getFile()
Expect(string(file.Name()[0])).To(Equal("."))
Expect(file.Name()).To(HaveSuffix(".qlog.gz.swp"))
Expect(file.Name()).To(HaveSuffix(".qlog.zst.swp"))
// close the logger. This should move the file.
Expect(logger.Close()).To(Succeed())
file = getFile()
Expect(string(file.Name()[0])).ToNot(Equal("."))
Expect(file.Name()).To(HaveSuffix(".qlog.gz"))
Expect(file.Name()).To(HaveSuffix(".qlog.zst"))
Expect(file.Name()).To(And(
ContainSubstring("server"),
ContainSubstring("deadbeef"),
Expand Down Expand Up @@ -76,7 +77,7 @@ var _ = Describe("qlogger", func() {
compressed, err := ioutil.ReadFile(qlogDir + "/" + getFile().Name())
Expect(err).ToNot(HaveOccurred())
Expect(compressed).ToNot(Equal("foobar"))
gz, err := gzip.NewReader(bytes.NewReader(compressed))
gz, err := zstd.NewReader(bytes.NewReader(compressed))
Expect(err).ToNot(HaveOccurred())
data, err := ioutil.ReadAll(gz)
Expect(err).ToNot(HaveOccurred())
Expand Down

0 comments on commit 0c7a9fb

Please sign in to comment.