@@ -205,8 +205,8 @@ func New(file string, cache int, handles int, namespace string, readonly bool) (
205205 // limit unchanged allows writes to be flushed more smoothly. This helps
206206 // avoid compaction spikes and mitigates write stalls caused by heavy
207207 // compaction workloads.
208- memTableLimit := 4
209- memTableSize := cache * 1024 * 1024 / 2 / memTableLimit
208+ memTableNumber := 4
209+ memTableSize := cache * 1024 * 1024 / 2 / memTableNumber
210210
211211 // The memory table size is currently capped at maxMemTableSize-1 due to a
212212 // known bug in the pebble where maxMemTableSize is not recognized as a
@@ -243,12 +243,16 @@ func New(file string, cache int, handles int, namespace string, readonly bool) (
243243 // Note, there may have more than two memory tables in the system.
244244 MemTableSize : uint64 (memTableSize ),
245245
246- // MemTableStopWritesThreshold places a hard limit on the size
246+ // MemTableStopWritesThreshold places a hard limit on the number
247247 // of the existent MemTables(including the frozen one).
248+ //
248249 // Note, this must be the number of tables not the size of all memtables
249250 // according to https://github.com/cockroachdb/pebble/blob/master/options.go#L738-L742
250251 // and to https://github.com/cockroachdb/pebble/blob/master/db.go#L1892-L1903.
251- MemTableStopWritesThreshold : memTableLimit ,
252+ //
253+ // MemTableStopWritesThreshold is set to twice the maximum number of
254+ // allowed memtables to accommodate temporary spikes.
255+ MemTableStopWritesThreshold : memTableNumber * 2 ,
252256
253257 // The default compaction concurrency(1 thread),
254258 // Here use all available CPUs for faster compaction.
@@ -296,6 +300,16 @@ func New(file string, cache int, handles int, namespace string, readonly bool) (
296300 // debt will be less than 1GB, but with more frequent compactions scheduled.
297301 L0CompactionThreshold : 2 ,
298302 }
303+ // These two settings define the conditions under which compaction concurrency
304+ // is increased. Specifically, one additional compaction job will be enabled when:
305+ // - there is one more overlapping sub-level0;
306+ // - there is an additional 512 MB of compaction debt;
307+ //
308+ // The maximum concurrency is still capped by MaxConcurrentCompactions, but with
309+ // these settings compactions can scale up more readily.
310+ opt .Experimental .L0CompactionConcurrency = 1
311+ opt .Experimental .CompactionDebtConcurrency = 1 << 28 // 256MB
312+
299313 // Open the db and recover any potential corruptions
300314 innerDB , err := pebble .Open (file , opt )
301315 if err != nil {
0 commit comments