當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。