Skip to content

Commit

Permalink
feat(options): add NumGoroutines option for default Stream.numGo (#1656)
Browse files Browse the repository at this point in the history
  • Loading branch information
karlmcguire authored Feb 3, 2021
1 parent 1bebc26 commit cf66e6f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type Options struct {
Logger Logger
Compression options.CompressionType
InMemory bool
// Sets the Stream.numGo field
NumGoroutines int

// Fine tuning options.

Expand Down Expand Up @@ -125,6 +127,7 @@ func DefaultOptions(path string) Options {
TableSizeMultiplier: 2,
LevelSizeMultiplier: 10,
MaxLevels: 7,
NumGoroutines: 8,

NumCompactors: 4, // Run at least 2 compactors. Zero-th compactor prioritizes L0.
NumLevelZeroTables: 5,
Expand Down Expand Up @@ -252,6 +255,14 @@ func (opt Options) WithNumVersionsToKeep(val int) Options {
return opt
}

// WithNumGoroutines sets the number of goroutines to be used in Stream.
//
// The default value of NumGoroutines is 8.
func (opt Options) WithNumGoroutines(val int) Options {
opt.NumGoroutines = val
return opt
}

// WithReadOnly returns a new Options value with ReadOnly set to the given value.
//
// When ReadOnly is true the DB will be opened on read-only mode.
Expand Down
2 changes: 1 addition & 1 deletion stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func (st *Stream) Orchestrate(ctx context.Context) error {
func (db *DB) newStream() *Stream {
return &Stream{
db: db,
NumGo: 8,
NumGo: db.opt.NumGoroutines,
LogPrefix: "Badger.Stream",
}
}
Expand Down

0 comments on commit cf66e6f

Please sign in to comment.