Skip to content

Commit

Permalink
Fix: the concurrent number of zstd encoders in k8s container and supp…
Browse files Browse the repository at this point in the history
…ort zstd configuration re-initialization(kubevela#92)
  • Loading branch information
hanzhaoyang committed Feb 23, 2024
1 parent 325c22e commit 7c6365a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
22 changes: 22 additions & 0 deletions util/compression/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package compression

import (
_ "go.uber.org/automaxprocs"

"github.com/spf13/pflag"
"runtime"
)

var (
EncoderLevel = 2
EnCoderConcurrent = runtime.GOMAXPROCS(0)
)

func AddFlags(fs *pflag.FlagSet) {
AddZStdEncoderFlags(fs)
}

func AddZStdEncoderFlags(fs *pflag.FlagSet) {
fs.IntVar(&EncoderLevel, "zstd-encoder-level", EncoderLevel, "specifies a predefined compression level")
fs.IntVar(&EnCoderConcurrent, "zstd-encoder-concurrent", EnCoderConcurrent, "set the concurrency, meaning the maximum number of encoders to run concurrently")
}
11 changes: 11 additions & 0 deletions util/compression/flags_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package compression

import (
"testing"

"github.com/spf13/pflag"
)

func TestFlags(t *testing.T) {
AddFlags(pflag.NewFlagSet("test", pflag.PanicOnError))
}
7 changes: 7 additions & 0 deletions util/compression/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,10 @@ func init() {
c.init()
}
}

func Reinitialize() {
// reinitialize compressors
for _, c := range compressors {
c.init()
}
}
4 changes: 3 additions & 1 deletion util/compression/zstd.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ func (c *zstdCompressor) init() {
// no compression: 38826717 ns 1.00x
// gzip: 94855264 ns 2.44x
// zstd: 48524197 ns 1.25x
zstd.WithEncoderLevel(zstd.SpeedDefault),
zstd.WithEncoderLevel(zstd.EncoderLevel(EncoderLevel)),

zstd.WithEncoderConcurrency(EnCoderConcurrent),
// TODO(charlie0129): give a dictionary to compressor to get even more improvements.
//
// Since we are dealing with highly-specialized small JSON data, a dictionary will
Expand Down

0 comments on commit 7c6365a

Please sign in to comment.