From 197f6d23f2bdd281e6bc8c4b24dd7a9409b10281 Mon Sep 17 00:00:00 2001
From: Manish R Jain <manishrjain@gmail.com>
Date: Wed, 2 Mar 2016 17:29:03 +1100
Subject: [PATCH] Pick the number of dirty posting lists to merge, based on the
 size of the dirtymap.

---
 posting/lists.go | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/posting/lists.go b/posting/lists.go
index 8f3d7744..a29474cf 100644
--- a/posting/lists.go
+++ b/posting/lists.go
@@ -101,22 +101,18 @@ func gentlyMerge(ms runtime.MemStats) {
 	ctr := NewCounters()
 	defer ctr.ticker.Stop()
 
-	// Pick 400 keys from dirty map.
+	// Pick 1% of the dirty map or 400 keys, whichever is higher.
+	pick := int(float64(dirtymap.Size()) * 0.01)
+	if pick < 400 {
+		pick = 400
+	}
 	var hs []gotomic.Hashable
 	dirtymap.Each(func(k gotomic.Hashable, v gotomic.Thing) bool {
 		hs = append(hs, k)
-		return len(hs) >= 400
+		return len(hs) >= pick
 	})
 
-	idx := 0
-	t := time.NewTicker(10 * time.Millisecond)
-	defer t.Stop()
-	for _ = range t.C {
-		if idx >= len(hs) {
-			break
-		}
-		hid := hs[idx]
-		idx += 1
+	for _, hid := range hs {
 		dirtymap.Delete(hid)
 
 		ret, ok := lhmap.Get(hid)
-- 
GitLab