forked from URLooker/web
/
init.go
40 lines (31 loc) · 829 Bytes
/
init.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
package sender
import (
"github.com/urlooker/web/g"
"github.com/urlooker/web/utils"
"github.com/toolkits/container/list"
)
var (
NodeRing *ConsistentHashNodeRing // 服务节点的一致性哈希环
SendQueues map[string]*list.SafeListLimited // 发送缓存队列,减少发起连接次数
)
func initRing() {
NodeRing = NewConsistentHashNodeRing(g.Config.Alarm.Replicas, utils.KeysOfMap(g.Config.Alarm.Cluster))
}
func initSendQueues() {
SendQueues = make(map[string]*list.SafeListLimited)
for node, _ := range g.Config.Alarm.Cluster {
Q := list.NewSafeListLimited(10240)
SendQueues[node] = Q
}
}
func startSendTasks() {
for node, _ := range g.Config.Alarm.Cluster {
queue := SendQueues[node]
go SendToAlarm(queue, node)
}
}
func Init() {
initRing()
initSendQueues()
startSendTasks()
}