Skip to content

Commit 61c3cf4

Browse files
authored
feat: support set max threads (#3537)
Signed-off-by: Jim Ma <majinjing3@gmail.com>
1 parent c9180af commit 61c3cf4

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

client/config/peerhost.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ type DaemonOption struct {
5151
AliveTime util.Duration `mapstructure:"aliveTime" yaml:"aliveTime"`
5252
GCInterval util.Duration `mapstructure:"gcInterval" yaml:"gcInterval"`
5353
Metrics string `mapstructure:"metrics" yaml:"metrics"`
54+
// MaxThreads indicates to invoke debug.SetMaxThreads to set max threads that golang runtime can create,
55+
// it's useful for large-scale downloading resource with none native golang source code, like call cgo to invoke c++
56+
// one cgo call will create a standalone os tread, the default 10000 limit is to small.
57+
// Normally, we can also set seed concurrent to limit for large-scale downloading at same time.
58+
MaxThreads int `mapstructure:"maxThreads" yaml:"maxThreads"`
5459

5560
WorkHome string `mapstructure:"workHome" yaml:"workHome"`
5661
WorkHomeMode uint32 `mapstructure:"workHomeMode" yaml:"workHomeMode"`

client/daemon/daemon.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"path"
2929
"path/filepath"
3030
"runtime"
31+
"runtime/debug"
3132
"sync"
3233
"time"
3334

@@ -119,6 +120,11 @@ func New(opt *config.DaemonOption, d dfpath.Dfpath) (Daemon, error) {
119120
// update plugin directory
120121
source.UpdatePluginDir(d.PluginDir())
121122

123+
if opt.MaxThreads > 10000 {
124+
debug.SetMaxThreads(opt.MaxThreads)
125+
logger.Infof("update runtime max threads: %d", opt.MaxThreads)
126+
}
127+
122128
// FIXME the viper casts all case sensitive keys into lower case, but the resource clients option is map[string]interface{}, it should not be casted.
123129
// issue: https://github.com/spf13/viper/issues/1014
124130
tmpOpt := config.NewDaemonConfig()

0 commit comments

Comments
 (0)