Skip to content

Commit

Permalink
parallelize factor
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekparwal committed Apr 24, 2020
1 parent cea013b commit 414d5c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion codegen/module_system.go
Expand Up @@ -240,6 +240,7 @@ func NewDefaultModuleSystemWithMockHook(
workflowMock bool,
serviceMock bool,
configFile string,
parallelizeFactor int,
hooks ...PostGenHook,
) (*ModuleSystem, error) {
t, err := NewDefaultTemplate()
Expand All @@ -249,7 +250,7 @@ func NewDefaultModuleSystemWithMockHook(

var clientMockGenHook, workflowMockGenHook, serviceMockGenHook PostGenHook
if clientsMock {
clientMockGenHook, err = ClientMockGenHook(h, t)
clientMockGenHook, err = ClientMockGenHook(h, t, parallelizeFactor)
if err != nil {
return nil, errors.Wrap(err, "error creating client mock gen hook")
}
Expand Down
5 changes: 3 additions & 2 deletions codegen/post_gen_hooks.go
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -67,7 +68,7 @@ func newMockableClient(raw []byte) (*mockableClient, error) {
}

// ClientMockGenHook returns a PostGenHook to generate client mocks
func ClientMockGenHook(h *PackageHelper, t *Template) (PostGenHook, error) {
func ClientMockGenHook(h *PackageHelper, t *Template, parallelizeFactor int) (PostGenHook, error) {
bin, err := NewMockgenBin(h, t)
if err != nil {
return nil, errors.Wrap(err, "error building mockgen binary")
Expand Down Expand Up @@ -136,7 +137,7 @@ func ClientMockGenHook(h *PackageHelper, t *Template) (PostGenHook, error) {

var idx int32 = 1
var files sync.Map
runner = parallelize.NewUnboundedRunner(mockCount)
runner = parallelize.NewBoundedRunner(mockCount, parallelizeFactor*runtime.NumCPU())
for _, instance := range clientInstances {
f := func(instanceInf interface{}) (interface{}, error) {
instance := instanceInf.(*ModuleInstance)
Expand Down
8 changes: 7 additions & 1 deletion codegen/runner/runner.go
Expand Up @@ -32,6 +32,8 @@ import (
zanzibar "github.com/uber/zanzibar/runtime"
)

const _defaultParallelizeFactor = 2

type stackTracer interface {
StackTrace() errors.StackTrace
}
Expand Down Expand Up @@ -142,7 +144,11 @@ func main() {
}
var moduleSystem *codegen.ModuleSystem
if genMock {
moduleSystem, err = codegen.NewDefaultModuleSystemWithMockHook(packageHelper, true, true, true, "test.yaml")
parallelizeFactor := _defaultParallelizeFactor
if config.ContainsKey("parallelizeFactor") {
parallelizeFactor = int(config.MustGetInt("parallelizeFactor"))
}
moduleSystem, err = codegen.NewDefaultModuleSystemWithMockHook(packageHelper, true, true, true, "test.yaml", parallelizeFactor)
} else {
moduleSystem, err = codegen.NewDefaultModuleSystem(packageHelper)
}
Expand Down

0 comments on commit 414d5c3

Please sign in to comment.