-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (43 loc) · 777 Bytes
/
main.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
package main
import (
"fmt"
"time"
"github.com/wangzhipeng/autoscalingworker/worker"
)
func main() {
c := make(chan interface{}, 1000)
auto := worker.AutoScalingWorker{
MinWorker: 0,
MaxWorker: 10,
QueueDepth: 8,
Interval: time.Second,
Process: func(i interface{}) {
time.Sleep(time.Millisecond * 100)
},
Queue: c,
}
go auto.Start()
go func() {
for n := 0; n < 5; n++ {
for i := 0; i < 30; i++ {
c <- i
}
time.Sleep(time.Second)
}
}()
go func() {
time.Sleep(time.Second * 15)
for n := 0; n < 5; n++ {
for i := 0; i < 30; i++ {
c <- i
}
}
}()
go func() {
for {
fmt.Println("auto worker:", auto.CurrentWorker, " QueueDepth:", len(c))
time.Sleep(time.Second)
}
}()
time.Sleep(time.Minute)
}