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)