Merge pull request #753 from andycheng123/improve/optimizer-config

optimizer: add max num of thread in config
This commit is contained in:
Yo-An Lin 2022-06-21 12:18:33 +08:00 committed by GitHub
commit 16682596df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 4 deletions

View File

@ -3,6 +3,7 @@
# go run ./cmd/bbgo optimize --config bollmaker_ethusdt.yaml --optimizer-config optimizer.yaml --debug
#
---
maxThread: 10
matrix:
- type: iterate
label: interval

View File

@ -3,6 +3,7 @@
# go run ./cmd/bbgo optimize --config bollmaker_ethusdt.yaml --optimizer-config optimizer.yaml --debug
#
---
maxThread: 10
matrix:
- type: iterate
path: '/exchangeStrategies/0/bollmaker/interval'

View File

@ -3,6 +3,7 @@
# go run ./cmd/bbgo optimize --config config/pivotshort-ETHUSDT.yaml --optimizer-config config/pivotshort_optimizer.yaml --debug
#
---
maxThread: 10
matrix:
- type: iterate

View File

@ -19,6 +19,7 @@ type SelectorConfig struct {
}
type Config struct {
MaxThread int `yaml:"maxThread,omitempty"`
Matrix []SelectorConfig `yaml:"matrix"`
}
@ -33,5 +34,10 @@ func LoadConfig(yamlConfigFileName string) (*Config, error) {
return nil, err
}
// The default of MaxThread is 5
if optConfig.MaxThread <= 0 {
optConfig.MaxThread = 5
}
return &optConfig, nil
}

View File

@ -199,7 +199,8 @@ func (o *GridOptimizer) Run(executor Executor, configJson []byte) (map[string][]
}
}
resultsC, err := executor.Run(context.Background(), taskC)
ctx := context.WithValue(context.Background(), "MaxThread", o.Config.MaxThread)
resultsC, err := executor.Run(ctx, taskC)
if err != nil {
return nil, err
}

View File

@ -73,8 +73,8 @@ func (e *LocalProcessExecutor) readReport(output []byte) (*backtest.SummaryRepor
}
func (e *LocalProcessExecutor) Run(ctx context.Context, taskC chan BacktestTask) (chan BacktestTask, error) {
var maxNumOfProcess = 5
var resultsC = make(chan BacktestTask, 10)
var maxNumOfProcess = ctx.Value("MaxThread").(int)
var resultsC = make(chan BacktestTask, maxNumOfProcess*2)
wg := sync.WaitGroup{}
wg.Add(maxNumOfProcess)