diff --git a/bin/gamesapi/config/config.json b/bin/gamesapi/config/config.json index 7bf05787..062ee28b 100644 --- a/bin/gamesapi/config/config.json +++ b/bin/gamesapi/config/config.json @@ -1,6 +1,6 @@ { "gamesapi_url": "https://game2006sapi-test.kingsome.cn", "redirect_url": "https://game2006api-test.kingsome.cn", - "max_request_cache": 10, + "max_concurrent_num": 10, "request_over_time": 30 } diff --git a/server/gamesapi/global/global.go b/server/gamesapi/global/global.go index 82033a59..8fe71005 100644 --- a/server/gamesapi/global/global.go +++ b/server/gamesapi/global/global.go @@ -32,10 +32,11 @@ func RegModule(idx int32, m q5.Module) { { app = m.(common.App) } - case constant.ROUTER_MODULE_IDX: + case constant.SERVICE_MGR_MODULE_IDX: { serviceMgr = m.(common.ServiceMgr) } + case constant.ROUTER_MODULE_IDX: default: { panic("unknow module") diff --git a/server/gamesapi/initialize/enter.go b/server/gamesapi/initialize/enter.go index de86a7d6..04ac6528 100644 --- a/server/gamesapi/initialize/enter.go +++ b/server/gamesapi/initialize/enter.go @@ -5,6 +5,7 @@ import ( _ "main/controller" . "main/global" _ "main/router" + _ "main/service" ) func Init() { diff --git a/server/gamesapi/middleware/caforward.go b/server/gamesapi/middleware/caforward.go index ed3fd6cd..bec34174 100644 --- a/server/gamesapi/middleware/caforward.go +++ b/server/gamesapi/middleware/caforward.go @@ -48,12 +48,14 @@ func CaForward(c *gin.Context) { var createErr error switch strings.ToUpper(c.Request.Method) { case "GET": { + service.SApiForward.IncGetTimes() httpRequest, createErr = http.NewRequest("GET", newUrl, nil) if !f5.IsOnlineEnv() { f5.GetSysLog().Info("CaForward method:%s newUrl:%s ", c.Request.Method, newUrl) } } case "POST": { + service.SApiForward.IncPostTimes() if postData, err := c.GetRawData(); err == nil { httpRequest, createErr = http.NewRequest("POST", newUrl, bytes.NewBuffer(postData)) contentType := c.GetHeader("Content-Type") @@ -76,6 +78,7 @@ func CaForward(c *gin.Context) { } } if createErr != nil { + service.SApiForward.IncCreateErrTimes() f5.RspErr(c, 500, "create request error") c.Abort() f5.GetSysLog().Info("CaForward create request url:%s error:%s", newUrl, createErr) @@ -85,16 +88,19 @@ func CaForward(c *gin.Context) { if resp, err := client.Do(httpRequest); err == nil { defer resp.Body.Close() if bytes, err := ioutil.ReadAll(resp.Body); err == nil { + service.SApiForward.IncOkTimes() c.String(200, string(bytes)) c.Abort() return } else { + service.SApiForward.IncReadRspErrTimes() f5.RspErr(c, 500, "read response error") c.Abort() f5.GetSysLog().Info("CaForward read response url:%s eror:%s", newUrl, err) return } } else { + service.SApiForward.IncDoErrTimes() f5.RspErr(c, 500, "client.Do error") c.Abort() f5.GetSysLog().Info("CaForward client.Do url:%s error:%s", newUrl, err) diff --git a/server/gamesapi/router/routermgr.go b/server/gamesapi/router/routermgr.go index 48471ef2..7ab29e0f 100644 --- a/server/gamesapi/router/routermgr.go +++ b/server/gamesapi/router/routermgr.go @@ -13,7 +13,7 @@ type routerMgr struct { func (this *routerMgr) Init() { redirectGroup := f5.GetApp().GetGinEngine().Group("/sapi") - redirectGroup.Any("webapp/index.php?", middleware.CaForward) + redirectGroup.Any("webapp/index.php", middleware.CaForward) f5.GetSysLog().Info("routerMgr.init") } diff --git a/server/gamesapi/service/sapi_forward.go b/server/gamesapi/service/sapi_forward.go index ed8d36b5..d8e1d90a 100644 --- a/server/gamesapi/service/sapi_forward.go +++ b/server/gamesapi/service/sapi_forward.go @@ -40,6 +40,7 @@ func (this *sApiForward) AcquireLock(accountId string) *SApiForwardLock { c := this.userCache[int64(crc32) % int64(len(this.userCache))] u := this.getOrCreate(c, accountId) if atomic.AddInt32(&u.lockTimes, 1) > mt.Table.Config.GetMaxConcurrentNum() { + atomic.AddInt32(&u.lockTimes, -1) return nil } u.lock.Lock() @@ -75,6 +76,10 @@ func (this *sApiForward) IncDoErrTimes() { } +func (this *sApiForward) IncOkTimes() { + +} + func (this *sApiForward) IncReadRspErrTimes() { }