diff --git a/g/net/ghttp/ghttp_server_hooks.go b/g/net/ghttp/ghttp_server_hooks.go index 501e91cd4..5e0a127e5 100644 --- a/g/net/ghttp/ghttp_server_hooks.go +++ b/g/net/ghttp/ghttp_server_hooks.go @@ -91,12 +91,17 @@ func (s *Server) setHookHandler(pattern string, hook string, item *HandlerItem) // 事件回调 - 检索动态路由规则 // 并按照指定hook回调函数的优先级及注册顺序进行调用 func (s *Server) callHookHandler(r *Request, hook string) { + // 缓存清空时是直接修改属性,因此必须使用互斥锁 s.hhcmu.RLock() defer s.hhcmu.RUnlock() var hookItems []*hookCacheItem cacheKey := s.handlerHookKey(r.GetHost(), r.Method, r.URL.Path, hook) + + return + + if v := s.hooksCache.Get(cacheKey); v == nil { hookItems = s.searchHookHandler(r, hook) if hookItems != nil { diff --git a/geg/net/ghttp/performance/beego/dynamic.go b/geg/net/ghttp/performance/beego/dynamic.go new file mode 100644 index 000000000..12778850d --- /dev/null +++ b/geg/net/ghttp/performance/beego/dynamic.go @@ -0,0 +1,14 @@ +package main + +import ( + "github.com/astaxie/beego" + "github.com/astaxie/beego/context" +) + +func main() { + beego.Get("/:name",func(ctx *context.Context){ + ctx.Output.Body([]byte(ctx.Input.Param(":name"))) + }) + beego.BeeLogger.SetLevel(0) + beego.Run(":8199") +} \ No newline at end of file diff --git a/geg/net/ghttp/performance/beego/static.go b/geg/net/ghttp/performance/beego/static.go new file mode 100644 index 000000000..7460b2d54 --- /dev/null +++ b/geg/net/ghttp/performance/beego/static.go @@ -0,0 +1,14 @@ +package main + +import ( + "github.com/astaxie/beego" + "github.com/astaxie/beego/context" +) + +func main() { + beego.Get("/",func(ctx *context.Context){ + ctx.Output.Body([]byte("哈喽世界!")) + }) + beego.BeeLogger.SetLevel(0) + beego.Run(":8199") +} \ No newline at end of file diff --git a/geg/net/ghttp/performance/client.go b/geg/net/ghttp/performance/client.go index 175b74b76..e34adacf1 100644 --- a/geg/net/ghttp/performance/client.go +++ b/geg/net/ghttp/performance/client.go @@ -19,8 +19,11 @@ func main() { for i := 0; i < clientMax; i++ { wg.Add(1) go func(clientId int) { - for j := 0; j < requestMax; j++ { - if c, e := ghttp.Get("http://127.0.0.1/"); e == nil { + url := "http://127.0.0.1:8199/" + for i := 0; i < requestMax; i++ { + //url = fmt.Sprintf("http://127.0.0.1:8199/%d_%d", clientId, i) + if c, e := ghttp.Get(url); e == nil { + //fmt.Println(string(c.ReadAll())) c.Close() successNum.Add(1) } else { diff --git a/geg/net/ghttp/performance/gf/dynamic.go b/geg/net/ghttp/performance/gf/dynamic.go index ed36c83c2..0ad723f77 100644 --- a/geg/net/ghttp/performance/gf/dynamic.go +++ b/geg/net/ghttp/performance/gf/dynamic.go @@ -7,8 +7,8 @@ import ( func main() { s := g.Server() - s.BindHandler("/dynamic/:name", func(r *ghttp.Request){ - r.Response.Writeln(r.Get("name")) + s.BindHandler("/:name", func(r *ghttp.Request){ + r.Response.Write(r.Get("name")) }) s.SetPort(8199) s.Run() diff --git a/geg/net/ghttp/performance/gf/static.go b/geg/net/ghttp/performance/gf/static.go index be6bc7c4f..3b6c7ec36 100644 --- a/geg/net/ghttp/performance/gf/static.go +++ b/geg/net/ghttp/performance/gf/static.go @@ -8,8 +8,9 @@ import ( func main() { s := g.Server() s.BindHandler("/", func(r *ghttp.Request){ - r.Response.Writeln("哈喽世界!") + r.Response.Write("哈喽世界!") }) + s.EnablePprof() s.SetPort(8199) s.Run() } \ No newline at end of file