gf/beego性能测试

This commit is contained in:
John
2018-05-28 13:21:59 +08:00
parent 02f80ddd9f
commit 9ec69a6d1f
6 changed files with 42 additions and 5 deletions

View File

@ -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 {

View File

@ -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")
}

View File

@ -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")
}

View File

@ -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 {

View File

@ -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()

View File

@ -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()
}