From 73e720ae910a0bc6800c1adcb74152c77339f3bd Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 12 Aug 2021 15:48:30 +0800 Subject: [PATCH] 1 --- httpserver.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/httpserver.go b/httpserver.go index d715c20..c825684 100644 --- a/httpserver.go +++ b/httpserver.go @@ -79,12 +79,14 @@ func (this *HttpServer) dispatchRequest(c *Context) { handle := this.getHandle(handleName) if handle != nil { beginTick := q5.GetTickCount() + defer func() { + endTick := q5.GetTickCount() + if oldVal := atomic.LoadInt64(&this.maxHandleTime); beginTick - endTick > oldVal { + atomic.CompareAndSwapInt64(&this.maxHandleTime, oldVal, endTick - beginTick) + } + atomic.AddInt64(&this.okTimes, 1) + }() handle(c) - endTick := q5.GetTickCount() - if oldVal := atomic.LoadInt64(&this.maxHandleTime); beginTick - endTick > oldVal { - atomic.CompareAndSwapInt64(&this.maxHandleTime, oldVal, endTick - beginTick) - } - atomic.AddInt64(&this.okTimes, 1) } else { c.Response(`{"errcode":404, "errmsg":"接口不存在"}`) atomic.AddInt64(&this.pageNotFoundTimes, 1)