잠시만 기다려 주세요

     '애도와 추모가 책임있는 사람들에게 면죄부를 주어서는 안됩니다. -더불어 민주당 국회의원 김용민-'
전체검색 :  
이번주 로또 및 연금번호 발생!!   |  HOME   |  여기는?   |  바다물때표   |  알림 (19)  |  여러가지 팁 (1095)  |  추천 및 재미 (163)  |  자료실 (28)  |  
시사, 이슈, 칼럼, 평론, 비평 (799)  |  끄적거림 (142)  |  문예 창작 (719)  |  바람 따라 (75)  |  시나리오 (760)  |  드라마 대본 (248)  |  
살인!


    golang

golang - golang Max number of goroutines, go 루틴 최대 개수 구하기.
이 름 : 바다아이   |   조회수 : 10147         짧은 주소 : https://www.bada-ie.com/su/?11591844198
자신의 시스템에서 굴릴 수 있는 go 루틴의 최대 개수를 구해 봅니다.
cpu와 ram 에 따라 달라지겠죠....


package main

import (
	"flag"
	"fmt"
	"os"
	"runtime"
	"time"
)

var n = flag.Int("n", 1e5, "Number of goroutines to create")

var ch = make(chan byte)
var counter = 0

func f() {
	counter++
	<-ch // Block this goroutine
}

func main() {
	flag.Parse()
	if *n <= 0 {
		fmt.Fprintf(os.Stderr, "invalid number of goroutines")
		os.Exit(1)
	}

	// Limit the number of spare OS threads to just 1
	runtime.GOMAXPROCS(1)

	// Make a copy of MemStats
	var m0 runtime.MemStats
	runtime.ReadMemStats(&m0)

	t0 := time.Now().UnixNano()
	for i := 0; i < *n; i++ {
		go f()
	}
	runtime.Gosched()
	t1 := time.Now().UnixNano()
	runtime.GC()

	// Make a copy of MemStats
	var m1 runtime.MemStats
	runtime.ReadMemStats(&m1)

	if counter != *n {
		fmt.Fprintf(os.Stderr, "failed to begin execution of all goroutines")
		os.Exit(1)
	}

	fmt.Printf("Number of goroutines: %d\n", *n)
	fmt.Printf("Per goroutine:\n")
	fmt.Printf("  Memory: %.2f bytes\n", float64(m1.Sys-m0.Sys)/float64(*n))
	fmt.Printf("  Time:   %f µs\n", float64(t1-t0)/float64(*n)/1e3)
}


출처 : https://stackoverflow.com/questions/8509152/max-number-of-goroutines
| |





      1 page / 6 page
번 호 카테고리 제 목 이름 조회수
180 golang golang ... 바다아이 139
179 golang golang , ... 바다아이 2726
178 golang golang , map . 바다아이 2106
177 golang Golang (, , data ) , ... 바다아이 2436
176 golang golang sort ... 바다아이 2808
175 golang golang html.EscapeString html.UnescapeString input value ... 바다아이 2731
174 golang golang go.mod go.sum . GOPATH SRC not module, 1.16 . 바다아이 6257
173 golang go 1.16 ... is not in GOROOT.. GOPATH .... . 바다아이 7412
172 golang , String Formatting 바다아이 8714
171 golang rand.Intn , random, , . 바다아이 8254
170 golang golang ... 바다아이 12005
169 golang golang gopath, goroot .. golang 바다아이 8971
168 golang golang ... Force download file example 바다아이 11002
167 golang golang , , cpu, memory, disk 바다아이 12068
166 golang golang , ... GOOS, GOARCH 바다아이 9714
165 golang golang checkbox ... 바다아이 9592
164 golang golang , , http .... 바다아이 9406
163 golang golang nil , nil , nil ... 바다아이 9485
162 golang 2 golang, go , .... golang .... 바다아이 12735
161 golang golang postgresql, mysql, mariadb ... ` Grave () .. .. 바다아이 10045
160 golang golang postgresql mysql, mariadb scan , null .. 바다아이 10117
159 golang golang , iconv 바다아이 12929
158 golang golang quote escape, unquote 바다아이 10352
157 golang golang , http errorLog , , ... 바다아이 10738
156 golang golang interface , 바다아이 9807
155 golang golang struct .... 바다아이 10530
154 golang golang map map , 바다아이 10003
153 golang golang map .... .... 바다아이 9338
152 golang golang slice copy 바다아이 9527
151 golang golang goto 바다아이 10717
| |









Copyright ⓒ 2001.12. bada-ie.com. All rights reserved.
이 사이트는 리눅스에서 firefox 기준으로 작성되었습니다. 기타 브라우저에서는 다르게 보일 수 있습니다.
[ Ubuntu + GoLang + PostgreSQL + Mariadb ]
서버위치 : 오라클 클라우드 춘천  실행시간 : 0.34217
to webmaster... gogo sea. gogo sea.