Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compress/Encrypt Blocks in background using two channels #1232

Closed
wants to merge 24 commits into from

Conversation

jarifibrahim
Copy link
Contributor

@jarifibrahim jarifibrahim commented Feb 27, 2020

This PR provides an alternate implementation of #1227
This PR adds support for block compression/encryptions in the background.

NOTE: The additional overhead in the case of no_compression mode is because we write to a block buffer and write the content of the block buffer to the main builder buffer.

The following code was used for benchmarking (builder.go BenchmarkBuilder)

    bench := func(b *testing.B, opt *Options) {    
        // KeyCount * (keySize + ValSize)    
        b.SetBytes(int64(keysCount) * (32 + 32))    
        opt.BlockSize = 4 * 1024    
        opt.BloomFalsePositive = 0.01    
    
        //opt.TableSize = 5 << 20    
        b.ResetTimer()    
    
        for i := 0; i < b.N; i++ {    
            builder := NewTableBuilder(*opt)    
            for j := 0; j < keysCount; j++ {    
                builder.Add(keyList[j], vs, 0)    
            }    
            _ = builder.Finish()    
        }    
    }    
    
    b.Run("no compression", func(b *testing.B) {    
        var opt Options    
        opt.Compression = options.None    
        bench(b, &opt)    
    })    
    b.Run("encryption", func(b *testing.B) {    
        var opt Options    
        key := make([]byte, 32)    
        rand.Read(key)    
        opt.DataKey = &pb.DataKey{Data: key}    
        bench(b, &opt)    
    })    
    b.Run("zstd compression", func(b *testing.B) {    
        var opt Options    
        opt.Compression = options.ZSTD    
        b.Run("level 1", func(b *testing.B) {    
            opt.ZSTDCompressionLevel = 1    
            bench(b, &opt)
        })
        b.Run("level 3", func(b *testing.B) {
            opt.ZSTDCompressionLevel = 3
            bench(b, &opt)
        })
        b.Run("level 15", func(b *testing.B) {
            opt.ZSTDCompressionLevel = 15
            bench(b, &opt)
        })
    })

Master branch vs This Branch (new) Benchmarks.

benchstat master.txt twochannel.txt
name                                   old time/op    new time/op     delta (-ve is better. Reduction in time)
Builder1/no_compression-16                177ms ± 1%      203ms ± 1%   +14.76%  (p=0.008 n=5+5)
Builder1/encryption-16                    313ms ± 4%      265ms ± 3%   -15.35%  (p=0.008 n=5+5)
Builder1/zstd_compression/level_1-16      330ms ± 1%      273ms ± 2%   -17.21%  (p=0.008 n=5+5)
Builder1/zstd_compression/level_3-16      345ms ± 2%      276ms ± 3%   -20.19%  (p=0.008 n=5+5)
Builder1/zstd_compression/level_15-16     10.7s ± 1%       1.2s ± 2%   -89.00%  (p=0.008 n=5+5)

name                                   old speed      new speed       delta (+ve is better. Improvement in speed)
Builder1/no_compression-16              471MB/s ± 1%    411MB/s ± 1%   -12.86%  (p=0.008 n=5+5)
Builder1/encryption-16                  266MB/s ± 4%    314MB/s ± 3%   +18.12%  (p=0.008 n=5+5)
Builder1/zstd_compression/level_1-16    252MB/s ± 1%    305MB/s ± 2%   +20.80%  (p=0.008 n=5+5)
Builder1/zstd_compression/level_3-16    241MB/s ± 2%    302MB/s ± 3%   +25.34%  (p=0.008 n=5+5)
Builder1/zstd_compression/level_15-16  7.80MB/s ± 1%  70.89MB/s ± 2%  +808.87%  (p=0.008 n=5+5)



This change is Reviewable

@coveralls
Copy link

coveralls commented Feb 27, 2020

Coverage Status

Coverage increased (+0.3%) to 70.129% when pulling f6505bf on ibrahim/replace-b.buf-twochannels into 617ed7c on master.

@jarifibrahim jarifibrahim marked this pull request as ready for review March 2, 2020 08:59
@jarifibrahim
Copy link
Contributor Author

Closing this PR in favor of #1227. #1227 has better performance than this PR.

@jarifibrahim jarifibrahim deleted the ibrahim/replace-b.buf-twochannels branch March 6, 2020 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants