forked from go-bond/bond
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
78 lines (62 loc) · 1.93 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package bond
import (
"runtime"
"time"
"github.com/cockroachdb/pebble"
"github.com/cockroachdb/pebble/bloom"
"github.com/cockroachdb/pebble/vfs"
"github.com/go-bond/bond/serializers"
)
const DefaultMaxConcurrentCompactions = 4
const DefaultMaxWriterConcurrency = 8
type Options struct {
PebbleOptions *pebble.Options
Serializer Serializer[any]
}
func DefaultOptions() *Options {
opts := Options{
Serializer: &serializers.CBORSerializer{},
}
if opts.PebbleOptions == nil {
opts.PebbleOptions = DefaultPebbleOptions()
}
return &opts
}
func DefaultPebbleOptions() *pebble.Options {
var maxOpenFileLimit = 10000
pCache := pebble.NewCache(128 << 20) // 128 MB
defer func() {
pCache.Unref()
}()
pTableCache := pebble.NewTableCache(pCache, runtime.GOMAXPROCS(0), maxOpenFileLimit)
opts := &pebble.Options{
Cache: pCache,
TableCache: pTableCache,
FS: vfs.Default,
Comparer: DefaultKeyComparer(),
L0CompactionThreshold: 2,
L0StopWritesThreshold: 1000,
LBaseMaxBytes: 64 << 20, // 64 MB
MaxOpenFiles: maxOpenFileLimit,
Levels: make([]pebble.LevelOptions, 7),
MaxConcurrentCompactions: func() int { return DefaultMaxConcurrentCompactions },
MemTableSize: 64 << 20, // 64 MB
MemTableStopWritesThreshold: 4,
}
opts.FlushDelayDeleteRange = 10 * time.Second
opts.FlushDelayRangeKey = 10 * time.Second
opts.Experimental.MinDeletionRate = 128 << 20 // 128 MB
opts.Experimental.MaxWriterConcurrency = DefaultMaxWriterConcurrency
for i := 0; i < len(opts.Levels); i++ {
l := &opts.Levels[i]
l.BlockSize = 32 << 10 // 32 KB
l.IndexBlockSize = 256 << 10 // 256 KB
l.FilterPolicy = bloom.FilterPolicy(10)
l.FilterType = pebble.TableFilter
if i > 0 {
l.TargetFileSize = opts.Levels[i-1].TargetFileSize * 2
}
l.EnsureDefaults()
}
return opts
}