@@ -19,6 +19,7 @@ import (
19
19
"flag"
20
20
"fmt"
21
21
"os"
22
+ "os/exec"
22
23
"strconv"
23
24
"syscall"
24
25
"time"
@@ -31,12 +32,14 @@ var (
31
32
memSize string
32
33
growthTime string
33
34
workers int
35
+ client bool
34
36
)
35
37
36
38
func init () {
37
39
flag .StringVar (& memSize , "size" , "0KB" , "size of memory you want to allocate" )
38
40
flag .StringVar (& growthTime , "time" , "0s" , "time to reach the size of memory you allocated" )
39
41
flag .IntVar (& workers , "workers" , 1 , "number of workers allocating memory" )
42
+ flag .BoolVar (& client , "client" , false , "the process runs as a client" )
40
43
flag .Parse ()
41
44
}
42
45
@@ -92,34 +95,47 @@ func run(length uint64, timeLine time.Duration) {
92
95
}
93
96
94
97
func main () {
95
- memInfo , _ := psutil .VirtualMemory ()
96
- var length uint64
97
-
98
- if memSize [len (memSize )- 1 ] != '%' {
99
- var err error
100
- length , err = humanize .ParseBytes (memSize )
101
- if err != nil {
102
- // TODO
103
- fmt .Println (err )
98
+ if ! client {
99
+ workQueue := make (chan struct {}, workers )
100
+ for {
101
+ workQueue <- struct {}{}
102
+ go func () {
103
+ err := exec .Command ("./memStress" , "--size" , memSize , "--time" , growthTime , "--client" , "1" ).Run ()
104
+ if err != nil {
105
+ fmt .Println (err )
106
+ }
107
+ <- workQueue
108
+ }()
109
+ time .Sleep (time .Second )
104
110
}
111
+
105
112
} else {
106
- percentage , err := strconv .ParseFloat (memSize [0 :len (memSize )- 1 ], 64 )
107
- if err != nil {
108
- fmt .Println (err )
113
+ memInfo , _ := psutil .VirtualMemory ()
114
+ var length uint64
115
+
116
+ if memSize [len (memSize )- 1 ] != '%' {
117
+ var err error
118
+ length , err = humanize .ParseBytes (memSize )
119
+ if err != nil {
120
+ // TODO
121
+ fmt .Println (err )
122
+ }
123
+ } else {
124
+ percentage , err := strconv .ParseFloat (memSize [0 :len (memSize )- 1 ], 64 )
125
+ if err != nil {
126
+ fmt .Println (err )
127
+ }
128
+ length = uint64 (float64 (memInfo .Total ) / 100.0 * percentage )
109
129
}
110
- length = uint64 (float64 (memInfo .Total ) / 100.0 * percentage )
111
- }
112
-
113
- timeLine , err := time .ParseDuration (growthTime )
114
- if err != nil {
115
- // TODO
116
- }
117
130
118
- for i := 0 ; i < workers ; i ++ {
119
- go run (length , timeLine )
120
- }
131
+ timeLine , err := time .ParseDuration (growthTime )
132
+ if err != nil {
133
+ // TODO
134
+ }
135
+ run (length , timeLine )
121
136
122
- for {
123
- time .Sleep (time .Second * 2 )
137
+ for {
138
+ time .Sleep (time .Second * 2 )
139
+ }
124
140
}
125
141
}
0 commit comments