From 3cb5ccc937dc358460cb2e033525867813f7d25c Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Fri, 25 Aug 2023 10:08:45 +0800 Subject: [PATCH 01/19] =?UTF-8?q?fix:=E8=AF=B7=E6=B1=82=E7=AE=97=E6=B3=95,?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/resource/internal/logic/logocombinelogic.go | 3 ++- server/resource/internal/logic/logoremovebglogic.go | 3 ++- server/upload/internal/logic/uploadlogologic.go | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/server/resource/internal/logic/logocombinelogic.go b/server/resource/internal/logic/logocombinelogic.go index 53b02768..b1d5cc11 100644 --- a/server/resource/internal/logic/logocombinelogic.go +++ b/server/resource/internal/logic/logocombinelogic.go @@ -1,6 +1,7 @@ package logic import ( + "fmt" "fusenapi/service/repositories" "fusenapi/utils/auth" "fusenapi/utils/basic" @@ -70,7 +71,7 @@ func (l *LogoCombineLogic) LogoCombine(req *types.LogoCombineReq, userinfo *auth }) if err != nil { - return resp.SetStatus(basic.CodeServiceErr) + return resp.SetStatus(basic.CodeServiceErr, fmt.Sprintf("算法请求--LOGO信息--错误:%+v", err)) } // 返回成功的响应和上传URL diff --git a/server/resource/internal/logic/logoremovebglogic.go b/server/resource/internal/logic/logoremovebglogic.go index 4091c7a0..648ab01c 100644 --- a/server/resource/internal/logic/logoremovebglogic.go +++ b/server/resource/internal/logic/logoremovebglogic.go @@ -1,6 +1,7 @@ package logic import ( + "fmt" "fusenapi/service/repositories" "fusenapi/utils/auth" "fusenapi/utils/basic" @@ -48,7 +49,7 @@ func (l *LogoRemovebgLogic) LogoRemovebg(req *types.LogoRemovebgReq, userinfo *a }) if err != nil { - return resp.SetStatus(basic.CodeServiceErr) + return resp.SetStatus(basic.CodeServiceErr, fmt.Sprintf("算法请求--LOGO信息--错误:%+v", err)) } // 返回成功的响应和上传URL diff --git a/server/upload/internal/logic/uploadlogologic.go b/server/upload/internal/logic/uploadlogologic.go index 6b6abea0..ea2eefbb 100644 --- a/server/upload/internal/logic/uploadlogologic.go +++ b/server/upload/internal/logic/uploadlogologic.go @@ -1,6 +1,7 @@ package logic import ( + "fmt" "fusenapi/model/gmodel" "fusenapi/service/repositories" "fusenapi/utils/auth" @@ -135,7 +136,7 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us }) if err != nil { logx.Error(err) - return resp.SetStatus(basic.CodeServiceErr) + return resp.SetStatus(basic.CodeServiceErr, fmt.Sprintf("算法请求--LOGO信息--错误:%+v", err)) } logoUrl = resLogoStandard.ResourceUrl } else { @@ -178,7 +179,7 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us if err != nil { logx.Error(err) - return resp.SetStatus(basic.CodeServiceErr) + return resp.SetStatus(basic.CodeServiceErr, fmt.Sprintf("算法请求--LOGO信息--错误:%+v", err)) } resultStr = resLogoStandard.Res From 7985c677f449318098e045de4ad8c4fa5f44701d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 25 Aug 2023 10:28:11 +0800 Subject: [PATCH 02/19] fix --- .../websocket/internal/logic/rendernotifylogic.go | 2 +- .../internal/logic/ws_render_image_logic.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/server/websocket/internal/logic/rendernotifylogic.go b/server/websocket/internal/logic/rendernotifylogic.go index 89405427..f966fd90 100644 --- a/server/websocket/internal/logic/rendernotifylogic.go +++ b/server/websocket/internal/logic/rendernotifylogic.go @@ -83,7 +83,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a Option: 2, TaskId: req.TaskId, TaskProperty: renderTask{ - UnityRenderEndTime: time.Now().UTC().Unix(), + UnityRenderEndTime: time.Now().UTC().UnixMilli(), }, }) //发送处理并删除任务 diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 9a6a7b96..6ddd579f 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -166,8 +166,8 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { b := w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{ RenderId: renderImageData.RenderId, Image: *resource.ResourceUrl, - CombineTakesTime: "耗时0秒(缓存)", - UnityRenderTakesTime: "耗时0秒(缓存)", + CombineTakesTime: "(缓存)", + UnityRenderTakesTime: "(缓存)", }) //发送数据到out chan w.sendToOutChan(b) @@ -220,7 +220,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re Option: 2, TaskId: taskId, TaskProperty: renderTask{ - CombineBeginTime: time.Now().UTC().Unix(), + CombineBeginTime: time.Now().UTC().UnixMilli(), }, }) //获取刀版图 @@ -253,7 +253,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re Option: 2, TaskId: taskId, TaskProperty: renderTask{ - CombineEndTime: time.Now().UTC().Unix(), + CombineEndTime: time.Now().UTC().UnixMilli(), }, }) logx.Info("合成刀版图成功,合成刀版图数据:", combineReq, ",logo图片:", info.RenderData.Logo, " 刀版图:", *res.ResourceUrl) @@ -354,7 +354,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re Option: 2, TaskId: taskId, TaskProperty: renderTask{ - UnityRenderBeginTime: time.Now().UTC().Unix(), + UnityRenderBeginTime: time.Now().UTC().UnixMilli(), }, }) logx.Info("发送到unity成功,刀版图:", combineImage, " 请求unity的数据:", string(postDataBytes)) @@ -426,10 +426,10 @@ func (w *wsConnectItem) operationRenderTask() { CombineTakesTime := "" UnityRenderTakesTime := "" if taskData.CombineBeginTime > 0 && taskData.CombineEndTime > 0 { - CombineTakesTime = fmt.Sprintf("耗时%d秒", taskData.CombineEndTime-taskData.CombineBeginTime) + CombineTakesTime = fmt.Sprintf("耗时%dms", taskData.CombineEndTime-taskData.CombineBeginTime) } if taskData.UnityRenderBeginTime > 0 && taskData.UnityRenderEndTime > 0 { - UnityRenderTakesTime = fmt.Sprintf("耗时%d秒", taskData.UnityRenderEndTime-taskData.UnityRenderBeginTime) + UnityRenderTakesTime = fmt.Sprintf("耗时%dms", taskData.UnityRenderEndTime-taskData.UnityRenderBeginTime) } //发送到出口 w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{ From 12097036ba14de2e52199c55677ac21ef45cc978 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Fri, 25 Aug 2023 10:37:07 +0800 Subject: [PATCH 03/19] =?UTF-8?q?fix:=E8=AF=B7=E6=B1=82=E7=AE=97=E6=B3=95,?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/repositories/image_handle.go | 34 ++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index 8fd3e078..caab53c2 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -96,13 +96,16 @@ type ( LogoUrl string `json:"logo_url"` // 合图参数 } LogoCombineRes struct { - ResourceId string - ResourceUrl *string - Metadata *string + ResourceId string + ResourceUrl *string + Metadata *string + DiffTimeLogoCombine time.Duration + DiffTimeUploadFile time.Duration } ) func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) { + logc.Infof(ctx, "合图--处理--开始时间:%v", time.Now().UTC()) // 查询logo最新基础信息 var metadata *string var logoUrl *string @@ -194,13 +197,18 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq postMap["module_data"] = moduleDataMap postMap["param_data"] = combineParam - logc.Infof(ctx, "算法请求--合图--开始时间:%v", time.Now().UTC()) + logc.Infof(ctx, "合图--算法请求--合图--开始时间:%v", time.Now().UTC()) + var startTimeLogoCombine = time.Now() //合图--处理--开始时间 + var resultBLM constants.BLMServiceUrlResult err = curl.NewClient(ctx, &curl.Config{ BaseUrl: *l.BLMServiceUrl, Url: constants.BLMServiceUrlLogoCombine, }).PostJson(postMap, &resultBLM) - logc.Infof(ctx, "算法请求--合图--结束时间:%v", time.Now().UTC()) + + logc.Infof(ctx, "合图--算法请求--合图--结束时间:%v", time.Now().UTC()) + endTimeLogoCombine := time.Now() //合图--处理--开始时间 + diffTimeLogoCombine := endTimeLogoCombine.Sub(startTimeLogoCombine) //合图--处理--中间差 if err != nil { logx.Error(err) @@ -229,6 +237,10 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq MysqlConn: l.MysqlConn, AwsSession: l.AwsSession, } + + logc.Infof(ctx, "合图--上传文件--开始时间:%v", time.Now().UTC()) + var startTimeUploadFile = time.Now() //合图--上传--开始时间 + uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{ Source: "combine-image", FileHash: resourceId, @@ -238,13 +250,21 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq UserId: in.UserId, GuestId: in.GuestId, }) + logc.Infof(ctx, "合图--上传文件--开始时间:%v", time.Now().UTC()) + endTimeUploadFile := time.Now() //合图--处理--开始时间 + diffTimeUploadFile := endTimeUploadFile.Sub(startTimeUploadFile) //合图--处理--中间差 + if err != nil { logx.Error(err) return nil, err } + logc.Infof(ctx, "合图--处理--结束时间:%v", time.Now().UTC()) + return &LogoCombineRes{ - ResourceId: uploadRes.ResourceId, - ResourceUrl: &uploadRes.ResourceUrl, + ResourceId: uploadRes.ResourceId, + ResourceUrl: &uploadRes.ResourceUrl, + DiffTimeLogoCombine: diffTimeLogoCombine, + DiffTimeUploadFile: diffTimeUploadFile, }, nil } From ed6326f07d2a2fa9b13c1aea5b3e55d25a794a67 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Fri, 25 Aug 2023 10:48:54 +0800 Subject: [PATCH 04/19] =?UTF-8?q?fix:=E8=AF=B7=E6=B1=82=E7=AE=97=E6=B3=95,?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/repositories/image_handle.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index caab53c2..d9ac8356 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -99,13 +99,12 @@ type ( ResourceId string ResourceUrl *string Metadata *string - DiffTimeLogoCombine time.Duration - DiffTimeUploadFile time.Duration + DiffTimeLogoCombine int64 + DiffTimeUploadFile int64 } ) func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) { - logc.Infof(ctx, "合图--处理--开始时间:%v", time.Now().UTC()) // 查询logo最新基础信息 var metadata *string var logoUrl *string @@ -198,7 +197,7 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq postMap["param_data"] = combineParam logc.Infof(ctx, "合图--算法请求--合图--开始时间:%v", time.Now().UTC()) - var startTimeLogoCombine = time.Now() //合图--处理--开始时间 + var startTimeLogoCombine = time.Now().UnixMilli() //合图--处理--开始时间 var resultBLM constants.BLMServiceUrlResult err = curl.NewClient(ctx, &curl.Config{ @@ -207,9 +206,9 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq }).PostJson(postMap, &resultBLM) logc.Infof(ctx, "合图--算法请求--合图--结束时间:%v", time.Now().UTC()) - endTimeLogoCombine := time.Now() //合图--处理--开始时间 - diffTimeLogoCombine := endTimeLogoCombine.Sub(startTimeLogoCombine) //合图--处理--中间差 - + endTimeLogoCombine := time.Now().UnixMilli() //合图--处理--开始时间 + diffTimeLogoCombine := endTimeLogoCombine - startTimeLogoCombine //合图--处理--中间差 + logc.Infof(ctx, "合图--算法请求--合图--业务耗时:%d", diffTimeLogoCombine) if err != nil { logx.Error(err) return nil, err @@ -239,7 +238,7 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq } logc.Infof(ctx, "合图--上传文件--开始时间:%v", time.Now().UTC()) - var startTimeUploadFile = time.Now() //合图--上传--开始时间 + var startTimeUploadFile = time.Now().UnixMilli() //合图--上传--开始时间 uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{ Source: "combine-image", @@ -251,14 +250,14 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq GuestId: in.GuestId, }) logc.Infof(ctx, "合图--上传文件--开始时间:%v", time.Now().UTC()) - endTimeUploadFile := time.Now() //合图--处理--开始时间 - diffTimeUploadFile := endTimeUploadFile.Sub(startTimeUploadFile) //合图--处理--中间差 + endTimeUploadFile := time.Now().UnixMilli() //合图--处理--开始时间 + diffTimeUploadFile := endTimeUploadFile - startTimeUploadFile //合图--处理--中间差 + logc.Infof(ctx, "合图--上传文件--业务耗时:%d", diffTimeUploadFile) if err != nil { logx.Error(err) return nil, err } - logc.Infof(ctx, "合图--处理--结束时间:%v", time.Now().UTC()) return &LogoCombineRes{ ResourceId: uploadRes.ResourceId, From f807069c83e7ecaeb2eaefc8edf8d82a1e0896c1 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Fri, 25 Aug 2023 10:49:52 +0800 Subject: [PATCH 05/19] =?UTF-8?q?fix:=E8=AF=B7=E6=B1=82=E7=AE=97=E6=B3=95,?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/repositories/image_handle.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index d9ac8356..9344d3a3 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -249,7 +249,7 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq UserId: in.UserId, GuestId: in.GuestId, }) - logc.Infof(ctx, "合图--上传文件--开始时间:%v", time.Now().UTC()) + logc.Infof(ctx, "合图--上传文件--结束时间:%v", time.Now().UTC()) endTimeUploadFile := time.Now().UnixMilli() //合图--处理--开始时间 diffTimeUploadFile := endTimeUploadFile - startTimeUploadFile //合图--处理--中间差 From e3aff09ede9e4fcbf5df78ecf180294d1606e2c8 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 25 Aug 2023 11:06:32 +0800 Subject: [PATCH 06/19] fix --- .../internal/logic/rendernotifylogic.go | 7 +- .../internal/logic/ws_render_image_logic.go | 83 +++++++++++-------- utils/websocket_data/render_data.go | 10 ++- 3 files changed, 60 insertions(+), 40 deletions(-) diff --git a/server/websocket/internal/logic/rendernotifylogic.go b/server/websocket/internal/logic/rendernotifylogic.go index f966fd90..9c8dedf4 100644 --- a/server/websocket/internal/logic/rendernotifylogic.go +++ b/server/websocket/internal/logic/rendernotifylogic.go @@ -45,6 +45,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a logx.Error("渲染回调参数错误:渲染结果图片数据") return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param image") } + unityRenderEndTime := time.Now().UTC().UnixMilli() //存base64打印测试 /* f, _ := os.Create("b.txt") defer f.Close() @@ -70,6 +71,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a logx.Error("渲染回调上传文件失败:", err) return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload render resource image") } + uploadUnityRenderImageTakesTime := time.Now().UTC().UnixMilli() - unityRenderEndTime //遍历websocket链接把数据传进去 mapConnPool.Range(func(key, value any) bool { //断言连接 @@ -78,12 +80,13 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a logx.Error("渲染回调断言websocket连接失败") return true } - //记录收到unity渲染结果时间 + //记录收到unity渲染结果时间以及上传渲染图耗时时间 ws.modifyRenderTaskTimeConsuming(renderImageControlChanItem{ Option: 2, TaskId: req.TaskId, TaskProperty: renderTask{ - UnityRenderEndTime: time.Now().UTC().UnixMilli(), + UnityRenderEndTime: unityRenderEndTime, + UploadUnityRenderImageTakesTime: uploadUnityRenderImageTakesTime, }, }) //发送处理并删除任务 diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 6ddd579f..f860adda 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -36,11 +36,12 @@ type renderImageControlChanItem struct { // 渲染任务属性 type renderTask struct { - RenderId string //渲染id(前端传的) - CombineBeginTime int64 //合图开始时间 - CombineEndTime int64 //合图结束时间 - UnityRenderBeginTime int64 //发送给unity时间 - UnityRenderEndTime int64 //unity回调结果时间 + RenderId string //渲染id(前端传的) + CombineTakesTime int64 //合刀版图耗时 + UploadCombineImageTakesTime int64 //上传刀版图耗时 + UnityRenderBeginTime int64 //发送给unity时间 + UnityRenderEndTime int64 //unity回调结果时间 + UploadUnityRenderImageTakesTime int64 //上传unity渲染结果图时间 } // 发送到渲染缓冲池 @@ -166,8 +167,8 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { b := w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{ RenderId: renderImageData.RenderId, Image: *resource.ResourceUrl, - CombineTakesTime: "(缓存)", - UnityRenderTakesTime: "(缓存)", + CombineTakesTime: "cache", + UnityRenderTakesTime: "cache", }) //发送数据到out chan w.sendToOutChan(b) @@ -214,15 +215,6 @@ func (w *wsConnectItem) genRenderTaskId(renderImageData websocket_data.RenderIma // 组装数据发送给unity func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.RenderImageReqMsg, productTemplate *gmodel.FsProductTemplateV2, model3dInfo *gmodel.FsProductModel3d, element *gmodel.FsProductTemplateElement, productFirstSize *gmodel.FsProductSize) error { - - //记录刀版图合成开始时间 - w.modifyRenderTaskTimeConsuming(renderImageControlChanItem{ - Option: 2, - TaskId: taskId, - TaskProperty: renderTask{ - CombineBeginTime: time.Now().UTC().UnixMilli(), - }, - }) //获取刀版图 combineReq := repositories.LogoCombineReq{ UserId: info.RenderData.UserId, @@ -248,12 +240,13 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re logx.Error("合成刀版图失败,合成的刀版图是空指针:", err) return err } - //记录刀版图合成结束时间 + //记录刀版图合成消耗时间跟上传刀版图时间 w.modifyRenderTaskTimeConsuming(renderImageControlChanItem{ Option: 2, TaskId: taskId, TaskProperty: renderTask{ - CombineEndTime: time.Now().UTC().UnixMilli(), + CombineTakesTime: res.DiffTimeLogoCombine, + UploadCombineImageTakesTime: res.DiffTimeUploadFile, }, }) logx.Info("合成刀版图成功,合成刀版图数据:", combineReq, ",logo图片:", info.RenderData.Logo, " 刀版图:", *res.ResourceUrl) @@ -334,15 +327,15 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re url := w.logic.svcCtx.Config.Unity.Host + "/api/render/queue/push" header := make(map[string]string) header["content-type"] = "application/json" - t := time.Now().UTC() postData := map[string]interface{}{ "group": "unity3d", "source": "home page", "priority": 1, - "create_at": t, + "create_at": time.Now().UTC(), "render_data": sendData, } postDataBytes, _ := json.Marshal(postData) + unityRenderBeginTime := time.Now().UTC().UnixMilli() _, err = curl.ApiCall(url, "POST", header, bytes.NewReader(postDataBytes), time.Second*10) if err != nil { w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "request unity api err", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id) @@ -354,7 +347,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re Option: 2, TaskId: taskId, TaskProperty: renderTask{ - UnityRenderBeginTime: time.Now().UTC().UnixMilli(), + UnityRenderBeginTime: unityRenderBeginTime, }, }) logx.Info("发送到unity成功,刀版图:", combineImage, " 请求unity的数据:", string(postDataBytes)) @@ -423,20 +416,34 @@ func (w *wsConnectItem) operationRenderTask() { case 0: //渲染结果回调,删除任务 //存在任务,则发送渲染结果给前端 if taskData, ok := w.extendRenderProperty.renderImageTask[data.TaskId]; ok { - CombineTakesTime := "" - UnityRenderTakesTime := "" - if taskData.CombineBeginTime > 0 && taskData.CombineEndTime > 0 { - CombineTakesTime = fmt.Sprintf("耗时%dms", taskData.CombineEndTime-taskData.CombineBeginTime) + CombineTakesTime := "0ms" + UnityRenderTakesTime := "0ms" + uploadCombineImageTakesTime := "0ms" + uploadUnityRenderImageTakesTime := "0ms" + //合图时间 + if taskData.CombineTakesTime > 0 { + CombineTakesTime = fmt.Sprintf("%dms", taskData.CombineTakesTime) } + //上传刀版图时间 + if taskData.UploadCombineImageTakesTime > 0 { + uploadCombineImageTakesTime = fmt.Sprintf("%dms", taskData.UploadCombineImageTakesTime) + } + //unity渲染时间 if taskData.UnityRenderBeginTime > 0 && taskData.UnityRenderEndTime > 0 { - UnityRenderTakesTime = fmt.Sprintf("耗时%dms", taskData.UnityRenderEndTime-taskData.UnityRenderBeginTime) + UnityRenderTakesTime = fmt.Sprintf("%dms", taskData.UnityRenderEndTime-taskData.UnityRenderBeginTime) + } + //上传unity渲染图耗时 + if taskData.UploadUnityRenderImageTakesTime > 0 { + uploadUnityRenderImageTakesTime = fmt.Sprintf("%dms", taskData.UploadUnityRenderImageTakesTime) } //发送到出口 w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{ - RenderId: taskData.RenderId, - Image: data.RenderNotifyImageUrl, - CombineTakesTime: CombineTakesTime, - UnityRenderTakesTime: UnityRenderTakesTime, + RenderId: taskData.RenderId, + Image: data.RenderNotifyImageUrl, + CombineTakesTime: CombineTakesTime, + UnityRenderTakesTime: UnityRenderTakesTime, + UploadCombineImageTakesTime: uploadCombineImageTakesTime, + UploadUnityRenderImageTakesTime: uploadUnityRenderImageTakesTime, })) } //删除任务 @@ -447,15 +454,23 @@ func (w *wsConnectItem) operationRenderTask() { } case 2: //修改(耗时)属性 if taskData, ok := w.extendRenderProperty.renderImageTask[data.TaskId]; ok { - if data.TaskProperty.CombineBeginTime != 0 { - taskData.CombineBeginTime = data.TaskProperty.CombineBeginTime + //合图耗时 + if data.TaskProperty.CombineTakesTime != 0 { + taskData.CombineTakesTime = data.TaskProperty.CombineTakesTime } - if data.TaskProperty.CombineEndTime != 0 { - taskData.CombineEndTime = data.TaskProperty.CombineEndTime + //上传合图耗时 + if data.TaskProperty.UploadCombineImageTakesTime != 0 { + taskData.UploadCombineImageTakesTime = data.TaskProperty.UploadCombineImageTakesTime } + //上传渲染结果图耗时 + if data.TaskProperty.UploadUnityRenderImageTakesTime != 0 { + taskData.UploadUnityRenderImageTakesTime = data.TaskProperty.UploadUnityRenderImageTakesTime + } + //发送unity时间 if data.TaskProperty.UnityRenderBeginTime != 0 { taskData.UnityRenderBeginTime = data.TaskProperty.UnityRenderBeginTime } + //收到unity返回的时间 if data.TaskProperty.UnityRenderEndTime != 0 { taskData.UnityRenderEndTime = data.TaskProperty.UnityRenderEndTime } diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index cbc5e1eb..0a88f86b 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -27,10 +27,12 @@ type RenderData struct { // websocket发送渲染完的数据 type RenderImageRspMsg struct { - RenderId string `json:"render_id"` //渲染id - Image string `json:"image"` //渲染结果图片 - CombineTakesTime string `json:"combine_takes_time"` //合图需要时间 - UnityRenderTakesTime string `json:"unity_render_takes_time"` //unity渲染用时 + RenderId string `json:"render_id"` //渲染id + Image string `json:"image"` //渲染结果图片 + CombineTakesTime string `json:"combine_takes_time"` //合图需要时间 + UnityRenderTakesTime string `json:"unity_render_takes_time"` //unity渲染用时 + UploadCombineImageTakesTime string `json:"upload_combine_image_takes_time"` //上传刀版图耗时 + UploadUnityRenderImageTakesTime string `json:"upload_unity_render_image_takes_time"` //上传unity渲染结果图时间 } type ThirdPartyLoginRspMsg struct { //websocket三方登录的通知数据 From 24384f6a6108cfeee9bc99238add950e1e71f181 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Fri, 25 Aug 2023 11:21:43 +0800 Subject: [PATCH 07/19] =?UTF-8?q?fix:=E8=AF=B7=E6=B1=82=E7=AE=97=E6=B3=95,?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/curl/client_resty.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/curl/client_resty.go b/utils/curl/client_resty.go index 8542ea80..6cb0423f 100644 --- a/utils/curl/client_resty.go +++ b/utils/curl/client_resty.go @@ -3,7 +3,7 @@ package curl import ( "bytes" "context" - "errors" + "fmt" "time" "github.com/go-resty/resty/v2" @@ -87,7 +87,7 @@ func (c *defaultClient) PostJson(jsonData interface{}, res interface{}) error { //logc.Infof(c.ctx, "客户端 请求返回结果 Client PostForm res result:%+v", res) if resp.StatusCode() != 200 { - err = errors.New("服务端失败") + err = fmt.Errorf("服务端失败,返回结果:%+v", resp.RawResponse.Status) logx.Errorf("客户端 请求失败 Client PostForm Server error:%+v", err) } return err @@ -111,7 +111,7 @@ func (c *defaultClient) PostForm(formData map[string]string, res interface{}) (i logc.Infof(c.ctx, "客户端 请求返回结果 Client PostForm RawResponse result:%+v,%+V", resp.RawResponse.Status, resp.RawResponse.StatusCode) logc.Infof(c.ctx, "客户端 请求返回结果 Client PostForm res result:%+v", res) if resp.StatusCode() != 200 { - err = errors.New("服务端失败") + err = fmt.Errorf("服务端失败,返回结果:%+v", resp.RawResponse.Status) logx.Errorf("客户端 请求失败 Client PostForm Server error:%+v", err) } return res, err @@ -137,7 +137,7 @@ func (c *defaultClient) PostFile(fileParam string, fileName string, res interfac logc.Infof(c.ctx, "客户端 请求返回结果 Client PostFile RawResponse result:%+v,%+V", resp.RawResponse.Status, resp.RawResponse.StatusCode) logc.Infof(c.ctx, "客户端 请求返回结果 Client PostFile res result:%+v", res) if resp.StatusCode() != 200 { - err = errors.New("服务端失败") + err = fmt.Errorf("服务端失败,返回结果:%+v", resp.RawResponse.Status) logx.Errorf("客户端 请求失败 Client PostFile Server error:%+v", err) } return res, err From 413b7c6863353bddcaa0e236249da7d9428bacdf Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 25 Aug 2023 11:26:44 +0800 Subject: [PATCH 08/19] fix --- server/websocket/internal/logic/ws_reuse_last_connect.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/websocket/internal/logic/ws_reuse_last_connect.go b/server/websocket/internal/logic/ws_reuse_last_connect.go index 5a6d9a44..30a36870 100644 --- a/server/websocket/internal/logic/ws_reuse_last_connect.go +++ b/server/websocket/internal/logic/ws_reuse_last_connect.go @@ -53,6 +53,7 @@ func (w *wsConnectItem) reuseLastConnect(data []byte) { } //重新绑定 w.uniqueId = wid + mapConnPool.Store(wid, w) rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, wid) w.sendToOutChan(rsp) return From 66532c0d981705dc902d497a682458b29fd7f40f Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 25 Aug 2023 11:28:36 +0800 Subject: [PATCH 09/19] fix --- server/websocket/internal/logic/ws_reuse_last_connect.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/ws_reuse_last_connect.go b/server/websocket/internal/logic/ws_reuse_last_connect.go index 30a36870..bab5d61b 100644 --- a/server/websocket/internal/logic/ws_reuse_last_connect.go +++ b/server/websocket/internal/logic/ws_reuse_last_connect.go @@ -53,7 +53,7 @@ func (w *wsConnectItem) reuseLastConnect(data []byte) { } //重新绑定 w.uniqueId = wid - mapConnPool.Store(wid, w) + mapConnPool.Store(wid, *w) rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, wid) w.sendToOutChan(rsp) return From 6dbb6391c1c0938869db08e0ce490f7d625ca240 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 25 Aug 2023 11:50:49 +0800 Subject: [PATCH 10/19] fix --- server/websocket/internal/logic/ws_render_image_logic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index f860adda..170e363c 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -228,7 +228,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re } res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq) if err != nil { - w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "failed to combine image", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id) + w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "failed to combine image:"+err.Error(), w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id) logx.Error("合成刀版图失败,合成请求数据:", combineReq, "错误信息:", err) return err } From c4f888a52f24733c93404f89348c9cb563eda677 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 25 Aug 2023 12:01:01 +0800 Subject: [PATCH 11/19] fix --- .../internal/logic/ws_render_image_logic.go | 14 ++++++++------ utils/websocket_data/render_data.go | 11 +++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 170e363c..dcd89aa3 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -438,12 +438,14 @@ func (w *wsConnectItem) operationRenderTask() { } //发送到出口 w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{ - RenderId: taskData.RenderId, - Image: data.RenderNotifyImageUrl, - CombineTakesTime: CombineTakesTime, - UnityRenderTakesTime: UnityRenderTakesTime, - UploadCombineImageTakesTime: uploadCombineImageTakesTime, - UploadUnityRenderImageTakesTime: uploadUnityRenderImageTakesTime, + RenderId: taskData.RenderId, + Image: data.RenderNotifyImageUrl, + RenderProcessTime: websocket_data.RenderProcessTime{ + CombineTakesTime: CombineTakesTime, + UnityRenderTakesTime: UnityRenderTakesTime, + UploadCombineImageTakesTime: uploadCombineImageTakesTime, + UploadUnityRenderImageTakesTime: uploadUnityRenderImageTakesTime, + }, })) } //删除任务 diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index 0a88f86b..e6ddfb93 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -27,14 +27,13 @@ type RenderData struct { // websocket发送渲染完的数据 type RenderImageRspMsg struct { - RenderId string `json:"render_id"` //渲染id - Image string `json:"image"` //渲染结果图片 + RenderId string `json:"render_id"` //渲染id + Image string `json:"image"` //渲染结果图片 + RenderProcessTime RenderProcessTime `json:"render_process_time"` //流程耗时 +} +type RenderProcessTime struct { CombineTakesTime string `json:"combine_takes_time"` //合图需要时间 UnityRenderTakesTime string `json:"unity_render_takes_time"` //unity渲染用时 UploadCombineImageTakesTime string `json:"upload_combine_image_takes_time"` //上传刀版图耗时 UploadUnityRenderImageTakesTime string `json:"upload_unity_render_image_takes_time"` //上传unity渲染结果图时间 } -type ThirdPartyLoginRspMsg struct { - //websocket三方登录的通知数据 - Token string `json:"token"` -} From 25ee551ae87e6ec1816c21c6bf8980f2ca328959 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 25 Aug 2023 12:02:07 +0800 Subject: [PATCH 12/19] fix --- .../internal/logic/ws_render_image_logic.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index dcd89aa3..4ac0f8f5 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -165,10 +165,14 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { } else { //返回给客户端 b := w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{ - RenderId: renderImageData.RenderId, - Image: *resource.ResourceUrl, - CombineTakesTime: "cache", - UnityRenderTakesTime: "cache", + RenderId: renderImageData.RenderId, + Image: *resource.ResourceUrl, + RenderProcessTime: websocket_data.RenderProcessTime{ + CombineTakesTime: "cache", + UnityRenderTakesTime: "cache", + UploadCombineImageTakesTime: "cache", + UploadUnityRenderImageTakesTime: "cache", + }, }) //发送数据到out chan w.sendToOutChan(b) From a9d565aff9e2926b9f3ecbe203bc2eb82fc497cd Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 25 Aug 2023 12:21:02 +0800 Subject: [PATCH 13/19] fix --- .../websocket/internal/logic/datatransferlogic.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 5cc978c2..1d677b34 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -5,6 +5,7 @@ import ( "bytes" "encoding/hex" "encoding/json" + "errors" "fusenapi/constants" "fusenapi/utils/auth" "fusenapi/utils/encryption_decryption" @@ -138,8 +139,8 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) // 设置连接 func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.UserInfo, isFirefoxBrowser bool) (wsConnectItem, error) { - //生成连接唯一标识 - uniqueId, err := l.getUniqueId(userInfo) + //生成连接唯一标识(失败重试10次) + uniqueId, err := l.getUniqueId(userInfo, 10) if err != nil { //发送获取唯一标识失败的消息 l.sendGetUniqueIdErrResponse(conn) @@ -170,11 +171,15 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.User } // 获取唯一id -func (l *DataTransferLogic) getUniqueId(userInfo auth.UserInfo) (uniqueId string, err error) { +func (l *DataTransferLogic) getUniqueId(userInfo auth.UserInfo, retryTimes int) (uniqueId string, err error) { + if retryTimes < 0 { + return "", errors.New("failed to get unique id") + } //后面拼接上用户id uniqueId = hex.EncodeToString([]byte(uuid.New().String())) + getUserJoinPart(userInfo.UserId, userInfo.GuestId) + //存在则从新获取 if _, ok := mapConnPool.Load(uniqueId); ok { - uniqueId, err = l.getUniqueId(userInfo) + uniqueId, err = l.getUniqueId(userInfo, retryTimes-1) if err != nil { return "", err } From a68a060a06454670affbf6420983002380b1c47a Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 25 Aug 2023 14:00:16 +0800 Subject: [PATCH 14/19] fix --- .../logic/{ws_render_image_logic.go => ws_render_image.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename server/websocket/internal/logic/{ws_render_image_logic.go => ws_render_image.go} (100%) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image.go similarity index 100% rename from server/websocket/internal/logic/ws_render_image_logic.go rename to server/websocket/internal/logic/ws_render_image.go From 826ba92b8e280f522d891693e7f12650d6766bdc Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 25 Aug 2023 14:49:24 +0800 Subject: [PATCH 15/19] fix --- .../internal/logic/commonnotifylogic.go | 76 ++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/commonnotifylogic.go b/server/websocket/internal/logic/commonnotifylogic.go index 7d13abac..65fd1ffc 100644 --- a/server/websocket/internal/logic/commonnotifylogic.go +++ b/server/websocket/internal/logic/commonnotifylogic.go @@ -5,6 +5,8 @@ import ( "fusenapi/constants" "fusenapi/utils/auth" "fusenapi/utils/basic" + "sync" + "time" "fusenapi/server/websocket/internal/svc" "fusenapi/server/websocket/internal/types" @@ -26,6 +28,68 @@ func NewCommonNotifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Comm } } +// 定义公共回调未找到websocket连接时暂存数据缓冲队列 +var commonConnectionNotFoundDataCacheChan = make(chan commonConnectionNotFoundDataCacheChanItem, 2000) + +type commonConnectionNotFoundDataCacheChanItem struct { + retryTimes int //重回队列次数 + data types.CommonNotifyReq //数据 +} + +// 放入缓冲队列 +func (l *CommonNotifyLogic) pushCommonCache(data commonConnectionNotFoundDataCacheChanItem) { + select { + case commonConnectionNotFoundDataCacheChan <- data: + return + case <-time.After(time.Second): //超1秒就丢弃 + return + } +} + +// 取出元素 +func (l *CommonNotifyLogic) popCommonCache() (data commonConnectionNotFoundDataCacheChanItem) { + return <-commonConnectionNotFoundDataCacheChan +} + +// 保证处理消息就一个循环在执行 +var consumeCommonCacheData sync.Once + +// 消费公共通知未处理的消息 +func (l *CommonNotifyLogic) consumeCommonCacheData() { + //单例 + consumeCommonCacheData.Do(func() { + tick := time.Tick(time.Millisecond * 200) + for { + select { + case <-tick: //200毫秒触发一次 + info := l.popCommonCache() + //查询websocket连接 + value, ok := mapConnPool.Load(info.data.Wid) + //没有连接 + if !ok { + info.retryTimes-- + //大于0,则放回队列 + if info.retryTimes > 0 { + l.pushCommonCache(info) + continue + } + //否则直接丢弃消息 + continue + } + //断言连接 + ws, ok := value.(wsConnectItem) + if !ok { + logx.Error("渲染回调断言websocket连接失败") + continue + } + //发送 + ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_COMMON_NOTIFY, info.data.Data)) + } + + } + }) +} + // 处理进入前逻辑w,r // func (l *CommonNotifyLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { // } @@ -35,10 +99,20 @@ func (l *CommonNotifyLogic) CommonNotify(req *types.CommonNotifyReq, userinfo *a if req.Wid == "" { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "websocket connect id is empty") } + //触发消费公共未处理的消息(只有第一次有用) + l.consumeCommonCacheData() //查询websocket连接 value, ok := mapConnPool.Load(req.Wid) if !ok { - return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found") + //没找到连接就放到公共缓冲队列 + l.pushCommonCache(commonConnectionNotFoundDataCacheChanItem{ + retryTimes: 4, //重试4次 + data: types.CommonNotifyReq{ + Wid: req.Wid, + Data: req.Data, + }, + }) + return resp.SetStatusWithMessage(basic.CodeOK, "success") } //断言连接 ws, ok := value.(wsConnectItem) From b5b3042226b1945cd7b9c26cbb0df052766ae8d9 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 25 Aug 2023 14:52:42 +0800 Subject: [PATCH 16/19] fix --- server/websocket/internal/logic/commonnotifylogic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/commonnotifylogic.go b/server/websocket/internal/logic/commonnotifylogic.go index 65fd1ffc..a3668d88 100644 --- a/server/websocket/internal/logic/commonnotifylogic.go +++ b/server/websocket/internal/logic/commonnotifylogic.go @@ -99,7 +99,7 @@ func (l *CommonNotifyLogic) CommonNotify(req *types.CommonNotifyReq, userinfo *a if req.Wid == "" { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "websocket connect id is empty") } - //触发消费公共未处理的消息(只有第一次有用) + //触发消费公共未处理的消息(该方法是单例) l.consumeCommonCacheData() //查询websocket连接 value, ok := mapConnPool.Load(req.Wid) From a635a2f546425f6c0202a5617283b05eff8b1b0e Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 25 Aug 2023 14:59:36 +0800 Subject: [PATCH 17/19] fix --- server/websocket/internal/logic/commonnotifylogic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/commonnotifylogic.go b/server/websocket/internal/logic/commonnotifylogic.go index a3668d88..cde02fc8 100644 --- a/server/websocket/internal/logic/commonnotifylogic.go +++ b/server/websocket/internal/logic/commonnotifylogic.go @@ -100,7 +100,7 @@ func (l *CommonNotifyLogic) CommonNotify(req *types.CommonNotifyReq, userinfo *a return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "websocket connect id is empty") } //触发消费公共未处理的消息(该方法是单例) - l.consumeCommonCacheData() + go l.consumeCommonCacheData() //查询websocket连接 value, ok := mapConnPool.Load(req.Wid) if !ok { From 5d926a287df1aee86e41e601bb16c063f1246c49 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 25 Aug 2023 15:06:09 +0800 Subject: [PATCH 18/19] fix --- server/websocket/internal/logic/commonnotifylogic.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/websocket/internal/logic/commonnotifylogic.go b/server/websocket/internal/logic/commonnotifylogic.go index cde02fc8..e995426d 100644 --- a/server/websocket/internal/logic/commonnotifylogic.go +++ b/server/websocket/internal/logic/commonnotifylogic.go @@ -41,7 +41,7 @@ func (l *CommonNotifyLogic) pushCommonCache(data commonConnectionNotFoundDataCac select { case commonConnectionNotFoundDataCacheChan <- data: return - case <-time.After(time.Second): //超1秒就丢弃 + case <-time.After(time.Millisecond * 50): //超50ms就丢弃 return } } @@ -105,7 +105,7 @@ func (l *CommonNotifyLogic) CommonNotify(req *types.CommonNotifyReq, userinfo *a value, ok := mapConnPool.Load(req.Wid) if !ok { //没找到连接就放到公共缓冲队列 - l.pushCommonCache(commonConnectionNotFoundDataCacheChanItem{ + go l.pushCommonCache(commonConnectionNotFoundDataCacheChanItem{ retryTimes: 4, //重试4次 data: types.CommonNotifyReq{ Wid: req.Wid, From 195ad7c37f819cf2b5873bcd4de72556d445bb07 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 25 Aug 2023 15:15:00 +0800 Subject: [PATCH 19/19] fix --- server/websocket/internal/logic/commonnotifylogic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/commonnotifylogic.go b/server/websocket/internal/logic/commonnotifylogic.go index e995426d..2e5e6e65 100644 --- a/server/websocket/internal/logic/commonnotifylogic.go +++ b/server/websocket/internal/logic/commonnotifylogic.go @@ -106,7 +106,7 @@ func (l *CommonNotifyLogic) CommonNotify(req *types.CommonNotifyReq, userinfo *a if !ok { //没找到连接就放到公共缓冲队列 go l.pushCommonCache(commonConnectionNotFoundDataCacheChanItem{ - retryTimes: 4, //重试4次 + retryTimes: 20, //重试20次 data: types.CommonNotifyReq{ Wid: req.Wid, Data: req.Data,