Skip to content

Commit

Permalink
Use multiple goroutines to add entries
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCutter committed Jul 23, 2024
1 parent 923389c commit 2f32e4d
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions cmd/example-posix/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"os"
"path/filepath"
"sync"
"time"

"golang.org/x/mod/sumdb/note"
Expand Down Expand Up @@ -154,14 +155,27 @@ func main() {
close(entries)
}()

for entry := range entries {
// ask storage to sequence
seq, err := st.Add(context.Background(), entry.e)
if err != nil {
klog.Exitf("failed to sequence %q: %q", entry.name, err)
}
klog.Infof("%d: %v", seq, entry.name)
numWorkers := 256
if l := len(toAdd); l < numWorkers {
numWorkers = l
}

wg := sync.WaitGroup{}
for i := 0; i < numWorkers; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for entry := range entries {
// ask storage to sequence
seq, err := st.Add(context.Background(), entry.e)
if err != nil {
klog.Exitf("failed to sequence %q: %q", entry.name, err)
}
klog.Infof("%d: %v", seq, entry.name)
}
}()
}
wg.Wait()
}

func getKeyFile(path string) (string, error) {
Expand Down

0 comments on commit 2f32e4d

Please sign in to comment.