forked from blackbeans/kiteq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kite_benchmark_consumer.go
89 lines (76 loc) · 1.69 KB
/
kite_benchmark_consumer.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"flag"
"fmt"
"kiteq/binding"
"kiteq/client"
"kiteq/protocol"
"log"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"runtime"
"runtime/debug"
"sync/atomic"
"syscall"
"time"
)
type defualtListener struct {
count int32
lc int32
}
func (self *defualtListener) monitor() {
for {
tmp := self.count
ftmp := self.lc
time.Sleep(1 * time.Second)
fmt.Printf("tps:%d\n", (tmp - ftmp))
self.lc = tmp
}
}
func (self *defualtListener) OnMessage(msg *protocol.QMessage) bool {
// log.Println("defualtListener|OnMessage", *msg.Header, *msg.Body)
atomic.AddInt32(&self.count, 1)
return true
}
func (self *defualtListener) OnMessageCheck(tx *protocol.TxResponse) error {
// log.Println("defualtListener|OnMessageCheck", messageId)
tx.Commit()
return nil
}
func main() {
zkhost := flag.String("zkhost", "localhost:2181", "-zkhost=localhost:2181")
flag.Parse()
runtime.GOMAXPROCS(8)
go func() {
log.Println(http.ListenAndServe(":38000", nil))
}()
lis := &defualtListener{}
go lis.monitor()
kite := client.NewKiteQClient(*zkhost, "s-mts-test", "123456", lis)
kite.SetBindings([]*binding.Binding{
binding.Bind_Direct("s-mts-test", "trade", "pay-succ", 1000, true),
})
kite.Start()
var s = make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGKILL, syscall.SIGUSR1)
//是否收到kill的命令
for {
cmd := <-s
if cmd == syscall.SIGKILL {
break
} else if cmd == syscall.SIGUSR1 {
//如果为siguser1则进行dump内存
unixtime := time.Now().Unix()
path := "./heapdump-consumer" + fmt.Sprintf("%d", unixtime)
f, err := os.Create(path)
if nil != err {
continue
} else {
debug.WriteHeapDump(f.Fd())
}
}
}
kite.Destory()
}