aboutsummaryrefslogtreecommitdiffstats
path: root/context.go
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2017-05-16 10:33:58 -0700
committerColin Cross <ccross@android.com>2017-05-16 10:55:29 -0700
commit4a02a3019a7ce18354d506c1fd8a5bc0dbbf09dd (patch)
tree388977347058e46ee85c99f8519d81f515ee371e /context.go
parentea10dedba9445aad5a14fc171a72c06e4d2280ba (diff)
downloadandroid_build_blueprint-4a02a3019a7ce18354d506c1fd8a5bc0dbbf09dd.tar.gz
android_build_blueprint-4a02a3019a7ce18354d506c1fd8a5bc0dbbf09dd.tar.bz2
android_build_blueprint-4a02a3019a7ce18354d506c1fd8a5bc0dbbf09dd.zip
Cap concurrency when parsing blueprint files
Darwin has a default limit of 256 open files per process. Parsing too many blueprint files in parallel can hit the limit. Cap the concurrency at 200. Test: manual testing with limit set to 32 Change-Id: Ic64d21d2c0ffd7c86bf3f02fb51216ee5684a80c
Diffstat (limited to 'context.go')
-rw-r--r--context.go25
1 files changed, 18 insertions, 7 deletions
diff --git a/context.go b/context.go
index 6793ac3..9dd68b4 100644
--- a/context.go
+++ b/context.go
@@ -719,10 +719,14 @@ func (c *Context) WalkBlueprintsFiles(rootFile string, handler FileHandler) (dep
// Number of outstanding goroutines to wait for
count := 0
- startParseBlueprintsFile := func(filename string, scope *parser.Scope) {
+ startParseBlueprintsFile := func(blueprint stringAndScope) {
+ if blueprintsSet[blueprint.string] {
+ return
+ }
+ blueprintsSet[blueprint.string] = true
count++
go func() {
- c.parseBlueprintsFile(filename, scope, rootDir,
+ c.parseBlueprintsFile(blueprint.string, blueprint.Scope, rootDir,
errsCh, fileCh, blueprintsCh, depsCh)
doneCh <- struct{}{}
}()
@@ -730,7 +734,9 @@ func (c *Context) WalkBlueprintsFiles(rootFile string, handler FileHandler) (dep
tooManyErrors := false
- startParseBlueprintsFile(rootFile, nil)
+ startParseBlueprintsFile(stringAndScope{rootFile, nil})
+
+ var pending []stringAndScope
loop:
for {
@@ -749,14 +755,19 @@ loop:
if tooManyErrors {
continue
}
- if blueprintsSet[blueprint.string] {
+ // Limit concurrent calls to parseBlueprintFiles to 200
+ // Darwin has a default limit of 256 open files
+ if count >= 200 {
+ pending = append(pending, blueprint)
continue
}
-
- blueprintsSet[blueprint.string] = true
- startParseBlueprintsFile(blueprint.string, blueprint.Scope)
+ startParseBlueprintsFile(blueprint)
case <-doneCh:
count--
+ if len(pending) > 0 {
+ startParseBlueprintsFile(pending[len(pending)-1])
+ pending = pending[:len(pending)-1]
+ }
if count == 0 {
break loop
}