mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-21 15:45:01 +00:00
lib/encoding: add vm_zstd_block_{original|compressed}_bytes_total
metrics for rough estimation of block compression ratio
This commit is contained in:
parent
f67f40d63a
commit
b23352dc9e
1 changed files with 11 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
package encoding
|
package encoding
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/VictoriaMetrics/metrics"
|
||||||
"github.com/valyala/gozstd"
|
"github.com/valyala/gozstd"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,7 +10,11 @@ import (
|
||||||
//
|
//
|
||||||
// The given compressLevel is used for the compression.
|
// The given compressLevel is used for the compression.
|
||||||
func CompressZSTDLevel(dst, src []byte, compressLevel int) []byte {
|
func CompressZSTDLevel(dst, src []byte, compressLevel int) []byte {
|
||||||
return gozstd.CompressLevel(dst, src, compressLevel)
|
originalBytes.Add(len(src))
|
||||||
|
dstLen := len(dst)
|
||||||
|
dst = gozstd.CompressLevel(dst, src, compressLevel)
|
||||||
|
compressedBytes.Add(len(dst) - dstLen)
|
||||||
|
return dst
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecompressZSTD decompresses src, appends the result to dst and returns
|
// DecompressZSTD decompresses src, appends the result to dst and returns
|
||||||
|
@ -17,3 +22,8 @@ func CompressZSTDLevel(dst, src []byte, compressLevel int) []byte {
|
||||||
func DecompressZSTD(dst, src []byte) ([]byte, error) {
|
func DecompressZSTD(dst, src []byte) ([]byte, error) {
|
||||||
return gozstd.Decompress(dst, src)
|
return gozstd.Decompress(dst, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
originalBytes = metrics.NewCounter(`vm_zstd_block_original_bytes_total`)
|
||||||
|
compressedBytes = metrics.NewCounter(`vm_zstd_block_compressed_bytes_total`)
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue