mirror of
https://github.com/gogrlx/bitcask.git
synced 2026-04-02 02:58:59 -07:00
Improve Get/Put performance with optional mempooling (#36)
* avoid unnecessary use of encoder/decoder to decrease memory allocations * add an optional configurable mempool to avoid extra allocs * add doc.go with examples
This commit is contained in:
committed by
James Mills
parent
6ceeccfd64
commit
a407905ae2
20
options.go
20
options.go
@@ -1,5 +1,7 @@
|
||||
package bitcask
|
||||
|
||||
import "errors"
|
||||
|
||||
const (
|
||||
// DefaultMaxDatafileSize is the default maximum datafile size in bytes
|
||||
DefaultMaxDatafileSize = 1 << 20 // 1MB
|
||||
@@ -11,6 +13,12 @@ const (
|
||||
DefaultMaxValueSize = 1 << 16 // 65KB
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrMaxConcurrencyLowerEqZero is the error returned for
|
||||
// maxConcurrency option not greater than zero
|
||||
ErrMaxConcurrencyLowerEqZero = errors.New("error: maxConcurrency must be greater than zero")
|
||||
)
|
||||
|
||||
// Option is a function that takes a config struct and modifies it
|
||||
type Option func(*config) error
|
||||
|
||||
@@ -18,6 +26,7 @@ type config struct {
|
||||
maxDatafileSize int
|
||||
maxKeySize int
|
||||
maxValueSize int
|
||||
maxConcurrency *int
|
||||
}
|
||||
|
||||
func newDefaultConfig() *config {
|
||||
@@ -51,3 +60,14 @@ func WithMaxValueSize(size int) Option {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithMemPool configures usage of a memory pool to avoid allocations
|
||||
func WithMemPool(maxConcurrency int) Option {
|
||||
return func(cfg *config) error {
|
||||
if maxConcurrency <= 0 {
|
||||
return ErrMaxConcurrencyLowerEqZero
|
||||
}
|
||||
cfg.maxConcurrency = &maxConcurrency
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user