fix
This commit is contained in:
parent
12795e2115
commit
1948a60c29
|
@ -39,24 +39,12 @@ func (l *GetStatLogic) GetStat(req *types.GetStatReq, userinfo *auth.UserInfo) (
|
||||||
GetStatMutex.Lock()
|
GetStatMutex.Lock()
|
||||||
defer GetStatMutex.Unlock()
|
defer GetStatMutex.Unlock()
|
||||||
userStat := make(map[string]interface{})
|
userStat := make(map[string]interface{})
|
||||||
currentWebsocketConnectCount := 0
|
|
||||||
currentCombineApiCount := 0
|
|
||||||
currentUnityHandleCount := 0
|
|
||||||
combineErrorCount := 0
|
|
||||||
req.UserKeys = strings.Trim(req.UserKeys, " ")
|
req.UserKeys = strings.Trim(req.UserKeys, " ")
|
||||||
if req.UserKeys != "" { //指定用户群体
|
if req.UserKeys != "" { //指定用户群体
|
||||||
reqUserList := strings.Split(req.UserKeys, ",")
|
reqUserList := strings.Split(req.UserKeys, ",")
|
||||||
for _, key := range reqUserList {
|
for _, key := range reqUserList {
|
||||||
value, ok := mapUserWsStat.Load(key)
|
value, ok := mapUserWsStat.Load(key)
|
||||||
if ok { //存在就累加
|
if ok { //存在就累加
|
||||||
if stat, ok := value.(mapUserWsStatItem); ok {
|
|
||||||
currentWebsocketConnectCount += stat.CurWsConnectCount
|
|
||||||
currentCombineApiCount += stat.CurCombineCount
|
|
||||||
currentUnityHandleCount += stat.CurUnityHandleCount
|
|
||||||
combineErrorCount += stat.CombineErrCount
|
|
||||||
} else {
|
|
||||||
logx.Error("断言mapUserWsStatItem错误")
|
|
||||||
}
|
|
||||||
userStat[key] = value
|
userStat[key] = value
|
||||||
} else {
|
} else {
|
||||||
userStat[key] = mapUserWsStatItem{}
|
userStat[key] = mapUserWsStatItem{}
|
||||||
|
@ -64,23 +52,15 @@ func (l *GetStatLogic) GetStat(req *types.GetStatReq, userinfo *auth.UserInfo) (
|
||||||
}
|
}
|
||||||
} else { //不指定用户
|
} else { //不指定用户
|
||||||
mapUserWsStat.Range(func(key, value any) bool {
|
mapUserWsStat.Range(func(key, value any) bool {
|
||||||
if stat, ok := value.(mapUserWsStatItem); ok {
|
|
||||||
currentWebsocketConnectCount += stat.CurWsConnectCount
|
|
||||||
currentCombineApiCount += stat.CurCombineCount
|
|
||||||
currentUnityHandleCount += stat.CurUnityHandleCount
|
|
||||||
combineErrorCount += stat.CombineErrCount
|
|
||||||
} else {
|
|
||||||
logx.Error("断言mapUserWsStatItem错误")
|
|
||||||
}
|
|
||||||
userStat[key.(string)] = value
|
userStat[key.(string)] = value
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetStatRsp{
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetStatRsp{
|
||||||
WsTotalCount: currentWebsocketConnectCount,
|
WsTotalCount: curWsTotalCount,
|
||||||
CurCombineCount: currentCombineApiCount,
|
CurCombineCount: curCombineTotalCount,
|
||||||
CurUnityHandleCount: currentUnityHandleCount,
|
CurUnityHandleCount: curUnityHandleTotalCount,
|
||||||
CombineErrorCount: combineErrorCount,
|
CombineErrorCount: combineErrTotalCount,
|
||||||
UserWsStat: userStat,
|
UserWsStat: userStat,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,16 @@ type mapUserWsStatItem struct {
|
||||||
var (
|
var (
|
||||||
//用户连接统计
|
//用户连接统计
|
||||||
mapUserWsStat = sync.Map{}
|
mapUserWsStat = sync.Map{}
|
||||||
//添加or减少连接的控制chan
|
//消息控制通道的数据结构
|
||||||
websocketStat = make(chan websocketStatData, 1000)
|
websocketStat = make(chan websocketStatData, 1000)
|
||||||
|
//ws总的连接数
|
||||||
|
curWsTotalCount int
|
||||||
|
//合图失败总数
|
||||||
|
combineErrTotalCount int
|
||||||
|
//unity正在渲染总数
|
||||||
|
curUnityHandleTotalCount int
|
||||||
|
//算法正在合图总数
|
||||||
|
curCombineTotalCount int
|
||||||
)
|
)
|
||||||
|
|
||||||
// 累增ws连接数计数
|
// 累增ws连接数计数
|
||||||
|
@ -48,6 +56,7 @@ func increaseWebsocketConnectCount(userId, guestId int64) {
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case websocketStat <- data:
|
case websocketStat <- data:
|
||||||
|
curWsTotalCount += data.Num
|
||||||
return
|
return
|
||||||
case <-time.After(time.Millisecond * 200):
|
case <-time.After(time.Millisecond * 200):
|
||||||
logx.Error("increaseWebsocketConnectCount 输入管道超时,丢弃消息")
|
logx.Error("increaseWebsocketConnectCount 输入管道超时,丢弃消息")
|
||||||
|
@ -65,6 +74,7 @@ func decreaseWebsocketConnectCount(userId, guestId int64) {
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case websocketStat <- data:
|
case websocketStat <- data:
|
||||||
|
curWsTotalCount += data.Num
|
||||||
return
|
return
|
||||||
case <-time.After(time.Millisecond * 200):
|
case <-time.After(time.Millisecond * 200):
|
||||||
logx.Error("decreaseWebsocketConnectCount 输入管道超时,丢弃消息")
|
logx.Error("decreaseWebsocketConnectCount 输入管道超时,丢弃消息")
|
||||||
|
@ -82,6 +92,7 @@ func increaseCombineRequestCount(userId, guestId int64) {
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case websocketStat <- data:
|
case websocketStat <- data:
|
||||||
|
curCombineTotalCount += data.Num
|
||||||
return
|
return
|
||||||
case <-time.After(time.Millisecond * 200):
|
case <-time.After(time.Millisecond * 200):
|
||||||
logx.Error("increaseCombineRequestCount 输入管道超时,丢弃消息")
|
logx.Error("increaseCombineRequestCount 输入管道超时,丢弃消息")
|
||||||
|
@ -99,6 +110,7 @@ func decreaseCombineRequestCount(userId, guestId int64) {
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case websocketStat <- data:
|
case websocketStat <- data:
|
||||||
|
curCombineTotalCount += data.Num
|
||||||
return
|
return
|
||||||
case <-time.After(time.Millisecond * 200):
|
case <-time.After(time.Millisecond * 200):
|
||||||
logx.Error("decreaseCombineRequestCount 输入管道超时,丢弃消息")
|
logx.Error("decreaseCombineRequestCount 输入管道超时,丢弃消息")
|
||||||
|
@ -116,6 +128,7 @@ func increaseCombineRequestErrorCount(userId, guestId int64) {
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case websocketStat <- data:
|
case websocketStat <- data:
|
||||||
|
combineErrTotalCount += data.Num
|
||||||
return
|
return
|
||||||
case <-time.After(time.Millisecond * 200):
|
case <-time.After(time.Millisecond * 200):
|
||||||
logx.Error("increaseCombineRequestErrorCount 输入管道超时,丢弃消息")
|
logx.Error("increaseCombineRequestErrorCount 输入管道超时,丢弃消息")
|
||||||
|
@ -133,6 +146,7 @@ func increaseUnityRequestCount(userId, guestId int64) {
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case websocketStat <- data:
|
case websocketStat <- data:
|
||||||
|
curUnityHandleTotalCount += data.Num
|
||||||
return
|
return
|
||||||
case <-time.After(time.Millisecond * 200):
|
case <-time.After(time.Millisecond * 200):
|
||||||
logx.Error("decreaseCombineRequestCount 输入管道超时,丢弃消息")
|
logx.Error("decreaseCombineRequestCount 输入管道超时,丢弃消息")
|
||||||
|
@ -150,6 +164,7 @@ func decreaseUnityRequestCount(userId, guestId int64) {
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case websocketStat <- data:
|
case websocketStat <- data:
|
||||||
|
curUnityHandleTotalCount += data.Num
|
||||||
return
|
return
|
||||||
case <-time.After(time.Millisecond * 200):
|
case <-time.After(time.Millisecond * 200):
|
||||||
logx.Error("decreaseUnityRequestCount 输入管道超时,丢弃消息")
|
logx.Error("decreaseUnityRequestCount 输入管道超时,丢弃消息")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user