@@ -369,11 +369,13 @@ type flushable struct {
369369 totDocs uint64
370370}
371371
372- var DefaultNumPersisterWorkers = 1
372+ // number workers which parallely perform an in-memory merge of the segments followed
373+ // by a flush operation.
374+ var DefaultNumPersisterWorkers = 4
373375
374376// maximum size of data that a single worker is allowed to perform the in-memory
375377// merge operation.
376- var DefaultMaxSizeInMemoryMerge = 0
378+ var DefaultMaxSizeInMemoryMerge = 200 * 1024 * 1024
377379
378380func legacyFlushBehaviour () bool {
379381 // DefaultMaxSizeInMemoryMerge = 0 is a special value to preserve the leagcy
@@ -417,6 +419,8 @@ func (s *Scorch) persistSnapshotMaybeMerge(snapshot *IndexSnapshot) (
417419
418420 flushSet = append (flushSet , val )
419421 } else {
422+ // constructs a flushSet where each flushable object contains a set of segments
423+ // to be merged and flushed out to disk.
420424 for i , snapshot := range snapshot .segment {
421425 if totSize >= DefaultMaxSizeInMemoryMerge {
422426 if len (sbs ) >= DefaultMinSegmentsForInMemoryMerge {
@@ -480,12 +484,7 @@ func (s *Scorch) persistSnapshotMaybeMerge(snapshot *IndexSnapshot) (
480484 return false , nil
481485 }
482486
483- // deploy the workers, have a wait group which waits for the flush set to complete
484- // each worker
485- // 1. merges the segments using mergeSegmentBases()
486- // wait for group to finish
487- //
488- // construct equiv snapshot and do a persistSnapshotDirect()
487+ // drains out (after merging in memory) the segments in the flushSet parallely
489488 newSnapshot , newSegmentIDs , err := s .mergeSegmentBasesParallel (snapshot , flushSet )
490489 if err != nil {
491490 return false , err
0 commit comments