Skip to content

Commit

Permalink
gzip: change compression level to the default
Browse files Browse the repository at this point in the history
We want the middle ground between a small compression size, a fast
compression time and a fast decompression time.

Tests suggest that the default compression level is better than the
maximum compression level: although the reports are 4% bigger and
decompress slower, they compress 33% faster.

See discussion on #1457 (comment)
  • Loading branch information
alban committed Apr 12, 2017
1 parent 7c22c97 commit a8af81f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func RegisterReportPostHandler(a Adder, router *mux.Router) {
// a.Add(..., buf) assumes buf is gzip'd msgpack
if !isMsgpack {
buf = bytes.Buffer{}
rpt.WriteBinary(&buf, gzip.BestCompression)
rpt.WriteBinary(&buf, gzip.DefaultCompression)
}

if err := a.Add(ctx, rpt, buf.Bytes()); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion probe/appclient/report_publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ func (p *ReportPublisher) Publish(r report.Report) error {
})
}
buf := &bytes.Buffer{}
r.WriteBinary(buf, gzip.BestCompression)
r.WriteBinary(buf, gzip.DefaultCompression)
return p.publisher.Publish(buf)
}
4 changes: 2 additions & 2 deletions report/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestRoundtrip(t *testing.T) {
var buf bytes.Buffer
r1 := report.MakeReport()
r1.WriteBinary(&buf, gzip.BestCompression)
r1.WriteBinary(&buf, gzip.DefaultCompression)
bytes := append([]byte{}, buf.Bytes()...) // copy the contents for later
r2, err := report.MakeFromBinary(&buf)
if err != nil {
Expand Down Expand Up @@ -49,7 +49,7 @@ func TestMoreCompressionMeansSmaller(t *testing.T) {
// Make sure that 0 level compression actually does compress less.
var buf1, buf2 bytes.Buffer
r := report.MakeReport()
r.WriteBinary(&buf1, gzip.BestCompression)
r.WriteBinary(&buf1, gzip.DefaultCompression)
r.WriteBinary(&buf2, 0)
if buf1.Len() >= buf2.Len() {
t.Errorf("Compression doesn't change size: %v >= %v", buf1.Len(), buf2.Len())
Expand Down

0 comments on commit a8af81f

Please sign in to comment.