{"id":7026,"date":"2026-03-03T16:14:52","date_gmt":"2026-03-03T08:14:52","guid":{"rendered":"https:\/\/t.n-years.com\/?p=7026"},"modified":"2026-03-03T16:14:52","modified_gmt":"2026-03-03T08:14:52","slug":"openresty-%e4%bd%9c%e8%80%85%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=7026","title":{"rendered":"OpenResty \u4f5c\u8005\u4ecb\u7ecd"},"content":{"rendered":"<blockquote>\n<p>Gemini \u751f\u6210<\/p>\n<\/blockquote>\n<p>\u4f5c\u4e3a\u6280\u672f\u987e\u95ee\uff0c\u63d0\u5230 OpenResty \u5c31\u4e0d\u5f97\u4e0d\u63d0\u5b83\u7684\u7075\u9b42\u4eba\u7269\u2014\u2014<strong>\u7ae0\u4ea6\u6625\uff08agentzh\uff09<\/strong>\u3002<\/p>\n<p>\u5728\u5f00\u53d1\u8005\u5708\u5b50\u91cc\uff0c\u7ae0\u4ea6\u6625\u4ee5\u5176\u6781\u81f4\u7684<strong>\u4ee3\u7801\u8d28\u91cf\u8ffd\u6c42<\/strong>\u548c\u5bf9<strong>\u6027\u80fd\u4f18\u5316<\/strong>\u7684\u6267\u7740\u800c\u95fb\u540d\u3002\u4ed6\u4e0d\u4ec5\u662f OpenResty \u7684\u5f00\u6e90\u9879\u76ee\u521b\u5efa\u8005\uff0c\u4e5f\u662f Nginx\u3001LuaJIT \u7b49\u6838\u5fc3\u5f00\u6e90\u793e\u533a\u7684\u91cd\u8981\u8d21\u732e\u8005\u3002<\/p>\n<hr \/>\n<h3>\u7ae0\u4ea6\u6625 (Yichun Zhang) \u7684\u6280\u672f\u80cc\u666f<\/h3>\n<ol>\n<li>\n<p><strong>\u804c\u4e1a\u751f\u6daf<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4ed6\u66fe\u5148\u540e\u5c31\u804c\u4e8e <strong>Yahoo! \u4e2d\u56fd<\/strong>\u3001<strong>\u6dd8\u5b9d\uff08\u963f\u91cc\u5df4\u5df4\uff09<\/strong>\u4ee5\u53ca <strong>Cloudflare<\/strong>\u3002<\/li>\n<li>\u5728 Cloudflare \u4efb\u804c\u671f\u95f4\uff0c\u4ed6\u5c06 OpenResty \u5e94\u7528\u5230\u4e86\u5168\u7403\u89c4\u6a21\u6700\u5927\u7684\u7f51\u7edc\u57fa\u7840\u8bbe\u65bd\u4e4b\u4e00\uff0c\u8d1f\u8d23\u5904\u7406\u5168\u7403\u7ea6 10% \u751a\u81f3\u66f4\u591a\u7684\u4e92\u8054\u7f51\u6d41\u91cf\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6838\u5fc3\u6210\u5c31<\/strong>\uff1a<\/p>\n<ul>\n<li><strong>\u521b\u5efa OpenResty<\/strong>\uff1a\u5c06 Nginx \u6838\u5fc3\u4e0e\u4f17\u591a\u7684\u7b2c\u4e09\u65b9\u6a21\u5757\uff08\u5c24\u5176\u662f Lua \u6a21\u5757\uff09\u8fdb\u884c\u6df1\u5ea6\u6574\u5408\u3002<\/li>\n<li><strong>Nginx \u6838\u5fc3\u8d21\u732e\u8005<\/strong>\uff1a\u4ed6\u5728 Nginx \u793e\u533a\u62e5\u6709\u6781\u9ad8\u7684\u58f0\u671b\uff0c\u5411 Nginx \u63d0\u4ea4\u4e86\u5927\u91cf\u7684\u8865\u4e01\u548c\u7279\u6027\u3002<\/li>\n<li><strong>\u52a8\u6001\u8ffd\u8e2a\u4e13\u5bb6<\/strong>\uff1a\u4ed6\u662f <strong>SystemTap<\/strong> \u548c <strong>eBPF<\/strong> \u5de5\u5177\u94fe\u7684\u4e13\u5bb6\uff0c\u5f00\u53d1\u4e86\u5927\u91cf\u7528\u4e8e\u751f\u4ea7\u73af\u5883\u5728\u7ebf\u8c03\u8bd5\u548c\u6027\u80fd\u5206\u6790\u7684\u5f00\u6e90\u5de5\u5177\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr \/>\n<h3>\u7ae0\u4ea6\u6625\u7684\u5f00\u53d1\u54f2\u5b66\uff1a\u4e3a\u4ec0\u4e48 OpenResty \u8fd9\u4e48\u5f3a\uff1f<\/h3>\n<p>\u901a\u8fc7\u5206\u6790\u4ed6\u7684\u4ee3\u7801\u548c\u6f14\u8bb2\uff0c\u6211\u4eec\u53ef\u4ee5\u603b\u7ed3\u51fa\u4ed6\u5728\u8bbe\u8ba1 OpenResty \u65f6\u7684\u4e09\u4e2a\u6838\u5fc3\u7406\u5ff5\uff1a<\/p>\n<h4>1. \u62d2\u7edd\u963b\u585e\uff08Non-blocking EVERYTHING\uff09<\/h4>\n<p>\u4ed6\u975e\u5e38\u538c\u6076\u4efb\u4f55\u53ef\u80fd\u5bfc\u81f4 Nginx Worker \u8fdb\u7a0b\u963b\u585e\u7684\u64cd\u4f5c\u3002\u4ed6\u5f00\u53d1\u7684 <code>cosocket<\/code> \u6280\u672f\u662f OpenResty \u7684\u57fa\u77f3\uff0c\u8ba9\u5f00\u53d1\u8005\u53ef\u4ee5\u7528 Lua \u5199\u540c\u6b65\u4ee3\u7801\uff0c\u4f46\u8dd1\u51fa\u5f02\u6b65\u975e\u963b\u585e\u7684\u6027\u80fd\u3002<\/p>\n<h4>2. \u6781\u81f4\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5<\/h4>\n<p>\u7ae0\u4ea6\u6625\u5bf9\u6d4b\u8bd5\u6709\u7740\u8fd1\u4e4e\u201c\u75af\u72c2\u201d\u7684\u8981\u6c42\u3002OpenResty \u7684\u6d4b\u8bd5\u5957\u4ef6\u975e\u5e38\u5e9e\u5927\uff0c\u4ed6\u4e13\u95e8\u5f00\u53d1\u4e86\u4e00\u5957\u540d\u4e3a <strong>Test::Nginx<\/strong> \u7684\u6d4b\u8bd5\u6846\u67b6\u3002<\/p>\n<blockquote>\n<p><strong>\u987e\u95ee\u7b14\u8bb0<\/strong>\uff1a\u4f60\u53ef\u4ee5\u53bb GitHub \u770b\u4e00\u4e0b\u4ed6\u7684\u9879\u76ee\uff0c\u6d4b\u8bd5\u7528\u4f8b\u7684\u6570\u91cf\u5f80\u5f80\u662f\u4e1a\u52a1\u4ee3\u7801\u7684\u6570\u500d\u3002\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48 OpenResty \u5728\u751f\u4ea7\u73af\u5883\u4e2d\u6781\u5ea6\u7a33\u5b9a\u7684\u539f\u56e0\u3002<\/p>\n<\/blockquote>\n<h4>3. \u52a8\u6001\u8ffd\u8e2a\uff08Dynamic Tracing\uff09<\/h4>\n<p>\u4ed6\u4e3b\u5f20\u201c\u4e0d\u8981\u731c\u6d4b\u6027\u80fd\u74f6\u9888\u201d\u3002\u4ed6\u5f00\u53d1\u7684\u8bb8\u591a\u5de5\u5177\uff08\u5982 <code>stap++<\/code> \u811a\u672c\uff09\u53ef\u4ee5\u76f4\u63a5\u5728\u4e0d\u91cd\u542f\u670d\u52a1\u7684\u60c5\u51b5\u4e0b\uff0c\u52a8\u6001\u89c2\u5bdf\u751f\u4ea7\u73af\u5883 Nginx \u8fdb\u7a0b\u5185\u90e8\u7684 Lua \u4ee3\u7801\u6267\u884c\u60c5\u51b5\u3002<\/p>\n<hr \/>\n<h3>\u4e2a\u4eba\u8f76\u4e8b\u4e0e\u5f71\u54cd\u529b<\/h3>\n<ul>\n<li><strong>\u201c\u4ee3\u7801\u6d01\u7656\u201d<\/strong>\uff1a\u4ed6\u7684\u4ee3\u7801\u98ce\u683c\u6781\u5176\u4e25\u8c28\uff0c\u751a\u81f3\u5bf9 C \u8bed\u8a00\u7684\u7f29\u8fdb\u548c\u7a7a\u683c\u90fd\u6709\u8fd1\u4e4e\u82db\u523b\u7684\u8981\u6c42\uff0c\u8fd9\u4e5f\u4fdd\u8bc1\u4e86 OpenResty \u6e90\u7801\u7684\u53ef\u8bfb\u6027\u548c\u5065\u58ee\u6027\u3002<\/li>\n<li><strong>\u5f00\u6e90\u7cbe\u795e<\/strong>\uff1a\u4ed6\u51e0\u4e4e\u5c06\u6240\u6709\u7684\u5de5\u4f5c\u7cbe\u529b\u90fd\u6295\u5165\u5230\u4e86\u5f00\u6e90\u9879\u76ee\u4e2d\u3002\u5373\u4f7f\u540e\u6765\u521b\u7acb\u4e86 <strong>OpenResty Inc.<\/strong> \u5546\u4e1a\u516c\u53f8\uff0c\u4ed6\u4f9d\u7136\u4fdd\u6301\u7740\u9ad8\u9891\u7387\u7684\u5f00\u6e90\u4ea7\u51fa\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>\u987e\u95ee\u603b\u7ed3\uff1a<\/h3>\n<p>\u7406\u89e3\u4e86\u4f5c\u8005\u7684\u80cc\u666f\uff0c\u4f60\u5c31\u4f1a\u660e\u767d\u4e3a\u4ec0\u4e48 OpenResty \u4f1a\u88ab\u8bbe\u8ba1\u6210\u73b0\u5728\u8fd9\u4e2a\u6837\u5b50\uff1a<strong>\u5b83\u4e0d\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5de5\u5177\u96c6\uff0c\u800c\u662f\u4e00\u5957\u4e3a\u4e86\u5904\u7406\u6d77\u91cf\u5e76\u53d1\u3001\u8ffd\u6c42\u6781\u81f4\u6027\u80fd\u548c\u7ebf\u4e0a\u9ad8\u53ef\u89c2\u6d4b\u6027\u800c\u751f\u7684\u5de5\u7a0b\u4f53\u7cfb\u3002<\/strong><\/p>\n<p>\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48\u50cf <strong>APISIX<\/strong> (\u7531\u4e2d\u56fd\u5f00\u53d1\u8005\u9886\u5bfc\u7684\u9876\u7ea7 API \u7f51\u5173\u9879\u76ee) \u548c <strong>Kong<\/strong> (\u5168\u7403\u6700\u6d41\u884c\u7684 API \u7f51\u5173) \u90fd\u4f1a\u9009\u62e9 OpenResty \u4f5c\u4e3a\u5e95\u5c42\u3002<\/p>\n<p><strong>\u4f60\u60f3\u6df1\u5165\u4e86\u89e3\u4e00\u4e0b\u7ae0\u4ea6\u6625\u63a8\u5d07\u7684\u201c\u52a8\u6001\u8ffd\u8e2a\u201d\u6280\u672f\uff08\u5982\u4f55\u5728\u7ebf\u6392\u67e5 Nginx \u6027\u80fd\u95ee\u9898\uff09\uff0c\u8fd8\u662f\u60f3\u770b\u770b\u7531\u4ed6\u4e3b\u5bfc\u8bbe\u8ba1\u7684 OpenResty \u6d4b\u8bd5\u65b9\u6848\u662f\u5982\u4f55\u4fdd\u8bc1\u4ee3\u7801\u5065\u58ee\u6027\u7684\uff1f<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Gemini \u751f\u6210 \u4f5c\u4e3a\u6280\u672f\u987e\u95ee\uff0c\u63d0\u5230 OpenResty \u5c31\u4e0d\u5f97\u4e0d\u63d0\u5b83\u7684\u7075\u9b42\u4eba\u7269\u2014\u2014\u7ae0\u4ea6\u6625\uff08agentzh\uff09&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=7026\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-7026","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/7026","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7026"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/7026\/revisions"}],"predecessor-version":[{"id":7027,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/7026\/revisions\/7027"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}