forked from blackbeans/kiteq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkiteq.go
85 lines (72 loc) · 2.15 KB
/
kiteq.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
package main
import (
"flag"
"fmt"
log "github.com/blackbeans/log4go"
"github.com/blackbeans/turbo"
"kiteq/server"
"net"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"runtime"
"runtime/debug"
"strconv"
"strings"
"syscall"
"time"
)
func main() {
fly := flag.Bool("fly", false, "-fly=true //开启服务端飞行模式")
logxml := flag.String("logxml", "./log/log.xml", "-logxml=./log/log.xml")
bindHost := flag.String("bind", ":13800", "-bind=localhost:13800")
zkhost := flag.String("zkhost", "localhost:2181", "-zkhost=localhost:2181")
topics := flag.String("topics", "", "-topics=trade,a,b")
db := flag.String("db", "memory://initcap=100000&maxcap=200000",
"-db=mysql://master:3306,slave:3306?db=kite&username=root&password=root&maxConn=500&batchUpdateSize=1000&batchDelSize=1000&flushPeriod=1000")
pprofPort := flag.Int("pport", -1, "pprof port default value is -1 ")
flag.Parse()
//加载log4go的配置
log.LoadConfiguration(*logxml)
flag.VisitAll(func(f *flag.Flag) {
log.Info("KiteQ[%s:%s]", f.Name, f.Value.String())
})
runtime.GOMAXPROCS(runtime.NumCPU())
host, port, _ := net.SplitHostPort(*bindHost)
rc := turbo.NewRemotingConfig(
"remoting-"+*bindHost,
20000, 16*1024,
16*1024, 10000, 10000,
10*time.Second, 160000)
kc := server.NewKiteQConfig("kiteq-"+*bindHost, *bindHost, *zkhost, *fly, 1*time.Second, 8000, 5*time.Second, strings.Split(*topics, ","), *db, rc)
qserver := server.NewKiteQServer(kc)
qserver.Start()
go func() {
if *pprofPort > 0 {
http.HandleFunc("/stat", qserver.HandleMonitor)
log.Error(http.ListenAndServe(host+":"+strconv.Itoa(*pprofPort), nil))
}
}()
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-kiteq-" + host + "_" + port + fmt.Sprintf("%d", unixtime)
f, err := os.Create(path)
if nil != err {
continue
} else {
debug.WriteHeapDump(f.Fd())
}
}
}
qserver.Shutdown()
log.Info("KiteQServer IS STOPPED!")
}