Skip to content

Commit

Permalink
Call mget in two goroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
suzaku committed Jan 24, 2021
1 parent 6568e81 commit c9826c1
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions pkg/meta/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -1200,29 +1200,45 @@ func (r *redisMeta) Readdir(ctx Context, inode Ino, plus uint8, entries *[]*Entr
i++
}
if plus != 0 {
batchSize := 40960
batchSize := 4096
if batchSize > len(*entries) {
batchSize = len(*entries)
}
keysBatch := make([]string, 0, batchSize)
for i := 0; i < len(*entries); i += batchSize {
end := i + batchSize
if end > len(*entries) {
end = len(*entries)
nEntries := len(*entries)
indexCh := make(chan int, 10)
go func() {
for i := 0; i < nEntries; i += batchSize {
indexCh <- i
}
for _, e := range (*entries)[i:end] {
keysBatch = append(keysBatch, r.inodeKey(e.Inode))
}
rs, _ := r.rdb.MGet(ctx, keysBatch...).Result()
for j, re := range rs {
if re != nil {
if a, ok := re.(string); ok {
r.parseAttr([]byte(a), (*entries)[i+j].Attr)
close(indexCh)
}()
var wg sync.WaitGroup
for i := 0; i < 2; i++ {
wg.Add(1)
go func() {
defer wg.Done()
keysBatch := make([]string, 0, batchSize)
for idx := range indexCh {
end := idx + batchSize
if end > len(*entries) {
end = len(*entries)
}
for _, e := range (*entries)[idx:end] {
keysBatch = append(keysBatch, r.inodeKey(e.Inode))
}
rs, _ := r.rdb.MGet(ctx, keysBatch...).Result()
for j, re := range rs {
if re != nil {
if a, ok := re.(string); ok {
r.parseAttr([]byte(a), (*entries)[idx+j].Attr)
}
}
}
keysBatch = keysBatch[:0]
}
}
keysBatch = keysBatch[:0]
}()
}
wg.Wait()
}
return 0
}
Expand Down

0 comments on commit c9826c1

Please sign in to comment.