当前位置: 首页>>代码示例>>Golang>>正文


Golang debug.SetMaxThreads函数代码示例

本文整理汇总了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)
}
开发者ID:yehohanan7,项目名称:swarm,代码行数:7,代码来源:cli.go

示例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
	}
}
开发者ID:achanda,项目名称:go,代码行数:12,代码来源:deadlock.go

示例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
}
开发者ID:nightowlware,项目名称:cybergrab,代码行数:13,代码来源:spider.go

示例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
}
开发者ID:docker,项目名称:docker,代码行数:16,代码来源:daemon_unix.go

示例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)
	})
}
开发者ID:yc7369,项目名称:gostudy,代码行数:39,代码来源:runtimetest.go


注:本文中的runtime/debug.SetMaxThreads函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。