-
Notifications
You must be signed in to change notification settings - Fork 3
/
options.go
96 lines (76 loc) · 2.54 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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 {
// TODO: query this with syscall to get file descriptor limit,
// and set the value to 80%. We should also record this value on /status
var maxOpenFileLimit = 5_000
pCache := pebble.NewCache(256 << 20) // 256 MB
defer 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 max(DefaultMaxConcurrentCompactions, runtime.NumCPU()) },
MemTableSize: 128 << 20, // 128 MB
MemTableStopWritesThreshold: 4,
}
opts.EnsureDefaults()
opts.FlushDelayDeleteRange = 10 * time.Second
opts.FlushDelayRangeKey = 10 * time.Second
opts.TargetByteDeletionRate = 128 << 20 // 128 MB
opts.Experimental.MaxWriterConcurrency = max(DefaultMaxWriterConcurrency, runtime.NumCPU())
opts.Experimental.ReadSamplingMultiplier = -1
// TODO, collect these stats
// opts.EventListener = &pebble.EventListener{
// CompactionBegin: db.onCompactionBegin,
// CompactionEnd: db.onCompactionEnd,
// WriteStallBegin: db.onWriteStallBegin,
// WriteStallEnd: db.onWriteStallEnd,
// }
for i := range opts.Levels {
l := &opts.Levels[i]
l.EnsureDefaults()
l.BlockSize = 32 << 10 // 32 KB
l.IndexBlockSize = 256 << 10 // 256 KB
// enable zstd
l.Compression = func() pebble.Compression {
return pebble.ZstdCompression
}
l.FilterPolicy = bloom.FilterPolicy(10)
l.FilterType = pebble.TableFilter
if i > 0 {
// L0 is 2MB, and grows from there
l.TargetFileSize = opts.Levels[i-1].TargetFileSize * 2
}
}
return opts
}