Commit 7e740c8d authored by Michael de Hoog's avatar Michael de Hoog

Use target size instead of max size, and add target frame count

parent f3f77875
...@@ -102,7 +102,8 @@ func (cc *ChannelConfig) NewCompressor() (derive.Compressor, error) { ...@@ -102,7 +102,8 @@ func (cc *ChannelConfig) NewCompressor() (derive.Compressor, error) {
switch cc.CompressorKind { switch cc.CompressorKind {
case flags.CompressorShadow: case flags.CompressorShadow:
return NewShadowCompressor( return NewShadowCompressor(
cc.MaxFrameSize, cc.TargetFrameSize,
cc.TargetNumFrames,
) )
default: default:
return NewTargetSizeCompressor( return NewTargetSizeCompressor(
......
...@@ -8,8 +8,14 @@ import ( ...@@ -8,8 +8,14 @@ import (
) )
type ShadowCompressor struct { type ShadowCompressor struct {
// The maximum byte-size a frame can have. // The frame size to target when creating channel frames. When adding new
MaxFrameSize uint64 // data to the shadow compressor causes the buffer size to be greater than
// the target size, the compressor is marked as full.
TargetFrameSize uint64
// The target number of frames to create in this channel. If the realized
// compression ratio is worse than approxComprRatio, additional leftover
// frame(s) might get created.
TargetNumFrames int
buf bytes.Buffer buf bytes.Buffer
compress *zlib.Writer compress *zlib.Writer
...@@ -20,9 +26,10 @@ type ShadowCompressor struct { ...@@ -20,9 +26,10 @@ type ShadowCompressor struct {
fullErr error fullErr error
} }
func NewShadowCompressor(maxFrameSize uint64) (derive.Compressor, error) { func NewShadowCompressor(targetFrameSize uint64, targetNumFrames int) (derive.Compressor, error) {
c := &ShadowCompressor{ c := &ShadowCompressor{
MaxFrameSize: maxFrameSize, TargetFrameSize: targetFrameSize,
TargetNumFrames: targetNumFrames,
} }
var err error var err error
...@@ -48,7 +55,7 @@ func (t *ShadowCompressor) Write(p []byte) (int, error) { ...@@ -48,7 +55,7 @@ func (t *ShadowCompressor) Write(p []byte) (int, error) {
if err != nil { if err != nil {
return 0, err return 0, err
} }
if uint64(t.shadowBuf.Len()) > t.MaxFrameSize { if uint64(t.shadowBuf.Len()) > t.TargetFrameSize*uint64(t.TargetNumFrames) {
t.fullErr = derive.CompressorFullErr t.fullErr = derive.CompressorFullErr
return 0, t.fullErr return 0, t.fullErr
} }
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
) )
type TargetSizeCompressor struct { type TargetSizeCompressor struct {
// The target number of frames to create per channel. Note that if the // The frame size to target when creating channel frames. Note that if the
// realized compression ratio is worse than the approximate, more frames may // realized compression ratio is worse than the approximate, more frames may
// actually be created. This also depends on how close TargetFrameSize is to // actually be created. This also depends on how close TargetFrameSize is to
// MaxFrameSize. // MaxFrameSize.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment