Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Paralellized gps.WriteDepTree
Browse files Browse the repository at this point in the history
gps.WriteDepTree now writes vendor/ tree in parallel with
configurable number of worker routines
  • Loading branch information
aneshas committed Jul 26, 2017
1 parent 7d36525 commit 91d33f3
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 9 deletions.
48 changes: 39 additions & 9 deletions internal/gps/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"path/filepath"
)

// NumDepTreeWorkers determines the number of
// WriteDepTree worker goroutines
var NumDepTreeWorkers = 2

// A Solution is returned by a solver run. It is mostly just a Lock, with some
// additional methods that report information about the solve run.
type Solution interface {
Expand Down Expand Up @@ -61,19 +65,45 @@ func WriteDepTree(basedir string, l Lock, sm SourceManager, sv bool) error {
return err
}

// TODO(sdboyer) parallelize
for _, p := range l.Projects() {
to := filepath.FromSlash(filepath.Join(basedir, string(p.Ident().ProjectRoot)))
projects := l.Projects()
worksz := len(projects)

workChan := make(chan LockedProject, worksz)
doneChan := make(chan error, worksz)

for i := 0; i < NumDepTreeWorkers; i++ {
go func() {
for p := range workChan {
to := filepath.FromSlash(filepath.Join(basedir, string(p.Ident().ProjectRoot)))

err = sm.ExportProject(p.Ident(), p.Version(), to)
err = sm.ExportProject(p.Ident(), p.Version(), to)
if err != nil {
doneChan <- fmt.Errorf("error while exporting %s: %s", p.Ident().ProjectRoot, err)
continue
}

if sv {
filepath.Walk(to, stripVendor)
}

doneChan <- nil
}
// TODO(sdboyer) dump version metadata file
}()
}

for _, p := range projects {
workChan <- p
}

close(workChan)

for i := 0; i < worksz; i++ {
err := <-doneChan
if err != nil {
removeAll(basedir)
return fmt.Errorf("error while exporting %s: %s", p.Ident().ProjectRoot, err)
}
if sv {
filepath.Walk(to, stripVendor)
return err
}
// TODO(sdboyer) dump version metadata file
}

return nil
Expand Down
32 changes: 32 additions & 0 deletions internal/gps/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,40 @@ func testWriteDepTree(t *testing.T) {
func BenchmarkCreateVendorTree(b *testing.B) {
// We're fs-bound here, so restrict to single parallelism
b.SetParallelism(1)
NumDepTreeWorkers = 1

r := basicResult
benchmarkCreateVendorTree(b, r)
}

func BenchmarkCreateVendorTreeParallel(b *testing.B) {
r := solution{
att: 1,
p: []LockedProject{
pa2lp(atom{
id: pi("github.com/sdboyer/testrepo"),
v: NewBranch("master").Pair(Revision("4d59fb584b15a94d7401e356d2875c472d76ef45")),
}, nil),
pa2lp(atom{
id: pi("github.com/Masterminds/VCSTestRepo"),
v: NewVersion("1.0.0").Pair(Revision("30605f6ac35fcb075ad0bfa9296f90a7d891523e")),
}, nil),
pa2lp(atom{
id: pi("launchpad.net/govcstestbzrrepo"),
v: NewVersion("1.0.0").Pair(Revision("matt@mattfarina.com-20150731135137-pbphasfppmygpl68")),
}, nil),
pa2lp(atom{
id: pi("bitbucket.org/sdboyer/withbm"),
v: NewVersion("v1.0.0").Pair(Revision("aa110802a0c64195d0a6c375c9f66668827c90b4")),
}, nil),
},
}
r.analyzerInfo = (naiveAnalyzer{}).Info()

benchmarkCreateVendorTree(b, r)
}

func benchmarkCreateVendorTree(b *testing.B, r solution) {
tmp := path.Join(os.TempDir(), "vsolvtest")

clean := true
Expand Down

0 comments on commit 91d33f3

Please sign in to comment.