@@ -18,6 +18,7 @@ package main
18
18
19
19
import (
20
20
"flag"
21
+ "math"
21
22
"math/rand"
22
23
"net/http"
23
24
"time"
@@ -26,10 +27,11 @@ import (
26
27
)
27
28
28
29
var (
29
- addr = flag .String ("listen-address" , ":8080" , "The address to listen on for HTTP requests." )
30
- uniformDomain = flag .Float64 ("random.uniform.domain" , 200 , "The domain for the uniform distribution." )
31
- normDomain = flag .Float64 ("random.exponential.domain" , 200 , "The domain for the normal distribution." )
32
- normMean = flag .Float64 ("random.exponential.mean" , 10 , "The mean for the normal distribution." )
30
+ addr = flag .String ("listen-address" , ":8080" , "The address to listen on for HTTP requests." )
31
+ uniformDomain = flag .Float64 ("uniform.domain" , 200 , "The domain for the uniform distribution." )
32
+ normDomain = flag .Float64 ("exponential.domain" , 200 , "The domain for the normal distribution." )
33
+ normMean = flag .Float64 ("exponential.mean" , 10 , "The mean for the normal distribution." )
34
+ oscillationPeriod = flag .Duration ("oscillation-period" , 10 * time .Minute , "The duration of the rate oscillation period." )
33
35
)
34
36
35
37
var (
@@ -53,14 +55,31 @@ func init() {
53
55
func main () {
54
56
flag .Parse ()
55
57
58
+ start := time .Now ()
59
+
60
+ oscillationFactor := func () float64 {
61
+ return 2 + math .Sin (math .Sin (2 * math .Pi * float64 (time .Since (start ))/ float64 (* oscillationPeriod )))
62
+ }
63
+
64
+ // Periodically record some sample latencies for the three services.
56
65
go func () {
57
66
for {
58
- // Periodically record some sample latencies for the three services.
59
67
rpcDurations .WithLabelValues ("uniform" ).Observe (rand .Float64 () * * uniformDomain )
68
+ time .Sleep (time .Duration (100 * oscillationFactor ()) * time .Millisecond )
69
+ }
70
+ }()
71
+
72
+ go func () {
73
+ for {
60
74
rpcDurations .WithLabelValues ("normal" ).Observe ((rand .NormFloat64 () * * normDomain ) + * normMean )
61
- rpcDurations .WithLabelValues ("exponential" ).Observe (rand .ExpFloat64 ())
75
+ time .Sleep (time .Duration (75 * oscillationFactor ()) * time .Millisecond )
76
+ }
77
+ }()
62
78
63
- time .Sleep (100 * time .Millisecond )
79
+ go func () {
80
+ for {
81
+ rpcDurations .WithLabelValues ("exponential" ).Observe (rand .ExpFloat64 ())
82
+ time .Sleep (time .Duration (50 * oscillationFactor ()) * time .Millisecond )
64
83
}
65
84
}()
66
85
0 commit comments