本文整理汇总了Golang中runtime/debug.SetMaxThreads函数的典型用法代码示例。如果您正苦于以下问题:Golang SetMaxThreads函数的具体用法?Golang SetMaxThreads怎么用?Golang SetMaxThreads使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetMaxThreads函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setProgramLimits
func setProgramLimits() {
// Swarm runnable threads could be large when the number of nodes is large
// or under request bursts. Most threads are occupied by network connections.
// Increase max thread count from 10k default to 50k to accommodate it.
const maxThreadCount int = 50 * 1000
debug.SetMaxThreads(maxThreadCount)
}
示例2: ThreadExhaustion
func ThreadExhaustion() {
debug.SetMaxThreads(10)
c := make(chan int)
for i := 0; i < 100; i++ {
go func() {
runtime.LockOSThread()
c <- 0
select {}
}()
<-c
}
}
示例3: NewSpider
func NewSpider(policy CrawlPolicy, numDownloads uint, numWorkers uint) (Spider, error) {
if numDownloads > MAX_DOWNLOADS || numWorkers > MAX_WORKERS {
return nil, InvalidArgs
}
d := newSimpleDownloader("downloads", numDownloads)
s := newSimpleScheduler(policy, numWorkers, d)
// set the max number of threads
debug.SetMaxThreads(MAX_WORKERS + MAX_DOWNLOADS + 1)
return &engine{s, d}, nil
}
示例4: configureMaxThreads
// configureMaxThreads sets the Go runtime max threads threshold
// which is 90% of the kernel setting from /proc/sys/kernel/threads-max
func configureMaxThreads(config *Config) error {
mt, err := ioutil.ReadFile("/proc/sys/kernel/threads-max")
if err != nil {
return err
}
mtint, err := strconv.Atoi(strings.TrimSpace(string(mt)))
if err != nil {
return err
}
maxThreads := (mtint / 100) * 90
debug.SetMaxThreads(maxThreads)
logrus.Debugf("Golang's threads limit set to %d", maxThreads)
return nil
}
示例5: main
func main() {
select {
case <-time.After(time.Second):
fmt.Println(time.Minute.Seconds(), time.Second)
}
select {
case <-time.After(time.Minute):
fmt.Println(time.Minute.Seconds(), time.Second)
}
var kvlist []int
kvlist = make([]int, 0, 10)
kvlist = append(kvlist, 1)
fmt.Println(kvlist)
m := make(map[int]int, 10)
m[1] += 1
fmt.Println("aaaa:", string(runtime.CPUProfile()), m, cap(kvlist))
for i := 0; ; i++ {
pc, file, line, ok := runtime.Caller(i)
if ok == false {
break
}
fmt.Println(pc, file, line, ok)
//runtime.Breakpoint()
}
fmt.Println(runtime.Version())
buf := make([]byte, 1025)
len := runtime.Stack(buf, true)
fmt.Println(string(runtime.CPUProfile()))
fmt.Println(len, string(buf[:len]))
//debug.PrintStack()
fmt.Println(debug.SetMaxThreads(10))
i := 100
fmt.Println(reflect.TypeOf((*int32)(nil)).Elem())
fmt.Println(reflect.ValueOf(&i).Kind())
fmt.Println(reflect.TypeOf(&i).Kind())
RoundPos(3, func(r, x, y int32) {
println(r, x, y)
})
}