From cd108c6055fb1a3d82cdfd232c5fa8ad5c8fb8d0 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 7 Sep 2023 12:13:40 +0800 Subject: [PATCH 1/3] 1 --- .../internal/logic/datatransferlogic.go | 41 +++++++++++++++---- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index a27dfdc3..d66990fb 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -70,15 +70,7 @@ var ( //用户标识的连接(白板用户不存) mapUserConnPool = make(map[string]map[string]struct{}) //key是user_id +"_"+guest_id (val是个普通map,存储这个用户的所有连接标识) //用户标识的连接增删操作队列 - userConnPoolCtlChan = make(chan userConnPoolCtlChanItem, 2000) - //每个websocket连接入口缓冲队列长度 - websocketInChanLen = 1000 - //每个websocket连接出口缓冲队列长度 - websocketOutChanLen = 1000 - //渲染任务调度(添加任务/删除任务/修改任务属性)缓冲队列长度(该队列用于避免map并发读写冲突) - renderImageTaskCtlChanLen = 500 - //渲染任务缓冲队列长度 - renderChanLen = 500 + userConnPoolCtlChan = make(chan userConnPoolCtlChanItem, getCacheChanLenByLevel(4)) //是否开启debug openDebug = true //允许跨域的origin @@ -188,6 +180,8 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use l.sendGetUniqueIdErrResponse(conn) return wsConnectItem{}, err } + //根据不同用户获取不同缓冲队列长度 + websocketInChanLen, websocketOutChanLen, renderImageTaskCtlChanLen, renderChanLen := getCacheChanLenByUser(userInfo.UserId, userInfo.GuestId) ws := wsConnectItem{ conn: conn, userAgent: userAgent, @@ -219,6 +213,35 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use return ws, nil } +// 根据level获取缓冲队列长度 +func getCacheChanLenByLevel(level int) int { + switch level { + case 1: + return 50 + case 2: + return 100 + case 3: + return 500 + case 4: + return 1000 + default: + return 50 + } +} + +// 根据用户获取缓冲队列长度 +func getCacheChanLenByUser(userId, guestId int64) (websocketInChanLen, websocketOutChanLen, renderImageTaskCtlChanLen, renderChanLen int) { + var l int + if userId > 0 { + l = getCacheChanLenByLevel(3) + } else if guestId > 0 { + l = getCacheChanLenByLevel(2) + } else { + l = getCacheChanLenByLevel(2) + } + return l, l, l, l +} + // 添加用户索引池ws连接 func createUserConnPoolElement(userId, guestId int64, uniqueId string) { data := userConnPoolCtlChanItem{ From f64b6e8a43f4873e09726f4a3bc66be16b8b357a Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 7 Sep 2023 12:19:52 +0800 Subject: [PATCH 2/3] 1 --- server/websocket/internal/logic/datatransferlogic.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index d66990fb..4d2ae3c3 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -217,7 +217,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use func getCacheChanLenByLevel(level int) int { switch level { case 1: - return 50 + return 10 case 2: return 100 case 3: @@ -225,7 +225,7 @@ func getCacheChanLenByLevel(level int) int { case 4: return 1000 default: - return 50 + return 10 } } From 7075dfb22378d4b33df85c3423bc7b8162a8aba8 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 7 Sep 2023 12:23:04 +0800 Subject: [PATCH 3/3] 1 --- .../internal/logic/datatransferlogic.go | 41 ++++--------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 4d2ae3c3..f4e057fb 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -70,7 +70,15 @@ var ( //用户标识的连接(白板用户不存) mapUserConnPool = make(map[string]map[string]struct{}) //key是user_id +"_"+guest_id (val是个普通map,存储这个用户的所有连接标识) //用户标识的连接增删操作队列 - userConnPoolCtlChan = make(chan userConnPoolCtlChanItem, getCacheChanLenByLevel(4)) + userConnPoolCtlChan = make(chan userConnPoolCtlChanItem, 500) + //每个websocket连接入口缓冲队列长度默认值 + websocketInChanLen = 500 + //每个websocket连接出口缓冲队列长度默认值 + websocketOutChanLen = 500 + //每个websocket连接渲染任务调度队列长度默认值(添加任务/删除任务/修改任务属性)缓冲队列长度(该队列用于避免map并发读写冲突) + renderImageTaskCtlChanLen = 100 + //每个websocket渲染任务缓冲队列长度默认值 + renderChanLen = 500 //是否开启debug openDebug = true //允许跨域的origin @@ -180,8 +188,6 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use l.sendGetUniqueIdErrResponse(conn) return wsConnectItem{}, err } - //根据不同用户获取不同缓冲队列长度 - websocketInChanLen, websocketOutChanLen, renderImageTaskCtlChanLen, renderChanLen := getCacheChanLenByUser(userInfo.UserId, userInfo.GuestId) ws := wsConnectItem{ conn: conn, userAgent: userAgent, @@ -213,35 +219,6 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use return ws, nil } -// 根据level获取缓冲队列长度 -func getCacheChanLenByLevel(level int) int { - switch level { - case 1: - return 10 - case 2: - return 100 - case 3: - return 500 - case 4: - return 1000 - default: - return 10 - } -} - -// 根据用户获取缓冲队列长度 -func getCacheChanLenByUser(userId, guestId int64) (websocketInChanLen, websocketOutChanLen, renderImageTaskCtlChanLen, renderChanLen int) { - var l int - if userId > 0 { - l = getCacheChanLenByLevel(3) - } else if guestId > 0 { - l = getCacheChanLenByLevel(2) - } else { - l = getCacheChanLenByLevel(2) - } - return l, l, l, l -} - // 添加用户索引池ws连接 func createUserConnPoolElement(userId, guestId int64, uniqueId string) { data := userConnPoolCtlChanItem{