Skip to content

Commit 8753095

Browse files
committed
try with a regular mutex instead of favor readers
1 parent b53cf29 commit 8753095

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

collect/cache/cuckoo.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const (
3232
type CuckooTraceChecker struct {
3333
current *cuckoo.Filter
3434
future *cuckoo.Filter
35-
mut sync.RWMutex
35+
mut sync.Mutex
3636
capacity uint
3737
met metrics.Metrics
3838
addch chan string
@@ -86,7 +86,7 @@ func NewCuckooTraceChecker(capacity uint, m metrics.Metrics) *CuckooTraceChecker
8686
batch = append(batch, t)
8787
// insert 100 traceIDs at a time to reduce
8888
// the amount of time this goroutine holding the write lock
89-
for len(batch) < 100 && len(c.addch) > 0 {
89+
for len(batch) < 1000 && len(c.addch) > 0 {
9090
batch = append(batch, <-c.addch)
9191
}
9292

@@ -184,8 +184,8 @@ func (c *CuckooTraceChecker) Add(traceID string) {
184184

185185
// Check tests if a traceID is (very probably) in the filter.
186186
func (c *CuckooTraceChecker) Check(traceID string) bool {
187-
c.mut.RLock()
188-
defer c.mut.RUnlock()
187+
c.mut.Lock()
188+
defer c.mut.Unlock()
189189
return c.current.Lookup([]byte(traceID))
190190
}
191191

@@ -197,13 +197,13 @@ func (c *CuckooTraceChecker) Maintain() {
197197
c.drain()
198198

199199
var futureLoadFactor float64
200-
c.mut.RLock()
200+
c.mut.Lock()
201201
currentLoadFactor := c.current.LoadFactor()
202202
if c.future != nil {
203203
futureLoadFactor = c.future.LoadFactor()
204204
}
205205
currentCapacity := c.capacity
206-
c.mut.RUnlock()
206+
c.mut.Unlock()
207207

208208
// once the current one is half loaded, we can start using the future one too
209209
if futureLoadFactor == 0 && currentLoadFactor > 0.5 {

0 commit comments

Comments
 (0)