Skip to content

Commit

Permalink
do not use ringbuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
shenwei356 committed Nov 19, 2020
1 parent cf23e0a commit 428d0bb
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions unikmer/cmd/util-db.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/pkg/errors"
"github.com/shenwei356/unikmer/index"
"github.com/shenwei356/util/pathutil"
"github.com/smallnest/ringbuffer"
"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -288,22 +287,22 @@ func (db *UnikIndexDB) searchHashes(hashes [][]uint64, threads int, queryCov flo
ch := make([]*map[string][3]float64, len(db.Indices))

var wg sync.WaitGroup
// tokens := make(chan int, threads)
tokens := ringbuffer.New(threads) // ringbufer is faster than channel
tokens := make(chan int, threads)
// tokens := ringbuffer.New(threads) // ringbufer is faster than channel
// for i, idx := range db.Indices {
for i := len(db.Indices) - 1; i >= 0; i-- { // start from bigger files
idx := db.Indices[i]

wg.Add(1)
// tokens <- 1
tokens.WriteByte(0)
tokens <- 1
// tokens.WriteByte(0)
go func(idx *UnikIndex, ch []*map[string][3]float64, i int) {
_m := idx.Search(hashes, queryCov, targetCov)
ch[i] = &_m

wg.Done()
// <-tokens
tokens.ReadByte()
<-tokens
// tokens.ReadByte()
}(idx, ch, i)
}
wg.Wait()
Expand Down

0 comments on commit 428d0bb

Please sign in to comment.