diff --git a/404.html b/404.html index 4d01f171aa1..b7c1854e444 100644 --- a/404.html +++ b/404.html @@ -4,7 +4,7 @@
Map
",id:"map",level:3},{value:"AllMap
",id:"allmap",level:3}];function s(t){const e={a:"a",code:"code",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",...(0,i.a)(),...t.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e.p,{children:"\u5206\u7ec4\u8def\u7531\u662f\u4e1a\u52a1\u9879\u76ee\u4e2d\u4e3b\u8981\u4f7f\u7528\u7684\u8def\u7531\u6ce8\u518c\u65b9\u5f0f\u3002"}),"\n",(0,r.jsx)(e.h2,{id:"\u5206\u7ec4\u8def\u7531",children:"\u5206\u7ec4\u8def\u7531"}),"\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.code,{children:"GoFrame"})," \u6846\u67b6\u652f\u6301\u5206\u7ec4\u8def\u7531\u7684\u6ce8\u518c\u65b9\u5f0f\uff0c\u53ef\u4ee5\u7ed9\u5206\u7ec4\u8def\u7531\u6307\u5b9a\u4e00\u4e2a ",(0,r.jsx)(e.code,{children:"prefix"})," \u524d\u7f00\uff08\u4e5f\u53ef\u4ee5\u76f4\u63a5\u7ed9\u5b9a ",(0,r.jsx)(e.code,{children:"/"})," \u524d\u7f00\uff0c\u8868\u793a\u6ce8\u518c\u5728\u6839\u8def\u7531\u4e0b\uff09\uff0c\u5728\u8be5\u5206\u7ec4\u4e0b\u7684\u6240\u6709\u8def\u7531\u6ce8\u518c\u90fd\u5c06\u6ce8\u518c\u5728\u8be5\u8def\u7531\u524d\u7f00\u4e0b\u3002 ",(0,r.jsx)(e.strong,{children:"\u5206\u7ec4\u8def\u7531\u6ce8\u518c\u65b9\u5f0f\u4e5f\u662f\u63a8\u8350\u7684\u8def\u7531\u6ce8\u518c\u65b9\u5f0f"}),"\u3002"]}),"\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.strong,{children:"\u63a5\u53e3\u6587\u6863"}),"\uff1a ",(0,r.jsx)(e.a,{href:"https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp#RouterGroup",children:"https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp#RouterGroup"})]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:"// \u521b\u5efa\u5206\u7ec4\u8def\u7531\nfunc (s *Server) Group(prefix string, groups ...func(g *RouterGroup)) *RouterGroup\n\n// \u6ce8\u518cMethod\u8def\u7531\nfunc (g *RouterGroup) ALL(pattern string, object interface{}, params...interface{})\nfunc (g *RouterGroup) GET(pattern string, object interface{}, params...interface{})\nfunc (g *RouterGroup) PUT(pattern string, object interface{}, params...interface{})\nfunc (g *RouterGroup) POST(pattern string, object interface{}, params...interface{})\nfunc (g *RouterGroup) DELETE(pattern string, object interface{}, params...interface{})\n...\n\n// \u4e2d\u95f4\u4ef6\u7ed1\u5b9a\nfunc (g *RouterGroup) Middleware(handlers ...HandlerFunc) *RouterGroup\n\n// \u6279\u91cf\u6ce8\u518c\nfunc (g *RouterGroup) Map(m map[string]interface{})\nfunc (g *RouterGroup) ALLMap(m map[string]interface{})\n"})}),"\n",(0,r.jsx)(e.p,{children:(0,r.jsx)(e.strong,{children:"\u7b80\u8981\u4ecb\u7ecd\uff1a"})}),"\n",(0,r.jsxs)(e.ol,{children:["\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:"Group"})," \u65b9\u6cd5\u7528\u4e8e\u521b\u5efa\u4e00\u4e2a\u5206\u7ec4\u8def\u7531\u5bf9\u8c61\uff0c\u5e76\u4e14\u652f\u6301\u5728\u6307\u5b9a\u57df\u540d\u5bf9\u8c61\u4e0a\u521b\u5efa\u3002"]}),"\n",(0,r.jsxs)(e.li,{children:["\u4ee5 ",(0,r.jsx)(e.code,{children:"HTTP Method"})," \u547d\u540d\u7684\u65b9\u6cd5\u7528\u4e8e\u7ed1\u5b9a\u6307\u5b9a\u7684 ",(0,r.jsx)(e.code,{children:"HTTP Method"})," \u8def\u7531\uff1b\u5176\u4e2d ",(0,r.jsx)(e.code,{children:"ALL"})," \u65b9\u6cd5\u7528\u4e8e\u6ce8\u518c\u6240\u6709\u7684 ",(0,r.jsx)(e.code,{children:"HTTP Method"})," \u5230\u6307\u5b9a\u7684\u51fd\u6570/\u5bf9\u8c61/\u63a7\u5236\u5668\u4e0a\uff1b ",(0,r.jsx)(e.code,{children:"REST"})," \u65b9\u6cd5\u7528\u4e8e\u6ce8\u518c ",(0,r.jsx)(e.code,{children:"RESTful"})," \u98ce\u683c\u7684\u8def\u7531\uff0c\u9700\u7ed9\u5b9a\u4e00\u4e2a\u6267\u884c\u5bf9\u8c61\u6216\u8005\u63a7\u5236\u5668\u5bf9\u8c61\u3002"]}),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:"Middleware"})," \u65b9\u6cd5\u7528\u4e8e\u7ed1\u5b9a\u4e00\u4e2a\u6216\u591a\u4e2a\u4e2d\u95f4\u4ef6\u5230\u5f53\u524d\u5206\u7ec4\u7684\u8def\u7531\u4e0a\uff0c\u5177\u4f53\u8be6\u89c1\u4e2d\u95f4\u4ef6\u7ae0\u8282\u3002"]}),"\n"]}),"\n",(0,r.jsx)(e.h2,{id:"\u7b80\u5355\u793a\u4f8b",children:"\u7b80\u5355\u793a\u4f8b"}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:'package main\n\nimport (\n\t"github.com/gogf/gf/v2/frame/g"\n\t"github.com/gogf/gf/v2/net/ghttp"\n)\n\nfunc main() {\n\ts := g.Server()\n\ts.Group("/api", func(group *ghttp.RouterGroup) {\n\t\tgroup.ALL("/all", func(r *ghttp.Request) {\n\t\t\tr.Response.Write("all")\n\t\t})\n\t\tgroup.GET("/get", func(r *ghttp.Request) {\n\t\t\tr.Response.Write("get")\n\t\t})\n\t\tgroup.POST("/post", func(r *ghttp.Request) {\n\t\t\tr.Response.Write("post")\n\t\t})\n\t})\n\ts.SetPort(8199)\n\ts.Run()\n}\n'})}),"\n",(0,r.jsx)(e.p,{children:"\u6267\u884c\u540e\uff0c\u7ec8\u7aef\u6253\u5370\u51fa\u8def\u7531\u8868\u5982\u4e0b\uff1a"}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:"SERVER | DOMAIN | ADDRESS | METHOD | ROUTE | HANDLER | MIDDLEWARE\n|---------|---------|---------|--------|-----------|-----------------|------------|\n default | default | :8199 | ALL | /api/all | main.main.func1 |\n|---------|---------|---------|--------|-----------|-----------------|------------|\n default | default | :8199 | GET | /api/get | main.main.func2 |\n|---------|---------|---------|--------|-----------|-----------------|------------|\n default | default | :8199 | POST | /api/post | main.main.func3 |\n|---------|---------|---------|--------|-----------|-----------------|------------|\n"})}),"\n",(0,r.jsxs)(e.p,{children:["\u5176\u4e2d\uff0c ",(0,r.jsx)(e.code,{children:"/api/get"})," \u4ec5\u5141\u8bb8 ",(0,r.jsx)(e.code,{children:"GET"})," \u65b9\u5f0f\u8bbf\u95ee\uff0c ",(0,r.jsx)(e.code,{children:"/api/post"})," \u4ec5\u5141\u8bb8 ",(0,r.jsx)(e.code,{children:"POST"})," \u65b9\u5f0f\u8bbf\u95ee\uff0c ",(0,r.jsx)(e.code,{children:"/api/all"})," \u5141\u8bb8\u6240\u6709\u7684\u65b9\u5f0f\u8bbf\u95ee\u3002"]}),"\n",(0,r.jsxs)(e.p,{children:["\u6211\u4eec\u4f7f\u7528 ",(0,r.jsx)(e.code,{children:"curl"})," \u5de5\u5177\u6765\u6d4b\u8bd5\u4e00\u4e0b\uff1a"]}),"\n",(0,r.jsxs)(e.ol,{children:["\n",(0,r.jsx)(e.li,{children:(0,r.jsx)(e.code,{children:"/api/get"})}),"\n"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:"$ curl http://127.0.0.1:8199/api/get\nget\n$ curl -X POST http://127.0.0.1:8199/api/get\nNot Found\n"})}),"\n",(0,r.jsxs)(e.ol,{start:"2",children:["\n",(0,r.jsx)(e.li,{children:(0,r.jsx)(e.code,{children:" /api/post"})}),"\n"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:"$ curl http://127.0.0.1:8199/api/post\nNot Found\n$ curl -X POST http://127.0.0.1:8199/api/post post\n"})}),"\n",(0,r.jsxs)(e.ol,{start:"3",children:["\n",(0,r.jsx)(e.li,{children:(0,r.jsx)(e.code,{children:"/api/all"})}),"\n"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:"$ curl http://127.0.0.1:8199/api/all\nall\n$ curl -X POST http://127.0.0.1:8199/api/all\nall\n$ curl -X DELETE http://127.0.0.1:8199/api/all\nall\n$ curl -X OPTIONS http://127.0.0.1:8199/api/all\nall\n"})}),"\n",(0,r.jsx)(e.h2,{id:"\u5c42\u7ea7\u6ce8\u518c",children:"\u5c42\u7ea7\u6ce8\u518c"}),"\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.code,{children:"GoFrame"})," \u6846\u67b6\u7684\u5c42\u7ea7\u8def\u7531\u6ce8\u518c\u65b9\u5f0f\u7075\u611f\u6765\u6e90\u4e8e ",(0,r.jsx)(e.code,{children:"PHP Laravel"})," \u6846\u67b6\u3002",(0,r.jsx)(e.img,{alt:"(\u7728\u773c)",src:n(20920).Z+"",width:"16",height:"16"})]}),"\n",(0,r.jsxs)(e.p,{children:["\u63a8\u8350\u4f7f\u7528\u8def\u7531\u5c42\u7ea7\u6ce8\u518c\u65b9\u5f0f\uff0c\u6ce8\u518c\u7684\u8def\u7531\u4ee3\u7801\u66f4\u6e05\u6670\u76f4\u89c2\u3002 ",(0,r.jsx)(e.code,{children:"GoFrame"})," \u6846\u67b6\u7684\u5206\u7ec4\u8def\u7531\u6ce8\u518c\u652f\u6301\u66f4\u52a0\u76f4\u89c2\u4f18\u96c5\u5c42\u7ea7\u7684\u6ce8\u518c\u65b9\u5f0f\uff0c\u4ee5\u4fbf\u4e8e\u5f00\u53d1\u8005\u66f4\u65b9\u4fbf\u5730\u7ba1\u7406\u8def\u7531\u5217\u8868\u3002\u8def\u7531\u5c42\u7ea7\u6ce8\u518c\u65b9\u5f0f\u4e5f\u662f\u63a8\u8350\u7684\u8def\u7531\u6ce8\u518c\u65b9\u5f0f\u3002\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u6bd4\u8f83\u5b8c\u6574\u7684\u793a\u4f8b\uff0c\u8be5\u793a\u4f8b\u4e2d\u6ce8\u518c\u4e86\u4f7f\u7528\u5230\u4e86\u4e2d\u95f4\u4ef6\u3001 ",(0,r.jsx)(e.code,{children:"HOOK"})," \u4ee5\u53ca\u4e0d\u540c ",(0,r.jsx)(e.code,{children:"HTTP Method"})," \u7ed1\u5b9a\u7684\u8def\u7531\u6ce8\u518c\uff1a"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:'package main\n\nimport (\n\t"net/http"\n\n\t"github.com/gogf/gf/v2/frame/g"\n\t"github.com/gogf/gf/v2/net/ghttp"\n\t"github.com/gogf/gf/v2/util/gconv"\n \t"fmt"\n)\n\nfunc MiddlewareAuth(r *ghttp.Request) {\n\ttoken := r.Get("token")\n\tif gconv.String(token) == "123456" {\n\t\tr.Middleware.Next()\n\t} else {\n\t\tr.Response.WriteStatus(http.StatusForbidden)\n\t}\n}\n\nfunc MiddlewareCORS(r *ghttp.Request) {\n\tr.Response.CORSDefault()\n\tr.Middleware.Next()\n}\n\nfunc MiddlewareLog(r *ghttp.Request) {\n\tr.Middleware.Next()\n\tfmt.Println(r.Response.Status, r.URL.Path)\n}\n\nfunc main() {\n\ts := g.Server()\n\ts.Use(MiddlewareLog)\n\ts.Group("/api.v2", func(group *ghttp.RouterGroup) {\n\t\tgroup.Middleware(MiddlewareAuth, MiddlewareCORS)\n\t\tgroup.GET("/test", func(r *ghttp.Request) {\n\t\t\tr.Response.Write("test")\n\t\t})\n\t\tgroup.Group("/order", func(group *ghttp.RouterGroup) {\n\t\t\tgroup.GET("/list", func(r *ghttp.Request) {\n\t\t\t\tr.Response.Write("list")\n\t\t\t})\n\t\t\tgroup.PUT("/update", func(r *ghttp.Request) {\n\t\t\t\tr.Response.Write("update")\n\t\t\t})\n\t\t})\n\t\tgroup.Group("/user", func(group *ghttp.RouterGroup) {\n\t\t\tgroup.GET("/info", func(r *ghttp.Request) {\n\t\t\t\tr.Response.Write("info")\n\t\t\t})\n\t\t\tgroup.POST("/edit", func(r *ghttp.Request) {\n\t\t\t\tr.Response.Write("edit")\n\t\t\t})\n\t\t\tgroup.DELETE("/drop", func(r *ghttp.Request) {\n\t\t\t\tr.Response.Write("drop")\n\t\t\t})\n\t\t})\n\t\tgroup.Group("/hook", func(group *ghttp.RouterGroup) {\n\t\t\tgroup.Hook("/*", ghttp.HookBeforeServe, func(r *ghttp.Request) {\n\t\t\t\tr.Response.Write("hook any")\n\t\t\t})\n\t\t\tgroup.Hook("/:name", ghttp.HookBeforeServe, func(r *ghttp.Request) {\n\t\t\t\tr.Response.Write("hook name")\n\t\t\t})\n\t\t})\n\t})\n\ts.SetPort(8199)\n\ts.Run()\n}\n'})}),"\n",(0,r.jsx)(e.p,{children:"\u6267\u884c\u540e\uff0c\u6ce8\u518c\u7684\u8def\u7531\u5217\u8868\u5982\u4e0b\uff1a"}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:"SERVER | DOMAIN | ADDRESS | METHOD | ROUTE | HANDLER | MIDDLEWARE\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | ALL | /* | main.MiddlewareLog | GLOBAL MIDDLEWARE\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | ALL | /api.v2/hook/* | main.main.func1.4.1 | HOOK_BEFORE_SERVE\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | ALL | /api.v2/hook/:name | main.main.func1.4.2 | HOOK_BEFORE_SERVE\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | GET | /api.v2/order/list | main.main.func1.2.1 | main.MiddlewareAuth,main.MiddlewareCORS\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | PUT | /api.v2/order/update | main.main.func1.2.2 | main.MiddlewareAuth,main.MiddlewareCORS\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | GET | /api.v2/test | main.main.func1.1 | main.MiddlewareAuth,main.MiddlewareCORS\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | DELETE | /api.v2/user/drop | main.main.func1.3.3 | main.MiddlewareAuth,main.MiddlewareCORS\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | POST | /api.v2/user/edit | main.main.func1.3.2 | main.MiddlewareAuth,main.MiddlewareCORS\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | GET | /api.v2/user/info | main.main.func1.3.1 | main.MiddlewareAuth,main.MiddlewareCORS\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n"})}),"\n",(0,r.jsx)(e.h2,{id:"\u6279\u91cf\u6ce8\u518c",children:"\u6279\u91cf\u6ce8\u518c"}),"\n",(0,r.jsx)(e.h3,{id:"map",children:(0,r.jsx)(e.code,{children:"Map"})}),"\n",(0,r.jsxs)(e.p,{children:["\u901a\u8fc7 ",(0,r.jsx)(e.code,{children:"Map"})," \u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u6279\u91cf\u7684\u5206\u7ec4\u8def\u7531\u6ce8\u518c\uff0c\u4f46\u662f\u5982\u679c\u662f\u76f8\u540c\u7684 ",(0,r.jsx)(e.code,{children:"URI"})," \u4e0d\u540c\u7684 ",(0,r.jsx)(e.code,{children:"HTTP Method"})," \u9700\u8981\u6309\u7167\u8def\u7531\u89c4\u8303\u7ed9\u5b9a ",(0,r.jsx)(e.code,{children:"HTTP Method"}),"\u3002\u4f7f\u7528\u793a\u4f8b\uff1a"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:'package main\n\nimport (\n\t"github.com/gogf/gf/v2/frame/g"\n\t"github.com/gogf/gf/v2/net/ghttp"\n)\n\nfunc UserGet(r *ghttp.Request) {\n\tr.Response.Write("get")\n}\n\nfunc UserDelete(r *ghttp.Request) {\n\tr.Response.Write("delete")\n}\n\nfunc main() {\n\ts := g.Server()\n\ts.Group("/api", func(group *ghttp.RouterGroup) {\n\t\tgroup.Map(g.Map{\n\t\t\t"GET: /user": UserGet,\n\t\t\t"DELETE: /user": UserDelete,\n\t\t})\n\t})\n\ts.SetPort(8199)\n\ts.Run()\n}\n'})}),"\n",(0,r.jsx)(e.h3,{id:"allmap",children:(0,r.jsx)(e.code,{children:"AllMap"})}),"\n",(0,r.jsxs)(e.p,{children:["\u4e5f\u53ef\u4ee5\u4f7f\u7528 ",(0,r.jsx)(e.code,{children:"ALLMap"})," \u65b9\u6cd5\u5b9e\u73b0\u6279\u91cf\u7684\u5206\u7ec4\u8def\u7531\u6ce8\u518c\uff0c\u901a\u8fc7\u8be5\u65b9\u6cd5\u6ce8\u518c\u7684\u8def\u7531\u5c06\u628a\u8def\u7531\u51fd\u6570/\u5bf9\u8c61\u5e94\u7528\u5230\u6240\u6709\u7684 ",(0,r.jsx)(e.code,{children:"HTTP Method"}),"\u3002\u4f7f\u7528\u793a\u4f8b\uff1a"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:'s := g.Server()\n// \u524d\u53f0\u7cfb\u7edf\u8def\u7531\u6ce8\u518c\ns.Group("/", func(group *ghttp.RouterGroup) {\n\tgroup.Middleware(service.Middleware.Ctx)\n\tgroup.ALLMap(g.Map{\n\t\t"/": api.Index, // \u9996\u9875\n\t\t"/login": api.Login, // \u767b\u5f55\n\t\t"/register": api.Register, // \u6ce8\u518c\n\t\t"/category": api.Category, // \u680f\u76ee\n\t\t"/topic": api.Topic, // \u4e3b\u9898\n\t\t"/topic/:id": api.Topic.Detail, // \u4e3b\u9898 - \u8be6\u60c5\n\t\t"/ask": api.Ask, // \u95ee\u7b54\n\t\t"/ask/:id": api.Ask.Detail, // \u95ee\u7b54 - \u8be6\u60c5\n\t\t"/article": api.Article, // \u6587\u7ae0\n\t\t"/article/:id": api.Article.Detail, // \u6587\u7ae0 - \u8be6\u60c5\n\t\t"/reply": api.Reply, // \u56de\u590d\n\t\t"/search": api.Search, // \u641c\u7d22\n\t\t"/captcha": api.Captcha, // \u9a8c\u8bc1\u7801\n\t\t"/user/:id": api.User.Index, // \u7528\u6237 - \u4e3b\u9875\n\t})\n\t// \u6743\u9650\u63a7\u5236\u8def\u7531\n\tgroup.Group("/", func(group *ghttp.RouterGroup) {\n\t\tgroup.Middleware(service.Middleware.Auth)\n\t\tgroup.ALLMap(g.Map{\n\t\t\t"/user": api.User, // \u7528\u6237\n\t\t\t"/content": api.Content, // \u5185\u5bb9\n\t\t\t"/interact": api.Interact, // \u4ea4\u4e92\n\t\t\t"/file": api.File, // \u6587\u4ef6\n\t\t})\n\t})\n})\n'})})]})}function p(t={}){const{wrapper:e}={...(0,i.a)(),...t.components};return e?(0,r.jsx)(e,{...t,children:(0,r.jsx)(s,{...t})}):s(t)}},20920:(t,e,n)=>{n.d(e,{Z:()=>r});const r="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxkZWZzPjxwYXRoIGlkPSJhIiBkPSJNMCAxNmgxNlYwSDB6Ii8+PC9kZWZzPjxnIHRyYW5zZm9ybT0ibWF0cml4KDEgMCAwIC0xIDAgMTYpIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjxtYXNrIGlkPSJiIiBmaWxsPSIjZmZmIj48dXNlIHhsaW5rOmhyZWY9IiNhIi8+PC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wNC0uMDAzLS40NS0uMzg0LTIuMDctLjM4NC0xLjYxOCAwLTIuMDY0LjM4LTIuMDY1LjM4YS4yMjMuMjIzIDAgMCAxLS4zNzMtLjIxMWMuMDA1LS4wMi41MS0xLjk0NyAyLjQzOC0xLjk0NyAxLjkyOSAwIDIuNDMzIDEuOTI3IDIuNDM4IDEuOTQ3YS4yMi4yMiAwIDAgMS0uMTAzLjI0MSIgZmlsbD0iIzY2NDUwMCIvPjwvZz48L2c+PC9zdmc+"},11151:(t,e,n)=>{n.d(e,{Z:()=>d,a:()=>a});var r=n(67294);const i={},o=r.createContext(i);function a(t){const e=r.useContext(o);return r.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function d(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(i):t.components||i:a(t.components),r.createElement(o.Provider,{value:e},t.children)}}}]);
\ No newline at end of file
+"use strict";(self.webpackChunkgfdoc=self.webpackChunkgfdoc||[]).push([[86360],{8256:(t,e,n)=>{n.r(e),n.d(e,{assets:()=>u,contentTitle:()=>a,default:()=>p,frontMatter:()=>o,metadata:()=>d,toc:()=>c});var r=n(85893),i=n(11151);const o={title:"\u8def\u7531\u6ce8\u518c-\u5206\u7ec4\u8def\u7531",sidebar_position:2},a=void 0,d={id:"WEB\u670d\u52a1\u5f00\u53d1/\u8def\u7531\u7ba1\u7406/\u8def\u7531\u7ba1\u7406-\u8def\u7531\u6ce8\u518c/\u8def\u7531\u6ce8\u518c-\u5206\u7ec4\u8def\u7531",title:"\u8def\u7531\u6ce8\u518c-\u5206\u7ec4\u8def\u7531",description:"\u5206\u7ec4\u8def\u7531\u662f\u4e1a\u52a1\u9879\u76ee\u4e2d\u4e3b\u8981\u4f7f\u7528\u7684\u8def\u7531\u6ce8\u518c\u65b9\u5f0f\u3002",source:"@site/docs/7-WEB\u670d\u52a1\u5f00\u53d1/1-\u8def\u7531\u7ba1\u7406/1-\u8def\u7531\u7ba1\u7406-\u8def\u7531\u6ce8\u518c/2-\u8def\u7531\u6ce8\u518c-\u5206\u7ec4\u8def\u7531.md",sourceDirName:"7-WEB\u670d\u52a1\u5f00\u53d1/1-\u8def\u7531\u7ba1\u7406/1-\u8def\u7531\u7ba1\u7406-\u8def\u7531\u6ce8\u518c",slug:"/WEB\u670d\u52a1\u5f00\u53d1/\u8def\u7531\u7ba1\u7406/\u8def\u7531\u7ba1\u7406-\u8def\u7531\u6ce8\u518c/\u8def\u7531\u6ce8\u518c-\u5206\u7ec4\u8def\u7531",permalink:"/docs/WEB\u670d\u52a1\u5f00\u53d1/\u8def\u7531\u7ba1\u7406/\u8def\u7531\u7ba1\u7406-\u8def\u7531\u6ce8\u518c/\u8def\u7531\u6ce8\u518c-\u5206\u7ec4\u8def\u7531",draft:!1,unlisted:!1,tags:[],version:"current",sidebarPosition:2,frontMatter:{title:"\u8def\u7531\u6ce8\u518c-\u5206\u7ec4\u8def\u7531",sidebar_position:2},sidebar:"tutorialSidebar",previous:{title:"\u8def\u7531\u6ce8\u518c-\u5bf9\u8c61\u6ce8\u518c",permalink:"/docs/WEB\u670d\u52a1\u5f00\u53d1/\u8def\u7531\u7ba1\u7406/\u8def\u7531\u7ba1\u7406-\u8def\u7531\u6ce8\u518c/\u8def\u7531\u6ce8\u518c-\u5bf9\u8c61\u6ce8\u518c"},next:{title:"\u8def\u7531\u6ce8\u518c-\u89c4\u8303\u8def\u7531",permalink:"/docs/WEB\u670d\u52a1\u5f00\u53d1/\u8def\u7531\u7ba1\u7406/\u8def\u7531\u7ba1\u7406-\u8def\u7531\u6ce8\u518c/\u8def\u7531\u6ce8\u518c-\u89c4\u8303\u8def\u7531/"}},u={},c=[{value:"\u5206\u7ec4\u8def\u7531",id:"\u5206\u7ec4\u8def\u7531",level:2},{value:"\u7b80\u5355\u793a\u4f8b",id:"\u7b80\u5355\u793a\u4f8b",level:2},{value:"\u5c42\u7ea7\u6ce8\u518c",id:"\u5c42\u7ea7\u6ce8\u518c",level:2},{value:"\u6279\u91cf\u6ce8\u518c",id:"\u6279\u91cf\u6ce8\u518c",level:2},{value:"Map
",id:"map",level:3},{value:"AllMap
",id:"allmap",level:3}];function s(t){const e={a:"a",code:"code",h2:"h2",h3:"h3",img:"img",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",...(0,i.a)(),...t.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e.p,{children:"\u5206\u7ec4\u8def\u7531\u662f\u4e1a\u52a1\u9879\u76ee\u4e2d\u4e3b\u8981\u4f7f\u7528\u7684\u8def\u7531\u6ce8\u518c\u65b9\u5f0f\u3002"}),"\n",(0,r.jsx)(e.h2,{id:"\u5206\u7ec4\u8def\u7531",children:"\u5206\u7ec4\u8def\u7531"}),"\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.code,{children:"GoFrame"})," \u6846\u67b6\u652f\u6301\u5206\u7ec4\u8def\u7531\u7684\u6ce8\u518c\u65b9\u5f0f\uff0c\u53ef\u4ee5\u7ed9\u5206\u7ec4\u8def\u7531\u6307\u5b9a\u4e00\u4e2a ",(0,r.jsx)(e.code,{children:"prefix"})," \u524d\u7f00\uff08\u4e5f\u53ef\u4ee5\u76f4\u63a5\u7ed9\u5b9a ",(0,r.jsx)(e.code,{children:"/"})," \u524d\u7f00\uff0c\u8868\u793a\u6ce8\u518c\u5728\u6839\u8def\u7531\u4e0b\uff09\uff0c\u5728\u8be5\u5206\u7ec4\u4e0b\u7684\u6240\u6709\u8def\u7531\u6ce8\u518c\u90fd\u5c06\u6ce8\u518c\u5728\u8be5\u8def\u7531\u524d\u7f00\u4e0b\u3002 ",(0,r.jsx)(e.strong,{children:"\u5206\u7ec4\u8def\u7531\u6ce8\u518c\u65b9\u5f0f\u4e5f\u662f\u63a8\u8350\u7684\u8def\u7531\u6ce8\u518c\u65b9\u5f0f"}),"\u3002"]}),"\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.strong,{children:"\u63a5\u53e3\u6587\u6863"}),"\uff1a ",(0,r.jsx)(e.a,{href:"https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp#RouterGroup",children:"https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp#RouterGroup"})]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:"// \u521b\u5efa\u5206\u7ec4\u8def\u7531\nfunc (s *Server) Group(prefix string, groups ...func(g *RouterGroup)) *RouterGroup\n\n// \u6ce8\u518cMethod\u8def\u7531\nfunc (g *RouterGroup) ALL(pattern string, object interface{}, params...interface{})\nfunc (g *RouterGroup) GET(pattern string, object interface{}, params...interface{})\nfunc (g *RouterGroup) PUT(pattern string, object interface{}, params...interface{})\nfunc (g *RouterGroup) POST(pattern string, object interface{}, params...interface{})\nfunc (g *RouterGroup) DELETE(pattern string, object interface{}, params...interface{})\n...\n\n// \u4e2d\u95f4\u4ef6\u7ed1\u5b9a\nfunc (g *RouterGroup) Middleware(handlers ...HandlerFunc) *RouterGroup\n\n// \u6279\u91cf\u6ce8\u518c\nfunc (g *RouterGroup) Map(m map[string]interface{})\nfunc (g *RouterGroup) ALLMap(m map[string]interface{})\n"})}),"\n",(0,r.jsx)(e.p,{children:(0,r.jsx)(e.strong,{children:"\u7b80\u8981\u4ecb\u7ecd\uff1a"})}),"\n",(0,r.jsxs)(e.ol,{children:["\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:"Group"})," \u65b9\u6cd5\u7528\u4e8e\u521b\u5efa\u4e00\u4e2a\u5206\u7ec4\u8def\u7531\u5bf9\u8c61\uff0c\u5e76\u4e14\u652f\u6301\u5728\u6307\u5b9a\u57df\u540d\u5bf9\u8c61\u4e0a\u521b\u5efa\u3002"]}),"\n",(0,r.jsxs)(e.li,{children:["\u4ee5 ",(0,r.jsx)(e.code,{children:"HTTP Method"})," \u547d\u540d\u7684\u65b9\u6cd5\u7528\u4e8e\u7ed1\u5b9a\u6307\u5b9a\u7684 ",(0,r.jsx)(e.code,{children:"HTTP Method"})," \u8def\u7531\uff1b\u5176\u4e2d ",(0,r.jsx)(e.code,{children:"ALL"})," \u65b9\u6cd5\u7528\u4e8e\u6ce8\u518c\u6240\u6709\u7684 ",(0,r.jsx)(e.code,{children:"HTTP Method"})," \u5230\u6307\u5b9a\u7684\u51fd\u6570/\u5bf9\u8c61/\u63a7\u5236\u5668\u4e0a\uff1b ",(0,r.jsx)(e.code,{children:"REST"})," \u65b9\u6cd5\u7528\u4e8e\u6ce8\u518c ",(0,r.jsx)(e.code,{children:"RESTful"})," \u98ce\u683c\u7684\u8def\u7531\uff0c\u9700\u7ed9\u5b9a\u4e00\u4e2a\u6267\u884c\u5bf9\u8c61\u6216\u8005\u63a7\u5236\u5668\u5bf9\u8c61\u3002"]}),"\n",(0,r.jsxs)(e.li,{children:[(0,r.jsx)(e.code,{children:"Middleware"})," \u65b9\u6cd5\u7528\u4e8e\u7ed1\u5b9a\u4e00\u4e2a\u6216\u591a\u4e2a\u4e2d\u95f4\u4ef6\u5230\u5f53\u524d\u5206\u7ec4\u7684\u8def\u7531\u4e0a\uff0c\u5177\u4f53\u8be6\u89c1\u4e2d\u95f4\u4ef6\u7ae0\u8282\u3002"]}),"\n"]}),"\n",(0,r.jsx)(e.h2,{id:"\u7b80\u5355\u793a\u4f8b",children:"\u7b80\u5355\u793a\u4f8b"}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:'package main\n\nimport (\n\t"github.com/gogf/gf/v2/frame/g"\n\t"github.com/gogf/gf/v2/net/ghttp"\n)\n\nfunc main() {\n\ts := g.Server()\n\ts.Group("/api", func(group *ghttp.RouterGroup) {\n\t\tgroup.ALL("/all", func(r *ghttp.Request) {\n\t\t\tr.Response.Write("all")\n\t\t})\n\t\tgroup.GET("/get", func(r *ghttp.Request) {\n\t\t\tr.Response.Write("get")\n\t\t})\n\t\tgroup.POST("/post", func(r *ghttp.Request) {\n\t\t\tr.Response.Write("post")\n\t\t})\n\t})\n\ts.SetPort(8199)\n\ts.Run()\n}\n'})}),"\n",(0,r.jsx)(e.p,{children:"\u6267\u884c\u540e\uff0c\u7ec8\u7aef\u6253\u5370\u51fa\u8def\u7531\u8868\u5982\u4e0b\uff1a"}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:"SERVER | DOMAIN | ADDRESS | METHOD | ROUTE | HANDLER | MIDDLEWARE\n|---------|---------|---------|--------|-----------|-----------------|------------|\n default | default | :8199 | ALL | /api/all | main.main.func1 |\n|---------|---------|---------|--------|-----------|-----------------|------------|\n default | default | :8199 | GET | /api/get | main.main.func2 |\n|---------|---------|---------|--------|-----------|-----------------|------------|\n default | default | :8199 | POST | /api/post | main.main.func3 |\n|---------|---------|---------|--------|-----------|-----------------|------------|\n"})}),"\n",(0,r.jsxs)(e.p,{children:["\u5176\u4e2d\uff0c ",(0,r.jsx)(e.code,{children:"/api/get"})," \u4ec5\u5141\u8bb8 ",(0,r.jsx)(e.code,{children:"GET"})," \u65b9\u5f0f\u8bbf\u95ee\uff0c ",(0,r.jsx)(e.code,{children:"/api/post"})," \u4ec5\u5141\u8bb8 ",(0,r.jsx)(e.code,{children:"POST"})," \u65b9\u5f0f\u8bbf\u95ee\uff0c ",(0,r.jsx)(e.code,{children:"/api/all"})," \u5141\u8bb8\u6240\u6709\u7684\u65b9\u5f0f\u8bbf\u95ee\u3002"]}),"\n",(0,r.jsxs)(e.p,{children:["\u6211\u4eec\u4f7f\u7528 ",(0,r.jsx)(e.code,{children:"curl"})," \u5de5\u5177\u6765\u6d4b\u8bd5\u4e00\u4e0b\uff1a"]}),"\n",(0,r.jsxs)(e.ol,{children:["\n",(0,r.jsx)(e.li,{children:(0,r.jsx)(e.code,{children:"/api/get"})}),"\n"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:"$ curl http://127.0.0.1:8199/api/get\nget\n$ curl -X POST http://127.0.0.1:8199/api/get\nNot Found\n"})}),"\n",(0,r.jsxs)(e.ol,{start:"2",children:["\n",(0,r.jsx)(e.li,{children:(0,r.jsx)(e.code,{children:" /api/post"})}),"\n"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:"$ curl http://127.0.0.1:8199/api/post\nNot Found\n$ curl -X POST http://127.0.0.1:8199/api/post post\n"})}),"\n",(0,r.jsxs)(e.ol,{start:"3",children:["\n",(0,r.jsx)(e.li,{children:(0,r.jsx)(e.code,{children:"/api/all"})}),"\n"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:"$ curl http://127.0.0.1:8199/api/all\nall\n$ curl -X POST http://127.0.0.1:8199/api/all\nall\n$ curl -X DELETE http://127.0.0.1:8199/api/all\nall\n$ curl -X OPTIONS http://127.0.0.1:8199/api/all\nall\n"})}),"\n",(0,r.jsx)(e.h2,{id:"\u5c42\u7ea7\u6ce8\u518c",children:"\u5c42\u7ea7\u6ce8\u518c"}),"\n",(0,r.jsxs)(e.p,{children:[(0,r.jsx)(e.code,{children:"GoFrame"})," \u6846\u67b6\u7684\u5c42\u7ea7\u8def\u7531\u6ce8\u518c\u65b9\u5f0f\u7075\u611f\u6765\u6e90\u4e8e ",(0,r.jsx)(e.code,{children:"PHP Laravel"})," \u6846\u67b6\u3002",(0,r.jsx)(e.img,{alt:"(\u7728\u773c)",src:n(20920).Z+"",width:"16",height:"16"})]}),"\n",(0,r.jsxs)(e.p,{children:["\u63a8\u8350\u4f7f\u7528\u8def\u7531\u5c42\u7ea7\u6ce8\u518c\u65b9\u5f0f\uff0c\u6ce8\u518c\u7684\u8def\u7531\u4ee3\u7801\u66f4\u6e05\u6670\u76f4\u89c2\u3002 ",(0,r.jsx)(e.code,{children:"GoFrame"})," \u6846\u67b6\u7684\u5206\u7ec4\u8def\u7531\u6ce8\u518c\u652f\u6301\u66f4\u52a0\u76f4\u89c2\u4f18\u96c5\u5c42\u7ea7\u7684\u6ce8\u518c\u65b9\u5f0f\uff0c\u4ee5\u4fbf\u4e8e\u5f00\u53d1\u8005\u66f4\u65b9\u4fbf\u5730\u7ba1\u7406\u8def\u7531\u5217\u8868\u3002\u8def\u7531\u5c42\u7ea7\u6ce8\u518c\u65b9\u5f0f\u4e5f\u662f\u63a8\u8350\u7684\u8def\u7531\u6ce8\u518c\u65b9\u5f0f\u3002\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u6bd4\u8f83\u5b8c\u6574\u7684\u793a\u4f8b\uff0c\u8be5\u793a\u4f8b\u4e2d\u6ce8\u518c\u4e86\u4f7f\u7528\u5230\u4e86\u4e2d\u95f4\u4ef6\u3001 ",(0,r.jsx)(e.code,{children:"HOOK"})," \u4ee5\u53ca\u4e0d\u540c ",(0,r.jsx)(e.code,{children:"HTTP Method"})," \u7ed1\u5b9a\u7684\u8def\u7531\u6ce8\u518c\uff1a"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:'package main\n\nimport (\n\t"fmt"\n\t"net/http"\n\n\t"github.com/gogf/gf/v2/frame/g"\n\t"github.com/gogf/gf/v2/net/ghttp"\n)\n\nfunc MiddlewareAuth(r *ghttp.Request) {\n\tif r.Get("token").String() != "123456" {\n\t\tr.Response.WriteStatus(http.StatusForbidden)\n\t\treturn\n\t}\n\tr.Middleware.Next()\n}\n\nfunc MiddlewareCORS(r *ghttp.Request) {\n\tr.Response.CORSDefault()\n\tr.Middleware.Next()\n}\n\nfunc MiddlewareLog(r *ghttp.Request) {\n\tr.Middleware.Next()\n\tfmt.Println(r.Response.Status, r.URL.Path)\n}\n\nfunc main() {\n\ts := g.Server()\n\ts.Use(MiddlewareLog)\n\ts.Group("/api.v2", func(group *ghttp.RouterGroup) {\n\t\tgroup.Middleware(MiddlewareAuth, MiddlewareCORS)\n\t\tgroup.GET("/test", func(r *ghttp.Request) {\n\t\t\tr.Response.Write("test")\n\t\t})\n\t\tgroup.Group("/order", func(group *ghttp.RouterGroup) {\n\t\t\tgroup.GET("/list", func(r *ghttp.Request) {\n\t\t\t\tr.Response.Write("list")\n\t\t\t})\n\t\t\tgroup.PUT("/update", func(r *ghttp.Request) {\n\t\t\t\tr.Response.Write("update")\n\t\t\t})\n\t\t})\n\t\tgroup.Group("/user", func(group *ghttp.RouterGroup) {\n\t\t\tgroup.GET("/info", func(r *ghttp.Request) {\n\t\t\t\tr.Response.Write("info")\n\t\t\t})\n\t\t\tgroup.POST("/edit", func(r *ghttp.Request) {\n\t\t\t\tr.Response.Write("edit")\n\t\t\t})\n\t\t\tgroup.DELETE("/drop", func(r *ghttp.Request) {\n\t\t\t\tr.Response.Write("drop")\n\t\t\t})\n\t\t})\n\t\tgroup.Group("/hook", func(group *ghttp.RouterGroup) {\n\t\t\tgroup.Hook("/*", ghttp.HookBeforeServe, func(r *ghttp.Request) {\n\t\t\t\tr.Response.Write("hook any")\n\t\t\t})\n\t\t\tgroup.Hook("/:name", ghttp.HookBeforeServe, func(r *ghttp.Request) {\n\t\t\t\tr.Response.Write("hook name")\n\t\t\t})\n\t\t})\n\t})\n\ts.SetPort(8199)\n\ts.Run()\n}\n'})}),"\n",(0,r.jsx)(e.p,{children:"\u6267\u884c\u540e\uff0c\u6ce8\u518c\u7684\u8def\u7531\u5217\u8868\u5982\u4e0b\uff1a"}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:"SERVER | DOMAIN | ADDRESS | METHOD | ROUTE | HANDLER | MIDDLEWARE\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | ALL | /* | main.MiddlewareLog | GLOBAL MIDDLEWARE\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | ALL | /api.v2/hook/* | main.main.func1.4.1 | HOOK_BEFORE_SERVE\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | ALL | /api.v2/hook/:name | main.main.func1.4.2 | HOOK_BEFORE_SERVE\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | GET | /api.v2/order/list | main.main.func1.2.1 | main.MiddlewareAuth,main.MiddlewareCORS\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | PUT | /api.v2/order/update | main.main.func1.2.2 | main.MiddlewareAuth,main.MiddlewareCORS\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | GET | /api.v2/test | main.main.func1.1 | main.MiddlewareAuth,main.MiddlewareCORS\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | DELETE | /api.v2/user/drop | main.main.func1.3.3 | main.MiddlewareAuth,main.MiddlewareCORS\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | POST | /api.v2/user/edit | main.main.func1.3.2 | main.MiddlewareAuth,main.MiddlewareCORS\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n default | default | :8199 | GET | /api.v2/user/info | main.main.func1.3.1 | main.MiddlewareAuth,main.MiddlewareCORS\n|---------|---------|---------|--------|----------------------|---------------------|-----------------------------------------|\n"})}),"\n",(0,r.jsx)(e.h2,{id:"\u6279\u91cf\u6ce8\u518c",children:"\u6279\u91cf\u6ce8\u518c"}),"\n",(0,r.jsx)(e.h3,{id:"map",children:(0,r.jsx)(e.code,{children:"Map"})}),"\n",(0,r.jsxs)(e.p,{children:["\u901a\u8fc7 ",(0,r.jsx)(e.code,{children:"Map"})," \u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u6279\u91cf\u7684\u5206\u7ec4\u8def\u7531\u6ce8\u518c\uff0c\u4f46\u662f\u5982\u679c\u662f\u76f8\u540c\u7684 ",(0,r.jsx)(e.code,{children:"URI"})," \u4e0d\u540c\u7684 ",(0,r.jsx)(e.code,{children:"HTTP Method"})," \u9700\u8981\u6309\u7167\u8def\u7531\u89c4\u8303\u7ed9\u5b9a ",(0,r.jsx)(e.code,{children:"HTTP Method"}),"\u3002\u4f7f\u7528\u793a\u4f8b\uff1a"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:'package main\n\nimport (\n\t"github.com/gogf/gf/v2/frame/g"\n\t"github.com/gogf/gf/v2/net/ghttp"\n)\n\nfunc UserGet(r *ghttp.Request) {\n\tr.Response.Write("get")\n}\n\nfunc UserDelete(r *ghttp.Request) {\n\tr.Response.Write("delete")\n}\n\nfunc main() {\n\ts := g.Server()\n\ts.Group("/api", func(group *ghttp.RouterGroup) {\n\t\tgroup.Map(g.Map{\n\t\t\t"GET: /user": UserGet,\n\t\t\t"DELETE: /user": UserDelete,\n\t\t})\n\t})\n\ts.SetPort(8199)\n\ts.Run()\n}\n'})}),"\n",(0,r.jsx)(e.h3,{id:"allmap",children:(0,r.jsx)(e.code,{children:"AllMap"})}),"\n",(0,r.jsxs)(e.p,{children:["\u4e5f\u53ef\u4ee5\u4f7f\u7528 ",(0,r.jsx)(e.code,{children:"ALLMap"})," \u65b9\u6cd5\u5b9e\u73b0\u6279\u91cf\u7684\u5206\u7ec4\u8def\u7531\u6ce8\u518c\uff0c\u901a\u8fc7\u8be5\u65b9\u6cd5\u6ce8\u518c\u7684\u8def\u7531\u5c06\u628a\u8def\u7531\u51fd\u6570/\u5bf9\u8c61\u5e94\u7528\u5230\u6240\u6709\u7684 ",(0,r.jsx)(e.code,{children:"HTTP Method"}),"\u3002\u4f7f\u7528\u793a\u4f8b\uff1a"]}),"\n",(0,r.jsx)(e.pre,{children:(0,r.jsx)(e.code,{children:'s := g.Server()\n// \u524d\u53f0\u7cfb\u7edf\u8def\u7531\u6ce8\u518c\ns.Group("/", func(group *ghttp.RouterGroup) {\n\tgroup.Middleware(service.Middleware.Ctx)\n\tgroup.ALLMap(g.Map{\n\t\t"/": api.Index, // \u9996\u9875\n\t\t"/login": api.Login, // \u767b\u5f55\n\t\t"/register": api.Register, // \u6ce8\u518c\n\t\t"/category": api.Category, // \u680f\u76ee\n\t\t"/topic": api.Topic, // \u4e3b\u9898\n\t\t"/topic/:id": api.Topic.Detail, // \u4e3b\u9898 - \u8be6\u60c5\n\t\t"/ask": api.Ask, // \u95ee\u7b54\n\t\t"/ask/:id": api.Ask.Detail, // \u95ee\u7b54 - \u8be6\u60c5\n\t\t"/article": api.Article, // \u6587\u7ae0\n\t\t"/article/:id": api.Article.Detail, // \u6587\u7ae0 - \u8be6\u60c5\n\t\t"/reply": api.Reply, // \u56de\u590d\n\t\t"/search": api.Search, // \u641c\u7d22\n\t\t"/captcha": api.Captcha, // \u9a8c\u8bc1\u7801\n\t\t"/user/:id": api.User.Index, // \u7528\u6237 - \u4e3b\u9875\n\t})\n\t// \u6743\u9650\u63a7\u5236\u8def\u7531\n\tgroup.Group("/", func(group *ghttp.RouterGroup) {\n\t\tgroup.Middleware(service.Middleware.Auth)\n\t\tgroup.ALLMap(g.Map{\n\t\t\t"/user": api.User, // \u7528\u6237\n\t\t\t"/content": api.Content, // \u5185\u5bb9\n\t\t\t"/interact": api.Interact, // \u4ea4\u4e92\n\t\t\t"/file": api.File, // \u6587\u4ef6\n\t\t})\n\t})\n})\n'})})]})}function p(t={}){const{wrapper:e}={...(0,i.a)(),...t.components};return e?(0,r.jsx)(e,{...t,children:(0,r.jsx)(s,{...t})}):s(t)}},20920:(t,e,n)=>{n.d(e,{Z:()=>r});const r="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxkZWZzPjxwYXRoIGlkPSJhIiBkPSJNMCAxNmgxNlYwSDB6Ii8+PC9kZWZzPjxnIHRyYW5zZm9ybT0ibWF0cml4KDEgMCAwIC0xIDAgMTYpIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjxtYXNrIGlkPSJiIiBmaWxsPSIjZmZmIj48dXNlIHhsaW5rOmhyZWY9IiNhIi8+PC9tYXNrPjxnIG1hc2s9InVybCgjYikiIGZpbGwtcnVsZT0ibm9uemVybyI+PHBhdGggZD0iTTE2IDhBOC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uMjIzIDAgMCAxLS4zNzMtLjIxMWMuMDA1LS4wMi41MS0xLjk0NyAyLjQzOC0xLjk0NyAxLjkyOSAwIDIuNDMzIDEuOTI3IDIuNDM4IDEuOTQ3YS4yMi4yMiAwIDAgMS0uMTAzLjI0MSIgZmlsbD0iIzY2NDUwMCIvPjwvZz48L2c+PC9zdmc+"},11151:(t,e,n)=>{n.d(e,{Z:()=>d,a:()=>a});var r=n(67294);const i={},o=r.createContext(i);function a(t){const e=r.useContext(o);return r.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function d(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(i):t.components||i:a(t.components),r.createElement(o.Provider,{value:e},t.children)}}}]);
\ No newline at end of file
diff --git a/assets/js/c2bc84e4.1405cdbe.js b/assets/js/c2bc84e4.1405cdbe.js
deleted file mode 100644
index a513282846a..00000000000
--- a/assets/js/c2bc84e4.1405cdbe.js
+++ /dev/null
@@ -1 +0,0 @@
-"use strict";(self.webpackChunkgfdoc=self.webpackChunkgfdoc||[]).push([[9847],{29453:(e,n,o)=>{o.r(n),o.d(n,{assets:()=>d,contentTitle:()=>s,default:()=>g,frontMatter:()=>i,metadata:()=>c,toc:()=>l});var r=o(85893),t=o(11151);const i={title:"PProf\u670d\u52a1\u6027\u80fd\u5206\u6790",sidebar_position:9},s=void 0,c={id:"WEB\u670d\u52a1\u5f00\u53d1/\u9ad8\u7ea7\u7279\u6027/PProf\u670d\u52a1\u6027\u80fd\u5206\u6790",title:"PProf\u670d\u52a1\u6027\u80fd\u5206\u6790",description:"GoFrame \u6846\u67b6\u7684 Web Server \u63d0\u4f9b\u4e86\u975e\u5e38\u5f3a\u5927\u548c\u7b80\u4fbf\u7684\u670d\u52a1\u6027\u80fd\u5206\u6790\u529f\u80fd\uff0c\u5185\u90e8\u5b8c\u7f8e\u96c6\u6210\u4e86 pprof \u6027\u80fd\u5206\u6790\u5de5\u5177\uff0c\u53ef\u4ee5\u5728\u4efb\u4f55\u65f6\u5019\u901a\u8fc7 EnablePProf \u65b9\u6cd5\u542f\u7528\u6027\u80fd\u5206\u6790\u7279\u6027\uff0c\u5e76\u53ef\u81ea\u5b9a\u4e49\u6027\u80fd\u5206\u6790\u5de5\u5177\u9875\u9762\u8def\u7531\u5730\u5740\uff0c\u4e0d\u4f20\u9012\u8def\u7531\u5730\u5740\u65f6\uff0c\u9ed8\u8ba4URI\u5730\u5740\u4e3a /debug/pprof\u3002",source:"@site/docs/7-WEB\u670d\u52a1\u5f00\u53d1/11-\u9ad8\u7ea7\u7279\u6027/9-PProf\u670d\u52a1\u6027\u80fd\u5206\u6790.md",sourceDirName:"7-WEB\u670d\u52a1\u5f00\u53d1/11-\u9ad8\u7ea7\u7279\u6027",slug:"/WEB\u670d\u52a1\u5f00\u53d1/\u9ad8\u7ea7\u7279\u6027/PProf\u670d\u52a1\u6027\u80fd\u5206\u6790",permalink:"/docs/WEB\u670d\u52a1\u5f00\u53d1/\u9ad8\u7ea7\u7279\u6027/PProf\u670d\u52a1\u6027\u80fd\u5206\u6790",draft:!1,unlisted:!1,tags:[],version:"current",sidebarPosition:9,frontMatter:{title:"PProf\u670d\u52a1\u6027\u80fd\u5206\u6790",sidebar_position:9},sidebar:"tutorialSidebar",previous:{title:"\u81ea\u5b9a\u4e49\u72b6\u6001\u7801\u5904\u7406",permalink:"/docs/WEB\u670d\u52a1\u5f00\u53d1/\u9ad8\u7ea7\u7279\u6027/\u81ea\u5b9a\u4e49\u72b6\u6001\u7801\u5904\u7406"},next:{title:"SameSite \u8bbe\u7f6e",permalink:"/docs/WEB\u670d\u52a1\u5f00\u53d1/\u9ad8\u7ea7\u7279\u6027/SameSite \u8bbe\u7f6e"}},d={},l=[{value:"PProf
\u542f\u7528",id:"pprof-\u542f\u7528",level:2},{value:"EnablePProf
",id:"enablepprof",level:3},{value:"StartPProfServer
",id:"startpprofserver",level:3},{value:"PProf
\u6307\u6807",id:"pprof-\u6307\u6807",level:2},{value:"PProf
\u9875\u9762",id:"pprof-\u9875\u9762",level:2},{value:"\u6027\u80fd\u91c7\u96c6\u5206\u6790\ud83d\udd25",id:"\u6027\u80fd\u91c7\u96c6\u5206\u6790",level:2},{value:"CPU\u6027\u80fd\u5206\u6790",id:"cpu\u6027\u80fd\u5206\u6790",level:3},{value:"\u5185\u5b58\u4f7f\u7528\u5206\u6790",id:"\u5185\u5b58\u4f7f\u7528\u5206\u6790",level:3}];function h(e){const n={a:"a",code:"code",h2:"h2",h3:"h3",img:"img",li:"li",p:"p",pre:"pre",ul:"ul",...(0,t.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.code,{children:"GoFrame"})," \u6846\u67b6\u7684 ",(0,r.jsx)(n.code,{children:"Web Server"})," \u63d0\u4f9b\u4e86\u975e\u5e38\u5f3a\u5927\u548c\u7b80\u4fbf\u7684\u670d\u52a1\u6027\u80fd\u5206\u6790\u529f\u80fd\uff0c\u5185\u90e8\u5b8c\u7f8e\u96c6\u6210\u4e86 ",(0,r.jsx)(n.code,{children:"pprof"})," \u6027\u80fd\u5206\u6790\u5de5\u5177\uff0c\u53ef\u4ee5\u5728\u4efb\u4f55\u65f6\u5019\u901a\u8fc7 ",(0,r.jsx)(n.code,{children:"EnablePProf"})," \u65b9\u6cd5\u542f\u7528\u6027\u80fd\u5206\u6790\u7279\u6027\uff0c\u5e76\u53ef\u81ea\u5b9a\u4e49\u6027\u80fd\u5206\u6790\u5de5\u5177\u9875\u9762\u8def\u7531\u5730\u5740\uff0c\u4e0d\u4f20\u9012\u8def\u7531\u5730\u5740\u65f6\uff0c\u9ed8\u8ba4URI\u5730\u5740\u4e3a ",(0,r.jsx)(n.code,{children:"/debug/pprof"}),"\u3002"]}),"\n",(0,r.jsxs)(n.h2,{id:"pprof-\u542f\u7528",children:[(0,r.jsx)(n.code,{children:"PProf"})," \u542f\u7528"]}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.code,{children:"PProf"})," \u7279\u6027\u7684\u542f\u7528\u4f1a\u5bf9\u7a0b\u5e8f\u6027\u80fd\u4ea7\u751f\u4e00\u5b9a\u5f71\u54cd\uff0c\u5177\u4f53\u5f71\u54cd\u7a0b\u5ea6\u9700\u8981\u6839\u636e\u5f53\u524d\u4e1a\u52a1\u573a\u666f\u5728 ",(0,r.jsx)(n.code,{children:"PProd"})," \u542f\u7528\u524d\u540e\u8fdb\u884c\u5bf9\u6bd4\u3002"]}),"\n",(0,r.jsx)(n.h3,{id:"enablepprof",children:(0,r.jsx)(n.code,{children:"EnablePProf"})}),"\n",(0,r.jsx)(n.p,{children:"\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{children:'package main\n\nimport (\n\t"github.com/gogf/gf/v2/frame/g"\n\t"github.com/gogf/gf/v2/net/ghttp"\n\t"runtime"\n)\n\nfunc main() {\n\truntime.SetMutexProfileFraction(1) // (\u975e\u5fc5\u9700)\u5f00\u542f\u5bf9\u9501\u8c03\u7528\u7684\u8ddf\u8e2a\n\truntime.SetBlockProfileRate(1) // (\u975e\u5fc5\u9700)\u5f00\u542f\u5bf9\u963b\u585e\u64cd\u4f5c\u7684\u8ddf\u8e2a\n\n\ts := g.Server()\n\ts.EnablePProf()\n\ts.BindHandler("/", func(r *ghttp.Request) {\n\t\tr.Response.Writeln("\u54c8\u55bd\u4e16\u754c\uff01")\n\t})\n\ts.SetPort(8199)\n\ts.Run()\n}\n'})}),"\n",(0,r.jsxs)(n.p,{children:["\u8fd9\u4e2a\u4f8b\u5b50\u4f7f\u7528\u4e86 ",(0,r.jsx)(n.code,{children:"s.EnablePProf()"})," \u542f\u7528\u4e86\u6027\u80fd\u5206\u6790\uff0c\u9ed8\u8ba4\u4f1a\u81ea\u52a8\u6ce8\u518c\u4ee5\u4e0b\u51e0\u4e2a\u8def\u7531\u89c4\u5219\uff1a"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-html",children:"/debug/pprof/*action\n/debug/pprof/cmdline\n/debug/pprof/profile\n/debug/pprof/symbol\n/debug/pprof/trace\n"})}),"\n",(0,r.jsxs)(n.p,{children:["\u5176\u4e2d ",(0,r.jsx)(n.code,{children:"/debug/pprof/*action"})," \u4e3a\u9875\u9762\u8bbf\u95ee\u7684\u8def\u7531\uff0c\u5176\u4ed6\u51e0\u4e2a\u5730\u5740\u4e3a ",(0,r.jsx)(n.code,{children:"go tool pprof"})," \u547d\u4ee4\u51c6\u5907\u7684\u3002"]}),"\n",(0,r.jsx)(n.h3,{id:"startpprofserver",children:(0,r.jsx)(n.code,{children:"StartPProfServer"})}),"\n",(0,r.jsxs)(n.p,{children:["\u4e5f\u53ef\u4ee5\u4f7f\u7528 ",(0,r.jsx)(n.code,{children:"StartPProfServer"})," \u65b9\u6cd5\uff0c\u5feb\u901f\u5f00\u542f\u4e00\u4e2a\u72ec\u7acb\u7684 ",(0,r.jsx)(n.code,{children:"PProf Server"}),"\uff0c\u5e38\u7528\u4e8e\u4e00\u4e9b\u6ca1\u6709 ",(0,r.jsx)(n.code,{children:"HTTP Server"})," \u7684\u5e38\u9a7b\u7684\u8fdb\u7a0b\u4e2d\uff08\u4f8b\u5982\u5b9a\u65f6\u4efb\u52a1\u3001 ",(0,r.jsx)(n.code,{children:"GRPC"})," \u670d\u52a1\u4e2d\uff09\uff0c\u53ef\u4ee5\u5feb\u901f\u5f00\u542f\u4e00\u4e2a ",(0,r.jsx)(n.code,{children:"PProf Server"})," \u7528\u4e8e\u7a0b\u5e8f\u6027\u80fd\u5206\u6790\u3002\u8be5\u65b9\u6cd5\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{children:"func StartPProfServer(port int, pattern ...string)\n"})}),"\n",(0,r.jsxs)(n.p,{children:["\u4e00\u822c\u7684\u573a\u666f\u662f\u4f7f\u7528\u5f02\u6b65 ",(0,r.jsx)(n.code,{children:"goroutine"})," \u8fd0\u884c\u8be5 ",(0,r.jsx)(n.code,{children:"PProd Server"}),"\uff0c\u5373\u5f80\u5f80\u662f\u8fd9\u4e48\u6765\u4f7f\u7528\uff1a"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{children:'package main\n\nimport (\n\t"github.com/gogf/gf/v2/net/ghttp"\n)\n\nfunc main() {\n\tgo ghttp.StartPProfServer(8199)\n\t// \u5176\u4ed6\u670d\u52a1\u542f\u52a8\u3001\u8fd0\u884c\n\t// ...\n}\n'})}),"\n",(0,r.jsx)(n.p,{children:"\u4ee5\u4e0a\u793a\u4f8b\u53ef\u4ee5\u6539\u8fdb\u4e3a\uff1a"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{children:'package main\n\nimport (\n\t"github.com/gogf/gf/v2/frame/g"\n\t"github.com/gogf/gf/v2/net/ghttp"\n)\n\nfunc main() {\n\tgo ghttp.StartPProfServer(8299)\n\n\ts := g.Server()\n\ts.EnablePProf()\n\ts.BindHandler("/", func(r *ghttp.Request) {\n\t\tr.Response.Writeln("\u54c8\u55bd\u4e16\u754c\uff01")\n\t})\n\ts.SetPort(8199)\n\ts.Run()\n}\n'})}),"\n",(0,r.jsxs)(n.h2,{id:"pprof-\u6307\u6807",children:[(0,r.jsx)(n.code,{children:"PProf"})," \u6307\u6807"]}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"heap"}),": \u62a5\u544a\u5185\u5b58\u5206\u914d\u6837\u672c\uff1b\u7528\u4e8e\u76d1\u89c6\u5f53\u524d\u548c\u5386\u53f2\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff0c\u5e76\u68c0\u67e5\u5185\u5b58\u6cc4\u6f0f\u3002"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"threadcreate"}),": \u62a5\u544a\u4e86\u5bfc\u81f4\u521b\u5efa\u65b0OS\u7ebf\u7a0b\u7684\u7a0b\u5e8f\u90e8\u5206\u3002"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"goroutine"}),": \u62a5\u544a\u6240\u6709\u5f53\u524d ",(0,r.jsx)(n.code,{children:"goroutine"})," \u7684\u5806\u6808\u8ddf\u8e2a\u3002"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"block"}),": \u663e\u793a ",(0,r.jsx)(n.code,{children:"goroutine"})," \u5728\u54ea\u91cc\u963b\u585e\u540c\u6b65\u539f\u8bed\uff08\u5305\u62ec\u8ba1\u65f6\u5668\u901a\u9053\uff09\u7684\u7b49\u5f85\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u672a\u542f\u7528\uff0c\u9700\u8981\u624b\u52a8\u8c03\u7528 ",(0,r.jsx)(n.code,{children:"runtime.SetBlockProfileRate"})," \u542f\u7528\u3002"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"mutex"}),": \u62a5\u544a\u9501\u7ade\u4e89\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u672a\u542f\u7528\uff0c\u9700\u8981\u624b\u52a8\u8c03\u7528 ",(0,r.jsx)(n.code,{children:"runtime.SetMutexProfileFraction"})," \u542f\u7528\u3002"]}),"\n"]}),"\n",(0,r.jsxs)(n.h2,{id:"pprof-\u9875\u9762",children:[(0,r.jsx)(n.code,{children:"PProf"})," \u9875\u9762"]}),"\n",(0,r.jsxs)(n.p,{children:["\u7b80\u5355\u7684\u6027\u80fd\u5206\u6790\u6211\u4eec\u76f4\u63a5\u8bbf\u95ee ",(0,r.jsx)(n.code,{children:"/debug/pprof"})," \u5730\u5740\u5373\u53ef\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a"]}),"\n",(0,r.jsxs)(n.p,{children:["1\u3001 ",(0,r.jsx)(n.code,{children:"pprof"})," \u9875\u9762"]}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.img,{src:o(21201).Z+"",width:"389",height:"252"})}),"\n",(0,r.jsx)(n.p,{children:"2\u3001\u5806\u4f7f\u7528\u91cf"}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.img,{src:o(10170).Z+"",width:"1000",height:"521"})}),"\n",(0,r.jsxs)(n.p,{children:["3\u3001\u5f53\u524d\u8fdb\u7a0b\u4e2d\u7684 ",(0,r.jsx)(n.code,{children:"goroutine"})," \u8be6\u60c5"]}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.img,{src:o(58702).Z+"",width:"1000",height:"473"})}),"\n",(0,r.jsx)(n.h2,{id:"\u6027\u80fd\u91c7\u96c6\u5206\u6790",children:"\u6027\u80fd\u91c7\u96c6\u5206\u6790\ud83d\udd25"}),"\n",(0,r.jsxs)(n.p,{children:["\u5982\u679c\u60f3\u8981\u8fdb\u884c\u8be6\u7ec6\u7684\u6027\u80fd\u5206\u6790\uff0c\u57fa\u672c\u4e0a\u79bb\u4e0d\u5f00 ",(0,r.jsx)(n.code,{children:"go tool pprof"})," \u547d\u4ee4\u884c\u5de5\u5177\u7684\u652f\u6301\uff0c\u5728\u5f00\u542f\u6027\u80fd\u5206\u6790\u652f\u6301\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6267\u884c\u6027\u80fd\u91c7\u96c6\u5206\u6790\uff1a"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-undefined",children:'go tool pprof "http://127.0.0.1:8199/debug/pprof/profile"\n'})}),"\n",(0,r.jsxs)(n.p,{children:["\u6267\u884c\u540e ",(0,r.jsx)(n.code,{children:"pprof"})," \u5de5\u5177\u7ecf\u8fc7\u7ea6 ",(0,r.jsx)(n.code,{children:"30"})," \u79d2\u5de6\u53f3\u7684\u63a5\u53e3\u4fe1\u606f\u91c7\u96c6\uff08\u8fd9 ",(0,r.jsx)(n.code,{children:"30"})," \u79d2\u671f\u95f4 ",(0,r.jsx)(n.code,{children:"WebServer"})," \u5e94\u5f53\u6709\u6d41\u91cf\u8fdb\u5165\uff0c\u6211\u4eec\u8fd9\u91cc\u4e0d\u505c\u5730\u8bbf\u95ee ",(0,r.jsx)(n.code,{children:"hello world"})," \u9875\u9762\u4ee5\u4f5c\u6d4b\u8bd5\uff09\uff0c\u7136\u540e\u751f\u6210\u6027\u80fd\u5206\u6790\u62a5\u544a\uff0c\u968f\u540e\u53ef\u4ee5\u901a\u8fc7 ",(0,r.jsx)(n.code,{children:"top10"}),"/ ",(0,r.jsx)(n.code,{children:"web"})," \u7b49 ",(0,r.jsx)(n.code,{children:"pprof"})," \u547d\u4ee4\u67e5\u770b\u62a5\u544a\u7ed3\u679c\uff0c\u66f4\u591a\u547d\u4ee4\u53ef\u4f7f\u7528 ",(0,r.jsx)(n.code,{children:"go tool pprof"})," \u67e5\u770b\u3002\u5173\u4e8e ",(0,r.jsx)(n.code,{children:"pprof"})," \u7684\u8be6\u7ec6\u4f7f\u7528\u4ecb\u7ecd\uff0c\u8bf7\u67e5\u770b ",(0,r.jsx)(n.code,{children:"Golang"})," \u5b98\u65b9\uff1a ",(0,r.jsx)(n.a,{href:"https://blog.golang.org/profiling-go-programs",children:"blog.golang.org/profiling-go-programs"})]}),"\n",(0,r.jsx)(n.h3,{id:"cpu\u6027\u80fd\u5206\u6790",children:"CPU\u6027\u80fd\u5206\u6790"}),"\n",(0,r.jsx)(n.p,{children:"\u672c\u793a\u4f8b\u4e2d\u7684\u547d\u4ee4\u884c\u6027\u80fd\u5206\u6790\u7ed3\u679c\u5982\u4e0b\uff1a"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-html",children:'$ go tool pprof "http://127.0.0.1:8199/debug/pprof/profile"\nFetching profile over HTTP from http://127.0.0.1:8199/debug/pprof/profile\nSaved profile in /home/john/pprof/pprof.___go_build_pprof_go.samples.cpu.001.pb.gz\nFile: ___go_build_pprof_go\nType: cpu\nTime: Apr 17, 2018 at 10:53pm (CST)\nDuration: 30s, Total samples = 80ms ( 0.27%)\nEntering interactive mode (type "help" for commands, "o" for options)\n(pprof) top10\nShowing nodes accounting for 80ms, 100% of 80ms total\nShowing top 10 nodes out of 49\n flat flat% sum% cum cum%\n 10ms 12.50% 12.50% 10ms 12.50% github.com/gogf/gf/v2/net/ghttp.(*Cookie).Get /home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/v2/net/ghttp/http_server_cookie.go\n 10ms 12.50% 25.00% 10ms 12.50% internal/poll.runtime_pollReset /home/john/Softs/go1.9.2/src/runtime/netpoll.go\n 10ms 12.50% 37.50% 10ms 12.50% runtime.futex /home/john/Softs/go1.9.2/src/runtime/sys_linux_amd64.s\n 10ms 12.50% 50.00% 10ms 12.50% runtime.getitab /home/john/Softs/go1.9.2/src/runtime/iface.go\n 10ms 12.50% 62.50% 10ms 12.50% runtime.newarray /home/john/Softs/go1.9.2/src/runtime/slice.go\n 10ms 12.50% 75.00% 10ms 12.50% runtime.rawstringtmp /home/john/Softs/go1.9.2/src/runtime/string.go\n 10ms 12.50% 87.50% 10ms 12.50% runtime.usleep /home/john/Softs/go1.9.2/src/runtime/sys_linux_amd64.s\n 10ms 12.50% 100% 10ms 12.50% sync.(*RWMutex).Lock /home/john/Softs/go1.9.2/src/sync/rwmutex.go\n 0 0% 100% 10ms 12.50% bufio.(*Writer).Flush /home/john/Softs/go1.9.2/src/bufio/bufio.go\n 0 0% 100% 10ms 12.50% github.com/gogf/gf/v2/container/gqueue.(*Queue).PopFront /home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/v2/container/gqueue/gqueue.go\n(pprof) web\nFailed to execute dot. Is Graphviz installed? Error: exec: "dot": executable file not found in $PATH\n(pprof) web\n(pprof)\n'})}),"\n",(0,r.jsxs)(n.p,{children:["\u5176\u4e2d ",(0,r.jsx)(n.code,{children:"web"})," \u547d\u4ee4\u7528\u4ee5\u56fe\u5f62\u5c55\u793a\u63a5\u53e3\u4e4b\u95f4\u7684\u8c03\u7528\u5173\u7cfb\u4ee5\u53ca\u6027\u80fd\u60c5\u51b5\uff0c\u4f46\u662f\u9700\u8981\u5b89\u88c5 ",(0,r.jsx)(n.code,{children:"Graphviz"})," \u56fe\u5f62\u5316\u5de5\u5177\uff0c\u4ee5\u6211\u76ee\u524d\u7684\u7cfb\u7edf\u4e3a ",(0,r.jsx)(n.code,{children:"Ubuntu"})," \u4e3a\u4f8b\uff0c\u76f4\u63a5\u6267\u884c ",(0,r.jsx)(n.code,{children:"sudo apt-get install graphviz"})," \u547d\u4ee4\u5373\u53ef\u5b89\u88c5\u5b8c\u6210\u56fe\u5f62\u5316\u5de5\u5177\uff08\u5982\u679c\u662f ",(0,r.jsx)(n.code,{children:"MacOS"}),"\uff0c\u4f7f\u7528 ",(0,r.jsx)(n.code,{children:"brew install Graphviz"})," \u5b89\u88c5\uff09\uff0c\u968f\u540e\u518d\u6b21\u4f7f\u7528 ",(0,r.jsx)(n.code,{children:"web"})," \u547d\u4ee4\uff0c\u6700\u7ec8\u751f\u6210\u4ee5\u4e0b\u56fe\u8868\uff1a"]}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.img,{src:o(35995).Z+"",width:"1000",height:"1030"})}),"\n",(0,r.jsx)(n.h3,{id:"\u5185\u5b58\u4f7f\u7528\u5206\u6790",children:"\u5185\u5b58\u4f7f\u7528\u5206\u6790"}),"\n",(0,r.jsxs)(n.p,{children:["\u4e0eCPU\u6027\u80fd\u5206\u6790\u7c7b\u4f3c\uff0c\u5185\u5b58\u4f7f\u7528\u5206\u6790\u540c\u6837\u4f7f\u7528\u5230 ",(0,r.jsx)(n.code,{children:"go tool pprof"})," \u547d\u4ee4\uff1a"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{children:'$ go tool pprof http://127.0.0.1:8299/debug/pprof/heap\nFetching profile over HTTP from http://127.0.0.1:8299/debug/pprof/heap\nSaved profile in /Users/john/pprof/pprof.alloc_objects.alloc_space.inuse_objects.inuse_space.004.pb.gz\nType: inuse_space\nTime: May 24, 2021 at 8:01pm (CST)\nEntering interactive mode (type "help" for commands, "o" for options)\n(pprof) top\nShowing nodes accounting for 1536.39kB, 100% of 1536.39kB total\nShowing top 10 nodes out of 19\n flat flat% sum% cum cum%\n 512.19kB 33.34% 33.34% 512.19kB 33.34% runtime.malg\n 512.14kB 33.33% 66.67% 512.14kB 33.33% github.com/gogf/gf/v2/container/gmap.(*StrAnyMap).doSetWithLockCheck\n 512.06kB 33.33% 100% 512.06kB 33.33% net.newFD (inline)\n 0 0% 100% 512.14kB 33.33% github.com/gogf/gf/v2/container/gmap.(*StrAnyMap).GetOrSetFuncLock\n 0 0% 100% 512.06kB 33.33% github.com/gogf/gf/v2/net/ghttp.(*Server).startServer.func1\n 0 0% 100% 512.06kB 33.33% github.com/gogf/gf/v2/net/ghttp.(*gracefulServer).ListenAndServe\n 0 0% 100% 512.06kB 33.33% github.com/gogf/gf/v2/net/ghttp.(*gracefulServer).doServe\n 0 0% 100% 512.14kB 33.33% github.com/gogf/gf/v2/os/gres.Instance\n 0 0% 100% 512.14kB 33.33% github.com/gogf/gf/v2/os/gres.init\n 0 0% 100% 512.06kB 33.33% net.(*TCPListener).Accept\n(pprof) web\n(pprof)\n'})}),"\n",(0,r.jsxs)(n.p,{children:["\u901a\u8fc7 ",(0,r.jsx)(n.code,{children:"web"})," \u56fe\u5f62\u5c55\u793a\uff0c\u7c7b\u4f3c\u8fd9\u6837\u7684\uff1a"]}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.img,{src:o(39051).Z+"",width:"1542",height:"1604"})})]})}function g(e={}){const{wrapper:n}={...(0,t.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},21201:(e,n,o)=>{o.d(n,{Z:()=>r});const r="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYUAAAD8CAMAAACvp0jHAAA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OO54iyribh0vsQcJ0daaFQq9VlKgGXHTP//uUOe8lgBYsEKEAtWgFiwAsSCFSAWrACxYAWIBStALFgBYsEKEAtWgFiwAv8PtgllwJJkkEEAAAAASUVORK5CYII="},58702:(e,n,o)=>{o.d(n,{Z:()=>r});const r=o.p+"assets/images/4aad1989545e9fe67cf46de3b06686aa-7022a469373d941eaa2919880d0b2208.png"},10170:(e,n,o)=>{o.d(n,{Z:()=>r});const r=o.p+"assets/images/990043747df320652c2ab0944f259f73-761ef5610b70d9606c2b3af927da6fcc.png"},35995:(e,n,o)=>{o.d(n,{Z:()=>r});const r=o.p+"assets/images/9f9678e7f3697dfe7c351ac613364eab-1704346158f12132ba0cf70903533de5.png"},39051:(e,n,o)=>{o.d(n,{Z:()=>r});const r=o.p+"assets/images/c90f14644e3cf7c2f84f79c14e81ec40-32dd4e0832c52c08a332b0393781115c.png"},11151:(e,n,o)=>{o.d(n,{Z:()=>c,a:()=>s});var r=o(67294);const t={},i=r.createContext(t);function s(e){const n=r.useContext(i);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:s(e.components),r.createElement(i.Provider,{value:n},e.children)}}}]);
\ No newline at end of file
diff --git a/assets/js/c2bc84e4.1a346870.js b/assets/js/c2bc84e4.1a346870.js
new file mode 100644
index 00000000000..a7bf569b64f
--- /dev/null
+++ b/assets/js/c2bc84e4.1a346870.js
@@ -0,0 +1 @@
+"use strict";(self.webpackChunkgfdoc=self.webpackChunkgfdoc||[]).push([[9847],{29453:(e,n,r)=>{r.r(n),r.d(n,{assets:()=>t,contentTitle:()=>s,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>l});var o=r(85893),d=r(11151);const i={title:"PProf\u670d\u52a1\u6027\u80fd\u5206\u6790",sidebar_position:9},s=void 0,c={id:"WEB\u670d\u52a1\u5f00\u53d1/\u9ad8\u7ea7\u7279\u6027/PProf\u670d\u52a1\u6027\u80fd\u5206\u6790",title:"PProf\u670d\u52a1\u6027\u80fd\u5206\u6790",description:"GoFrame \u6846\u67b6\u7684 Web Server \u63d0\u4f9b\u4e86\u975e\u5e38\u5f3a\u5927\u548c\u7b80\u4fbf\u7684\u670d\u52a1\u6027\u80fd\u5206\u6790\u529f\u80fd\uff0c\u5185\u90e8\u5b8c\u7f8e\u96c6\u6210\u4e86 pprof \u6027\u80fd\u5206\u6790\u5de5\u5177\uff0c\u53ef\u4ee5\u5728\u4efb\u4f55\u65f6\u5019\u901a\u8fc7 EnablePProf \u65b9\u6cd5\u542f\u7528\u6027\u80fd\u5206\u6790\u7279\u6027\uff0c\u5e76\u53ef\u81ea\u5b9a\u4e49\u6027\u80fd\u5206\u6790\u5de5\u5177\u9875\u9762\u8def\u7531\u5730\u5740\uff0c\u4e0d\u4f20\u9012\u8def\u7531\u5730\u5740\u65f6\uff0c\u9ed8\u8ba4URI\u5730\u5740\u4e3a /debug/pprof\u3002",source:"@site/docs/7-WEB\u670d\u52a1\u5f00\u53d1/11-\u9ad8\u7ea7\u7279\u6027/9-PProf\u670d\u52a1\u6027\u80fd\u5206\u6790.md",sourceDirName:"7-WEB\u670d\u52a1\u5f00\u53d1/11-\u9ad8\u7ea7\u7279\u6027",slug:"/WEB\u670d\u52a1\u5f00\u53d1/\u9ad8\u7ea7\u7279\u6027/PProf\u670d\u52a1\u6027\u80fd\u5206\u6790",permalink:"/docs/WEB\u670d\u52a1\u5f00\u53d1/\u9ad8\u7ea7\u7279\u6027/PProf\u670d\u52a1\u6027\u80fd\u5206\u6790",draft:!1,unlisted:!1,tags:[],version:"current",sidebarPosition:9,frontMatter:{title:"PProf\u670d\u52a1\u6027\u80fd\u5206\u6790",sidebar_position:9},sidebar:"tutorialSidebar",previous:{title:"\u81ea\u5b9a\u4e49\u72b6\u6001\u7801\u5904\u7406",permalink:"/docs/WEB\u670d\u52a1\u5f00\u53d1/\u9ad8\u7ea7\u7279\u6027/\u81ea\u5b9a\u4e49\u72b6\u6001\u7801\u5904\u7406"},next:{title:"SameSite \u8bbe\u7f6e",permalink:"/docs/WEB\u670d\u52a1\u5f00\u53d1/\u9ad8\u7ea7\u7279\u6027/SameSite \u8bbe\u7f6e"}},t={},l=[{value:"PProf
\u542f\u7528",id:"pprof-\u542f\u7528",level:2},{value:"EnablePProf
",id:"enablepprof",level:3},{value:"StartPProfServer
",id:"startpprofserver",level:3},{value:"PProf
\u6307\u6807",id:"pprof-\u6307\u6807",level:2},{value:"PProf
\u9875\u9762",id:"pprof-\u9875\u9762",level:2},{value:"\u6027\u80fd\u91c7\u96c6\u5206\u6790\ud83d\udd25",id:"\u6027\u80fd\u91c7\u96c6\u5206\u6790",level:2},{value:"CPU\u6027\u80fd\u5206\u6790",id:"cpu\u6027\u80fd\u5206\u6790",level:3},{value:"\u5185\u5b58\u4f7f\u7528\u5206\u6790",id:"\u5185\u5b58\u4f7f\u7528\u5206\u6790",level:3},{value:"goroutine\u4f7f\u7528\u5206\u6790",id:"goroutine\u4f7f\u7528\u5206\u6790",level:3}];function h(e){const n={a:"a",code:"code",h2:"h2",h3:"h3",img:"img",li:"li",p:"p",pre:"pre",ul:"ul",...(0,d.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:[(0,o.jsx)(n.code,{children:"GoFrame"})," \u6846\u67b6\u7684 ",(0,o.jsx)(n.code,{children:"Web Server"})," \u63d0\u4f9b\u4e86\u975e\u5e38\u5f3a\u5927\u548c\u7b80\u4fbf\u7684\u670d\u52a1\u6027\u80fd\u5206\u6790\u529f\u80fd\uff0c\u5185\u90e8\u5b8c\u7f8e\u96c6\u6210\u4e86 ",(0,o.jsx)(n.code,{children:"pprof"})," \u6027\u80fd\u5206\u6790\u5de5\u5177\uff0c\u53ef\u4ee5\u5728\u4efb\u4f55\u65f6\u5019\u901a\u8fc7 ",(0,o.jsx)(n.code,{children:"EnablePProf"})," \u65b9\u6cd5\u542f\u7528\u6027\u80fd\u5206\u6790\u7279\u6027\uff0c\u5e76\u53ef\u81ea\u5b9a\u4e49\u6027\u80fd\u5206\u6790\u5de5\u5177\u9875\u9762\u8def\u7531\u5730\u5740\uff0c\u4e0d\u4f20\u9012\u8def\u7531\u5730\u5740\u65f6\uff0c\u9ed8\u8ba4URI\u5730\u5740\u4e3a ",(0,o.jsx)(n.code,{children:"/debug/pprof"}),"\u3002"]}),"\n",(0,o.jsxs)(n.h2,{id:"pprof-\u542f\u7528",children:[(0,o.jsx)(n.code,{children:"PProf"})," \u542f\u7528"]}),"\n",(0,o.jsxs)(n.p,{children:[(0,o.jsx)(n.code,{children:"PProf"})," \u7279\u6027\u7684\u542f\u7528\u4f1a\u5bf9\u7a0b\u5e8f\u6027\u80fd\u4ea7\u751f\u4e00\u5b9a\u5f71\u54cd\uff0c\u5177\u4f53\u5f71\u54cd\u7a0b\u5ea6\u9700\u8981\u6839\u636e\u5f53\u524d\u4e1a\u52a1\u573a\u666f\u5728 ",(0,o.jsx)(n.code,{children:"PProd"})," \u542f\u7528\u524d\u540e\u8fdb\u884c\u5bf9\u6bd4\u3002"]}),"\n",(0,o.jsx)(n.h3,{id:"enablepprof",children:(0,o.jsx)(n.code,{children:"EnablePProf"})}),"\n",(0,o.jsx)(n.p,{children:"\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{children:'package main\n\nimport (\n\t"github.com/gogf/gf/v2/frame/g"\n\t"github.com/gogf/gf/v2/net/ghttp"\n\t"runtime"\n)\n\nfunc main() {\n\truntime.SetMutexProfileFraction(1) // (\u975e\u5fc5\u9700)\u5f00\u542f\u5bf9\u9501\u8c03\u7528\u7684\u8ddf\u8e2a\n\truntime.SetBlockProfileRate(1) // (\u975e\u5fc5\u9700)\u5f00\u542f\u5bf9\u963b\u585e\u64cd\u4f5c\u7684\u8ddf\u8e2a\n\n\ts := g.Server()\n\ts.EnablePProf()\n\ts.BindHandler("/", func(r *ghttp.Request) {\n\t\tr.Response.Writeln("\u54c8\u55bd\u4e16\u754c\uff01")\n\t})\n\ts.SetPort(8199)\n\ts.Run()\n}\n'})}),"\n",(0,o.jsxs)(n.p,{children:["\u8fd9\u4e2a\u4f8b\u5b50\u4f7f\u7528\u4e86 ",(0,o.jsx)(n.code,{children:"s.EnablePProf()"})," \u542f\u7528\u4e86\u6027\u80fd\u5206\u6790\uff0c\u9ed8\u8ba4\u4f1a\u81ea\u52a8\u6ce8\u518c\u4ee5\u4e0b\u51e0\u4e2a\u8def\u7531\u89c4\u5219\uff1a"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-html",children:"/debug/pprof/*action\n/debug/pprof/cmdline\n/debug/pprof/profile\n/debug/pprof/symbol\n/debug/pprof/trace\n"})}),"\n",(0,o.jsxs)(n.p,{children:["\u5176\u4e2d ",(0,o.jsx)(n.code,{children:"/debug/pprof/*action"})," \u4e3a\u9875\u9762\u8bbf\u95ee\u7684\u8def\u7531\uff0c\u5176\u4ed6\u51e0\u4e2a\u5730\u5740\u4e3a ",(0,o.jsx)(n.code,{children:"go tool pprof"})," \u547d\u4ee4\u51c6\u5907\u7684\u3002"]}),"\n",(0,o.jsx)(n.h3,{id:"startpprofserver",children:(0,o.jsx)(n.code,{children:"StartPProfServer"})}),"\n",(0,o.jsxs)(n.p,{children:["\u4e5f\u53ef\u4ee5\u4f7f\u7528 ",(0,o.jsx)(n.code,{children:"StartPProfServer"})," \u65b9\u6cd5\uff0c\u5feb\u901f\u5f00\u542f\u4e00\u4e2a\u72ec\u7acb\u7684 ",(0,o.jsx)(n.code,{children:"PProf Server"}),"\uff0c\u5e38\u7528\u4e8e\u4e00\u4e9b\u6ca1\u6709 ",(0,o.jsx)(n.code,{children:"HTTP Server"})," \u7684\u5e38\u9a7b\u7684\u8fdb\u7a0b\u4e2d\uff08\u4f8b\u5982\u5b9a\u65f6\u4efb\u52a1\u3001 ",(0,o.jsx)(n.code,{children:"GRPC"})," \u670d\u52a1\u4e2d\uff09\uff0c\u53ef\u4ee5\u5feb\u901f\u5f00\u542f\u4e00\u4e2a ",(0,o.jsx)(n.code,{children:"PProf Server"})," \u7528\u4e8e\u7a0b\u5e8f\u6027\u80fd\u5206\u6790\u3002\u8be5\u65b9\u6cd5\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{children:"func StartPProfServer(port int, pattern ...string)\n"})}),"\n",(0,o.jsxs)(n.p,{children:["\u4e00\u822c\u7684\u573a\u666f\u662f\u4f7f\u7528\u5f02\u6b65 ",(0,o.jsx)(n.code,{children:"goroutine"})," \u8fd0\u884c\u8be5 ",(0,o.jsx)(n.code,{children:"PProd Server"}),"\uff0c\u5373\u5f80\u5f80\u662f\u8fd9\u4e48\u6765\u4f7f\u7528\uff1a"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{children:'package main\n\nimport (\n\t"github.com/gogf/gf/v2/net/ghttp"\n)\n\nfunc main() {\n\tgo ghttp.StartPProfServer(8199)\n\t// \u5176\u4ed6\u670d\u52a1\u542f\u52a8\u3001\u8fd0\u884c\n\t// ...\n}\n'})}),"\n",(0,o.jsx)(n.p,{children:"\u4ee5\u4e0a\u793a\u4f8b\u53ef\u4ee5\u6539\u8fdb\u4e3a\uff1a"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{children:'package main\n\nimport (\n\t"github.com/gogf/gf/v2/frame/g"\n\t"github.com/gogf/gf/v2/net/ghttp"\n)\n\nfunc main() {\n\tgo ghttp.StartPProfServer(8299)\n\n\ts := g.Server()\n\ts.EnablePProf()\n\ts.BindHandler("/", func(r *ghttp.Request) {\n\t\tr.Response.Writeln("\u54c8\u55bd\u4e16\u754c\uff01")\n\t})\n\ts.SetPort(8199)\n\ts.Run()\n}\n'})}),"\n",(0,o.jsxs)(n.h2,{id:"pprof-\u6307\u6807",children:[(0,o.jsx)(n.code,{children:"PProf"})," \u6307\u6807"]}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"heap"}),": \u62a5\u544a\u5185\u5b58\u5206\u914d\u6837\u672c\uff1b\u7528\u4e8e\u76d1\u89c6\u5f53\u524d\u548c\u5386\u53f2\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff0c\u5e76\u68c0\u67e5\u5185\u5b58\u6cc4\u6f0f\u3002"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"threadcreate"}),": \u62a5\u544a\u4e86\u5bfc\u81f4\u521b\u5efa\u65b0OS\u7ebf\u7a0b\u7684\u7a0b\u5e8f\u90e8\u5206\u3002"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"goroutine"}),": \u62a5\u544a\u6240\u6709\u5f53\u524d ",(0,o.jsx)(n.code,{children:"goroutine"})," \u7684\u5806\u6808\u8ddf\u8e2a\u3002"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"block"}),": \u663e\u793a ",(0,o.jsx)(n.code,{children:"goroutine"})," \u5728\u54ea\u91cc\u963b\u585e\u540c\u6b65\u539f\u8bed\uff08\u5305\u62ec\u8ba1\u65f6\u5668\u901a\u9053\uff09\u7684\u7b49\u5f85\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u672a\u542f\u7528\uff0c\u9700\u8981\u624b\u52a8\u8c03\u7528 ",(0,o.jsx)(n.code,{children:"runtime.SetBlockProfileRate"})," \u542f\u7528\u3002"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"mutex"}),": \u62a5\u544a\u9501\u7ade\u4e89\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u672a\u542f\u7528\uff0c\u9700\u8981\u624b\u52a8\u8c03\u7528 ",(0,o.jsx)(n.code,{children:"runtime.SetMutexProfileFraction"})," \u542f\u7528\u3002"]}),"\n"]}),"\n",(0,o.jsxs)(n.h2,{id:"pprof-\u9875\u9762",children:[(0,o.jsx)(n.code,{children:"PProf"})," \u9875\u9762"]}),"\n",(0,o.jsxs)(n.p,{children:["\u7b80\u5355\u7684\u6027\u80fd\u5206\u6790\u6211\u4eec\u76f4\u63a5\u8bbf\u95ee ",(0,o.jsx)(n.code,{children:"/debug/pprof"})," \u5730\u5740\u5373\u53ef\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a"]}),"\n",(0,o.jsxs)(n.p,{children:["1\u3001 ",(0,o.jsx)(n.code,{children:"pprof"})," \u9875\u9762"]}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsx)(n.img,{src:r(21201).Z+"",width:"389",height:"252"})}),"\n",(0,o.jsx)(n.p,{children:"2\u3001\u5806\u4f7f\u7528\u91cf"}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsx)(n.img,{src:r(10170).Z+"",width:"1000",height:"521"})}),"\n",(0,o.jsxs)(n.p,{children:["3\u3001\u5f53\u524d\u8fdb\u7a0b\u4e2d\u7684 ",(0,o.jsx)(n.code,{children:"goroutine"})," \u8be6\u60c5"]}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsx)(n.img,{src:r(58702).Z+"",width:"1000",height:"473"})}),"\n",(0,o.jsx)(n.h2,{id:"\u6027\u80fd\u91c7\u96c6\u5206\u6790",children:"\u6027\u80fd\u91c7\u96c6\u5206\u6790\ud83d\udd25"}),"\n",(0,o.jsx)(n.p,{children:"\u4ee5\u4e0b\u793a\u4f8b\u622a\u56fe\u6765\u6e90\u4e8e\u793a\u4f8b\u9879\u76ee\uff0c\u4ec5\u4f9b\u53c2\u8003\u3002"}),"\n",(0,o.jsxs)(n.p,{children:["\u5982\u679c\u60f3\u8981\u8fdb\u884c\u8be6\u7ec6\u7684\u6027\u80fd\u5206\u6790\uff0c\u57fa\u672c\u4e0a\u79bb\u4e0d\u5f00 ",(0,o.jsx)(n.code,{children:"go tool pprof"})," \u547d\u4ee4\u884c\u5de5\u5177\u7684\u652f\u6301\uff0c\u5728\u5f00\u542f\u6027\u80fd\u5206\u6790\u652f\u6301\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6267\u884c\u6027\u80fd\u91c7\u96c6\u5206\u6790\uff1a"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{children:'go tool pprof -http :8080 "http://127.0.0.1:8199/debug/pprof/profile"\n'})}),"\n",(0,o.jsx)(n.p,{children:"\u4e5f\u53ef\u4ee5\u5c06pprof\u6587\u4ef6\u5bfc\u51fa\u540e\u518d\u901a\u8fc7go tool pprof\u547d\u4ee4\u6253\u5f00\uff1a"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{children:"curl http://127.0.0.1:8199/debug/pprof/profile > pprof.profile\ngo tool pprof -http :8080 pprof.profile\n"})}),"\n",(0,o.jsxs)(n.p,{children:["\u6267\u884c\u540e ",(0,o.jsx)(n.code,{children:"profile"})," \u7684 ",(0,o.jsx)(n.code,{children:"pprof"})," \u5de5\u5177\u7ecf\u8fc7\u7ea6 ",(0,o.jsx)(n.code,{children:"30"})," \u79d2\u5de6\u53f3\u7684\u63a5\u53e3\u4fe1\u606f\u91c7\u96c6\uff08\u8fd9 ",(0,o.jsx)(n.code,{children:"30"})," \u79d2\u671f\u95f4 ",(0,o.jsx)(n.code,{children:"WebServer"})," \u5e94\u5f53\u6709\u6d41\u91cf\u8fdb\u5165\uff09\uff0c\u7136\u540e\u751f\u6210\u6027\u80fd\u5206\u6790\u62a5\u544a\uff0c\u968f\u540e\u53ef\u4ee5\u901a\u8fc7 ",(0,o.jsx)(n.code,{children:"top10"}),"/ ",(0,o.jsx)(n.code,{children:"web"})," \u7b49 ",(0,o.jsx)(n.code,{children:"pprof"})," \u547d\u4ee4\u67e5\u770b\u62a5\u544a\u7ed3\u679c\uff0c\u66f4\u591a\u547d\u4ee4\u53ef\u4f7f\u7528 ",(0,o.jsx)(n.code,{children:"go tool pprof"})," \u67e5\u770b\u3002\u5173\u4e8e ",(0,o.jsx)(n.code,{children:"pprof"})," \u7684\u8be6\u7ec6\u4f7f\u7528\u4ecb\u7ecd\uff0c\u8bf7\u67e5\u770b ",(0,o.jsx)(n.code,{children:"Golang"})," \u5b98\u65b9\uff1a ",(0,o.jsx)(n.a,{href:"https://blog.golang.org/profiling-go-programs",children:"blog.golang.org/profiling-go-programs"})]}),"\n",(0,o.jsx)(n.h3,{id:"cpu\u6027\u80fd\u5206\u6790",children:"CPU\u6027\u80fd\u5206\u6790"}),"\n",(0,o.jsx)(n.p,{children:"\u672c\u793a\u4f8b\u4e2d\u7684\u547d\u4ee4\u884c\u6027\u80fd\u5206\u6790\u7ed3\u679c\u5982\u4e0b\uff1a"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{children:'$ go tool pprof -http :8080 "http://127.0.0.1:8199/debug/pprof/profile"\nServing web UI on http://localhost:8080\n'})}),"\n",(0,o.jsxs)(n.p,{children:["\u56fe\u5f62\u5316\u5c55\u793a ",(0,o.jsx)(n.code,{children:"pprof"})," \u9700\u8981\u5b89\u88c5 ",(0,o.jsx)(n.code,{children:"Graphviz"})," \u56fe\u5f62\u5316\u5de5\u5177\uff0c\u4ee5\u6211\u76ee\u524d\u7684\u7cfb\u7edf\u4e3a ",(0,o.jsx)(n.code,{children:"Ubuntu"})," \u4e3a\u4f8b\uff0c\u76f4\u63a5\u6267\u884c ",(0,o.jsx)(n.code,{children:"sudo apt-get install graphviz"})," \u547d\u4ee4\u5373\u53ef\u5b89\u88c5\u5b8c\u6210\u56fe\u5f62\u5316\u5de5\u5177\uff08\u5982\u679c\u662f ",(0,o.jsx)(n.code,{children:"MacOS"}),"\uff0c\u4f7f\u7528 ",(0,o.jsx)(n.code,{children:"brew install Graphviz"})," \u5b89\u88c5\uff09\u3002"]}),"\n",(0,o.jsx)(n.p,{children:"\u8fd0\u884c\u540e\u5c06\u4f1a\u4f7f\u7528\u9ed8\u8ba4\u7684\u6d4f\u89c8\u5668\u6253\u5f00\u4ee5\u4e0b\u56fe\u5f62\u754c\u9762\uff0c\u5c55\u793a\u8fd9\u6bb5\u65f6\u95f4\u6293\u53d6\u7684CPU\u5f00\u9500\u94fe\u8def\uff1a"}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsx)(n.img,{src:r(51655).Z+"",width:"3454",height:"1854"})}),"\n",(0,o.jsx)(n.p,{children:"\u4e5f\u53ef\u4ee5\u67e5\u770b\u706b\u70ac\u56fe\uff0c\u53ef\u80fd\u66f4\u5f62\u8c61\u4e00\u4e9b\uff1a"}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsx)(n.img,{src:r(79389).Z+"",width:"3454",height:"1168"})}),"\n",(0,o.jsx)(n.h3,{id:"\u5185\u5b58\u4f7f\u7528\u5206\u6790",children:"\u5185\u5b58\u4f7f\u7528\u5206\u6790"}),"\n",(0,o.jsxs)(n.p,{children:["\u4e0e ",(0,o.jsx)(n.code,{children:"CPU"})," \u6027\u80fd\u5206\u6790\u7c7b\u4f3c\uff0c\u5185\u5b58\u4f7f\u7528\u5206\u6790\u540c\u6837\u4f7f\u7528\u5230 ",(0,o.jsx)(n.code,{children:"go tool pprof"})," \u547d\u4ee4\uff1a"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{children:'$ go tool pprof -http :8080 "http://127.0.0.1:8199/debug/pprof/heap"\nServing web UI on http://localhost:8080\n'})}),"\n",(0,o.jsx)(n.p,{children:"\u56fe\u5f62\u5c55\u793a\u7c7b\u4f3c\u8fd9\u6837\u7684\uff1a"}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsx)(n.img,{src:r(72777).Z+"",width:"3454",height:"1820"})}),"\n",(0,o.jsx)(n.p,{children:"\u540c\u6837\u7684\uff0c\u4e5f\u53ef\u4ee5\u67e5\u770b\u706b\u70ac\u56fe\uff0c\u53ef\u80fd\u66f4\u5f62\u8c61\u4e00\u4e9b\uff1a"}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsx)(n.img,{src:r(24590).Z+"",width:"3454",height:"1010"})}),"\n",(0,o.jsx)(n.h3,{id:"goroutine\u4f7f\u7528\u5206\u6790",children:"goroutine\u4f7f\u7528\u5206\u6790"}),"\n",(0,o.jsxs)(n.p,{children:["\u4e0e\u4e0a\u9762\u7684\u5206\u6790\u7c7b\u4f3c\uff0cgoroutine\u4f7f\u7528\u5206\u6790\u540c\u6837\u4f7f\u7528\u5230 ",(0,o.jsx)(n.code,{children:"go tool pprof"})," \u547d\u4ee4\uff1a"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{children:'$ go tool pprof -http :8080 "http://127.0.0.1:8199/debug/pprof/goroutine"\nServing web UI on http://localhost:8080\n'})}),"\n",(0,o.jsx)(n.p,{children:"\u56fe\u5f62\u5c55\u793a\u7c7b\u4f3c\u8fd9\u6837\u7684\uff0c\u901a\u5e38goroutine\u770b\u8fd9\u4e2a\u56fe\u7684\u8bdd\u5c31\u5dee\u4e0d\u591a\u4e86\uff0c\u5f53\u7136\u4e5f\u6709\u706b\u70ac\u56fe\u3002"}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsx)(n.img,{src:r(29828).Z+"",width:"3454",height:"1818"})})]})}function p(e={}){const{wrapper:n}={...(0,d.a)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(h,{...e})}):h(e)}},21201:(e,n,r)=>{r.d(n,{Z:()=>o});const o="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYUAAAD8CAMAAACvp0jHAAAAA3NCSVQICAjb4U/gAAADAFBMVEUAAAC5ufuzy0qMrlUAAO57e3s7gsZCQkJ2y/AxMfGOqr/////Hys0EQZ1sq8+EhPePj5Dm5ubFxcXIy8bm5v6tsrYhISEBRKhsljkZGe+tra1kZPXe3t6MjIytrfogKDPW1tZKSvPW1v3v7+8ZGRmLm6iUlPhra2tSUlKas8TG2llmZmaEhITf7J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ZaLoSyPLcSaEclfPlvMxtPKDvlIk/NXQny50uT4XcdCNr53dKfreUaXFiiYFmoNgEcQNlioJgHYc9TBbhaAmI8vZX0RZ5pL8qBKJQwjoHticVBIU7FSgOKA3N0WUdyHImBig2kBKgjALSIxwMdryEKhLkeux1eAO0srOyzsUrVSnsoueBxZvkpl84H45Z1O+jgW/CE86TzwBdA082VQRr1qs2igeUfIMOozHhYdd36jAkp3W7SDeqgA8pIFJwf24QoVmEjSCWghoUgARZR+4ml1hzi3Qv0U4TGhbtMgRl3a8TSOZQEuhDFfohbgh2ZWGnDBV0Pf+IwWAnGtK2JSK2bylYqTlywArhajPCV5SAeOaqi14STaYWXIggNZcEiHU728nVCOYyEf50A9Bi2gwqGhWECnLiwHxluQutviPXiyVEiyEMnyCWQB7h6gciFNKR0/UU+4Iy3kh4vyy8OQBZTxjFgAsVoZxVUF92VOSxbqTfji9xtGQDdYkLvbou3hjndhFEILBVRgwBVwHh9BMV1TRqxvoGsVaEHZodECzJECvguLlYtGbyGNMvb9/Sy1wEvXC/L0wbvr6XQA5gblSgmgQhlNQA8jKwD4JmccAR2VC3nZgtzdFpEtAb7CAx/qdVvjilSVq1HFdCiBuu7yDoeUXtJUjd+PxzzaDvUW0HQb5QuOm4tDteApUutVwO/FYwuO3UKMypbyTbmCn/f54hRVRinF7y+BRINCuXwAfkD5im4E9BIaFt0vdcstyd1tEfVKzA/LFGelDIqVEAfTFF+Mw4vEElwX/t+Q1AXXWfHtNmseeYcc+m433sjnHfF0garX/Jd4SJnj3M2LoFgqnfim0hTBGeQlRrUw3S6150NzljF1nhwjLXBUjOO54iyribh0vsQcJ0daaFQq9VlKgGXHTP//uUOe8lgBYsEKEAtWgFiwAsSCFSAWrACxYAWIBStALFgBYsEKEAtWgFiwAv8PtgllwJJkkEEAAAAASUVORK5CYII="},72777:(e,n,r)=>{r.d(n,{Z:()=>o});const o=r.p+"assets/images/3740981520744e6a3831ba5f2c811e23-106e5055d34c120f2b335ea3aba40314.png"},58702:(e,n,r)=>{r.d(n,{Z:()=>o});const o=r.p+"assets/images/4aad1989545e9fe67cf46de3b06686aa-7022a469373d941eaa2919880d0b2208.png"},51655:(e,n,r)=>{r.d(n,{Z:()=>o});const o=r.p+"assets/images/56387af30ed4e111df652c5918f36313-1e1464e580139e1f73d3f5767a289e7b.png"},79389:(e,n,r)=>{r.d(n,{Z:()=>o});const o=r.p+"assets/images/69a078ee228fa5ae63e91ea8bd45b6db-a2ac2242284aea23d03782ff95610d8d.png"},24590:(e,n,r)=>{r.d(n,{Z:()=>o});const o=r.p+"assets/images/8f5ef1007b9eaddab88adadfff9f6101-e77077195fa46dbde29702f9daf7868f.png"},10170:(e,n,r)=>{r.d(n,{Z:()=>o});const o=r.p+"assets/images/990043747df320652c2ab0944f259f73-761ef5610b70d9606c2b3af927da6fcc.png"},29828:(e,n,r)=>{r.d(n,{Z:()=>o});const o=r.p+"assets/images/adbc81d2a903ede5454eeb85c2ca5743-b93888a4701c77c59047144100f555d8.png"},11151:(e,n,r)=>{r.d(n,{Z:()=>c,a:()=>s});var o=r(67294);const d={},i=o.createContext(d);function s(e){const n=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(d):e.components||d:s(e.components),o.createElement(i.Provider,{value:n},e.children)}}}]);
\ No newline at end of file
diff --git a/assets/js/runtime~main.066caa2e.js b/assets/js/runtime~main.70873899.js
similarity index 99%
rename from assets/js/runtime~main.066caa2e.js
rename to assets/js/runtime~main.70873899.js
index 69d7ee0fbe4..028d1f3fcec 100644
--- a/assets/js/runtime~main.066caa2e.js
+++ b/assets/js/runtime~main.70873899.js
@@ -1 +1 @@
-(()=>{"use strict";var e,b,a,f,c,d={},t={};function r(e){var b=t[e];if(void 0!==b)return b.exports;var a=t[e]={id:e,loaded:!1,exports:{}};return d[e].call(a.exports,a,a.exports,r),a.loaded=!0,a.exports}r.m=d,r.c=t,e=[],r.O=(b,a,f,c)=>{if(!a){var d=1/0;for(i=0;iPProf3、当前进程中的 goroutine
详情
![](/assets/images/4aad1989545e9fe67cf46de3b06686aa-7022a469373d941eaa2919880d0b2208.png)
性能采集分析🔥
+以下示例截图来源于示例项目,仅供参考。
如果想要进行详细的性能分析,基本上离不开 go tool pprof
命令行工具的支持,在开启性能分析支持后,我们可以使用以下命令执行性能采集分析:
-go tool pprof "http://127.0.0.1:8199/debug/pprof/profile"
-执行后 pprof
工具经过约 30
秒左右的接口信息采集(这 30
秒期间 WebServer
应当有流量进入,我们这里不停地访问 hello world
页面以作测试),然后生成性能分析报告,随后可以通过 top10
/ web
等 pprof
命令查看报告结果,更多命令可使用 go tool pprof
查看。关于 pprof
的详细使用介绍,请查看 Golang
官方: blog.golang.org/profiling-go-programs
+go tool pprof -http :8080 "http://127.0.0.1:8199/debug/pprof/profile"
+也可以将pprof文件导出后再通过go tool pprof命令打开:
+curl http://127.0.0.1:8199/debug/pprof/profile > pprof.profile
go tool pprof -http :8080 pprof.profile
+执行后 profile
的 pprof
工具经过约 30
秒左右的接口信息采集(这 30
秒期间 WebServer
应当有流量进入),然后生成性能分析报告,随后可以通过 top10
/ web
等 pprof
命令查看报告结果,更多命令可使用 go tool pprof
查看。关于 pprof
的详细使用介绍,请查看 Golang
官方: blog.golang.org/profiling-go-programs
CPU性能分析
本示例中的命令行性能分析结果如下:
-$ go tool pprof "http://127.0.0.1:8199/debug/pprof/profile"
Fetching profile over HTTP from http://127.0.0.1:8199/debug/pprof/profile
Saved profile in /home/john/pprof/pprof.___go_build_pprof_go.samples.cpu.001.pb.gz
File: ___go_build_pprof_go
Type: cpu
Time: Apr 17, 2018 at 10:53pm (CST)
Duration: 30s, Total samples = 80ms ( 0.27%)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top10
Showing nodes accounting for 80ms, 100% of 80ms total
Showing top 10 nodes out of 49
flat flat% sum% cum cum%
10ms 12.50% 12.50% 10ms 12.50% github.com/gogf/gf/v2/net/ghttp.(*Cookie).Get /home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/v2/net/ghttp/http_server_cookie.go
10ms 12.50% 25.00% 10ms 12.50% internal/poll.runtime_pollReset /home/john/Softs/go1.9.2/src/runtime/netpoll.go
10ms 12.50% 37.50% 10ms 12.50% runtime.futex /home/john/Softs/go1.9.2/src/runtime/sys_linux_amd64.s
10ms 12.50% 50.00% 10ms 12.50% runtime.getitab /home/john/Softs/go1.9.2/src/runtime/iface.go
10ms 12.50% 62.50% 10ms 12.50% runtime.newarray /home/john/Softs/go1.9.2/src/runtime/slice.go
10ms 12.50% 75.00% 10ms 12.50% runtime.rawstringtmp /home/john/Softs/go1.9.2/src/runtime/string.go
10ms 12.50% 87.50% 10ms 12.50% runtime.usleep /home/john/Softs/go1.9.2/src/runtime/sys_linux_amd64.s
10ms 12.50% 100% 10ms 12.50% sync.(*RWMutex).Lock /home/john/Softs/go1.9.2/src/sync/rwmutex.go
0 0% 100% 10ms 12.50% bufio.(*Writer).Flush /home/john/Softs/go1.9.2/src/bufio/bufio.go
0 0% 100% 10ms 12.50% github.com/gogf/gf/v2/container/gqueue.(*Queue).PopFront /home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/v2/container/gqueue/gqueue.go
(pprof) web
Failed to execute dot. Is Graphviz installed? Error: exec: "dot": executable file not found in $PATH
(pprof) web
(pprof)
-其中 web
命令用以图形展示接口之间的调用关系以及性能情况,但是需要安装 Graphviz
图形化工具,以我目前的系统为 Ubuntu
为例,直接执行 sudo apt-get install graphviz
命令即可安装完成图形化工具(如果是 MacOS
,使用 brew install Graphviz
安装),随后再次使用 web
命令,最终生成以下图表:
-![](/assets/images/9f9678e7f3697dfe7c351ac613364eab-1704346158f12132ba0cf70903533de5.png)
+$ go tool pprof -http :8080 "http://127.0.0.1:8199/debug/pprof/profile"
Serving web UI on http://localhost:8080
+图形化展示 pprof
需要安装 Graphviz
图形化工具,以我目前的系统为 Ubuntu
为例,直接执行 sudo apt-get install graphviz
命令即可安装完成图形化工具(如果是 MacOS
,使用 brew install Graphviz
安装)。
+运行后将会使用默认的浏览器打开以下图形界面,展示这段时间抓取的CPU开销链路:
+![](/assets/images/56387af30ed4e111df652c5918f36313-1e1464e580139e1f73d3f5767a289e7b.png)
+也可以查看火炬图,可能更形象一些:
+![](/assets/images/69a078ee228fa5ae63e91ea8bd45b6db-a2ac2242284aea23d03782ff95610d8d.png)
内存使用分析
-与CPU性能分析类似,内存使用分析同样使用到 go tool pprof
命令:
-$ go tool pprof http://127.0.0.1:8299/debug/pprof/heap
Fetching profile over HTTP from http://127.0.0.1:8299/debug/pprof/heap
Saved profile in /Users/john/pprof/pprof.alloc_objects.alloc_space.inuse_objects.inuse_space.004.pb.gz
Type: inuse_space
Time: May 24, 2021 at 8:01pm (CST)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top
Showing nodes accounting for 1536.39kB, 100% of 1536.39kB total
Showing top 10 nodes out of 19
flat flat% sum% cum cum%
512.19kB 33.34% 33.34% 512.19kB 33.34% runtime.malg
512.14kB 33.33% 66.67% 512.14kB 33.33% github.com/gogf/gf/v2/container/gmap.(*StrAnyMap).doSetWithLockCheck
512.06kB 33.33% 100% 512.06kB 33.33% net.newFD (inline)
0 0% 100% 512.14kB 33.33% github.com/gogf/gf/v2/container/gmap.(*StrAnyMap).GetOrSetFuncLock
0 0% 100% 512.06kB 33.33% github.com/gogf/gf/v2/net/ghttp.(*Server).startServer.func1
0 0% 100% 512.06kB 33.33% github.com/gogf/gf/v2/net/ghttp.(*gracefulServer).ListenAndServe
0 0% 100% 512.06kB 33.33% github.com/gogf/gf/v2/net/ghttp.(*gracefulServer).doServe
0 0% 100% 512.14kB 33.33% github.com/gogf/gf/v2/os/gres.Instance
0 0% 100% 512.14kB 33.33% github.com/gogf/gf/v2/os/gres.init
0 0% 100% 512.06kB 33.33% net.(*TCPListener).Accept
(pprof) web
(pprof)
-通过 web
图形展示,类似这样的:
-![](/assets/images/c90f14644e3cf7c2f84f79c14e81ec40-32dd4e0832c52c08a332b0393781115c.png)
+与 CPU
性能分析类似,内存使用分析同样使用到 go tool pprof
命令:
+$ go tool pprof -http :8080 "http://127.0.0.1:8199/debug/pprof/heap"
Serving web UI on http://localhost:8080
+图形展示类似这样的:
+![](/assets/images/3740981520744e6a3831ba5f2c811e23-106e5055d34c120f2b335ea3aba40314.png)
+同样的,也可以查看火炬图,可能更形象一些:
+![](/assets/images/8f5ef1007b9eaddab88adadfff9f6101-e77077195fa46dbde29702f9daf7868f.png)
+goroutine使用分析
+与上面的分析类似,goroutine使用分析同样使用到 go tool pprof
命令:
+$ go tool pprof -http :8080 "http://127.0.0.1:8199/debug/pprof/goroutine"
Serving web UI on http://localhost:8080
+图形展示类似这样的,通常goroutine看这个图的话就差不多了,当然也有火炬图。
+![](/assets/images/adbc81d2a903ede5454eeb85c2ca5743-b93888a4701c77c59047144100f555d8.png)