Skip to content

Commit

Permalink
feat(fix): wti 将broadcast 内存泄露修改
Browse files Browse the repository at this point in the history
  • Loading branch information
steven committed Apr 9, 2022
1 parent aabcd05 commit 1a09e1d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
6 changes: 3 additions & 3 deletions plugins/wti/wti.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ func (t *tg) DelTAG(cli client.Clienter, tags ...string){
}


// 给某一个标签的群体进行广播
// BroadCast 给某一个标签的群体进行广播
func (t *tg) BroadCast(content []byte,tags ...string) {
if len(tags)== 0 {
return
}
t.rw.RLock()
defer t.rw.RUnlock()

for _,tag := range tags{
if group,ok := t.mp[tag];ok{
group.broadCast(content)
Expand All @@ -83,7 +82,8 @@ func (t *tg)Update(token ...string){
func(t *tg)BroadCastByTarget(targetAndContent map[string][]byte){
if len(targetAndContent) == 0{ return }
for target ,content := range targetAndContent {
go t.BroadCast(content,target)
// 将goroutine变成顺序写
t.BroadCast(content,target)
}
}

Expand Down
13 changes: 5 additions & 8 deletions plugins/wti/wti_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ func TestTg_DelTAG(t *testing.T) {
}





func TestTg_SetTAG(t *testing.T) {
tests := []struct{
tag string
Expand Down Expand Up @@ -143,8 +140,6 @@ func TestTg_BroadCast(t *testing.T) {

}



// 主要应对数据发送的时候版本的问题,比如某一条数据由于协议更改需要向上兼容老的版本,因为这是应用层的内容
// 所以使用wti 接口来进行兼容处理。避免进行内容的感染
func TestTg_BroadCastByTarget(t *testing.T) {
Expand Down Expand Up @@ -182,9 +177,6 @@ func TestTg_BroadCastByTarget(t *testing.T) {
// v1,v2,v3 websocket output :hello v1 | hello v2 | hello v3
}




// 主要应对数据发送的时候版本的问题,比如某一条数据由于协议更改需要向上兼容老的版本,因为这是应用层的内容
// 所以使用wti 接口来进行兼容处理。避免进行内容的感染
func TestTg_UpdateAndF(t *testing.T) {
Expand All @@ -209,4 +201,9 @@ func TestTg_UpdateAndF(t *testing.T) {
fmt.Println(res)
}
// output : []
}

// 对wti进行压力测试
func BenchmarkSetTAG(b *testing.B) {

}

0 comments on commit 1a09e1d

Please sign in to comment.