-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.go
50 lines (41 loc) · 859 Bytes
/
example.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
package main
import (
"github.com/forrestjgq/gomark"
"github.com/forrestjgq/gomark/internal/gm"
"math/rand"
"sync"
"time"
)
func main() {
gomark.StartHTTPServer(7777)
wg := sync.WaitGroup{}
wg.Add(2) // for adder and latency waiting
// adder
go func() {
adder := gomark.NewAdder("test_adder")
for i := 0; i < 10000; i++ {
adder.Mark(rand.Int31n(100))
time.Sleep(100 * time.Millisecond)
}
adder.Cancel()
wg.Done()
}()
// latency recorder
go func() {
lr := gomark.NewLatencyRecorder("test_latency")
for i := 0; i < 10000; i++ {
lr.Mark(rand.Int31n(100))
time.Sleep(100 * time.Millisecond)
}
lr.Cancel()
wg.Done()
}()
go func() {
time.Sleep(time.Second * 10)
gm.DisableServer()
time.Sleep(time.Second * 10)
gm.EnableServer()
}()
// wait and see monitor on http://127.0.0.1:7777/vars
wg.Wait()
}