-
Notifications
You must be signed in to change notification settings - Fork 0
/
idlegs.go
58 lines (48 loc) · 1.16 KB
/
idlegs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Test STW latency with large numbers of idle goroutines.
package main
import (
"flag"
"os"
"time"
"github.com/aclements/go-gcbench/gcbench"
)
const (
ballastSize = 100 << 20
garbagePerSec = 100 << 20
)
var (
flagDuration = flag.Duration("benchtime", 10*time.Second, "steady state duration")
// 5e5 Gs uses about 1.5GB of memory.
flagGs = flag.Int("idle-gs", 5e5, "start `n` idle goroutines")
flagStackSize = gcbench.FlagBytes("stack-size", 0, "stack size")
)
func main() {
flag.Parse()
if flag.NArg() > 0 {
flag.Usage()
os.Exit(2)
}
gcbench.NewBenchmark("IdleGs", benchMain).Config("idle-gs", *flagGs).Run()
}
func benchMain() {
for i := 0; i < *flagGs; i++ {
if *flagStackSize == 0 {
go func() { select {} }()
} else {
go func() {
gcbench.WithStack(*flagStackSize, func() {
select {}
})
}()
}
}
(&gcbench.Churner{
BallastBytes: ballastSize,
BytesPerSec: garbagePerSec,
}).Start()
time.AfterFunc(*flagDuration, func() { os.Exit(0) })
select {}
}