-
Notifications
You must be signed in to change notification settings - Fork 0
/
dirtystack.go
66 lines (52 loc) · 1.46 KB
/
dirtystack.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
59
60
61
62
63
64
65
66
// 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 regions of dirty stack.
package main
import (
"flag"
"os"
"time"
"github.com/aclements/go-gcbench/gcbench"
"github.com/aclements/go-gcbench/gcbench/heapgen"
)
const (
// The ballast has to be reasonably large (and have pointers)
// so concurrent mark takes more than stackHighTime.
ballastSize = 128 << 20
garbagePerSec = 1000 << 20
stackHighTime = 10 * time.Millisecond
)
var ballast interface{}
func stack(id int) {
for {
gcbench.WithStack(*flagDirtyStack, func() {
time.Sleep(stackHighTime)
})
}
}
var (
flagDuration = flag.Duration("benchtime", 10*time.Second, "steady state duration")
flagGs = flag.Int("gs", 10000, "start `n` goroutines")
flagDirtyStack = gcbench.FlagBytes("dirty-stack", 10*gcbench.KB, "dirty approximately `bytes` of stack per goroutine each GC cycle")
)
func main() {
flag.Parse()
if flag.NArg() > 0 {
flag.Usage()
os.Exit(2)
}
gcbench.NewBenchmark("DirtyStack", benchMain).Config("gs", *flagGs).Config("dirty-stack", *flagDirtyStack).Run()
}
func benchMain() {
m := heapgen.Measure(heapgen.MakeAST)
ballast = heapgen.Generate(m.Gen, m.BytesRetained, ballastSize)
for i := 0; i < *flagGs; i++ {
go stack(i)
}
(&gcbench.Churner{
BytesPerSec: garbagePerSec,
}).Start()
time.Sleep(*flagDuration)
os.Exit(0)
}