{"id":18399,"date":"2025-04-19T00:48:07","date_gmt":"2025-04-18T16:48:07","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/18399.html"},"modified":"2025-04-19T00:48:07","modified_gmt":"2025-04-18T16:48:07","slug":"%e5%a4%a7%e6%a8%a1%e5%9e%8b%e5%bf%ab%e9%80%9f-asgi-%e6%9c%8d%e5%8a%a1%e5%99%a8uvicorn","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/18399.html","title":{"rendered":"\u5927\u6a21\u578b\u5feb\u901f ASGI \u670d\u52a1\u5668uvicorn"},"content":{"rendered":"<h4>\u57fa\u7840\u6982\u5ff5\u7c7b<\/h4>\n<h5>1. \u4ec0\u4e48\u662f Uvicorn&#xff0c;\u5b83\u7684\u4f5c\u7528\u662f\u4ec0\u4e48&#xff1f;<\/h5>\n<p>\u7b54\u6848&#xff1a;Uvicorn \u662f\u4e00\u4e2a\u57fa\u4e8e Python \u7684\u5feb\u901f ASGI&#xff08;\u5f02\u6b65\u670d\u52a1\u5668\u7f51\u5173\u63a5\u53e3&#xff09;\u670d\u52a1\u5668\u3002\u5b83\u7684\u4e3b\u8981\u4f5c\u7528\u662f\u4f5c\u4e3a Web \u5e94\u7528\u7a0b\u5e8f\u7684\u670d\u52a1\u5668&#xff0c;\u8d1f\u8d23\u63a5\u6536\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42&#xff0c;\u5e76\u5c06\u8bf7\u6c42\u4f20\u9012\u7ed9\u5e94\u7528\u7a0b\u5e8f\u5904\u7406&#xff0c;\u7136\u540e\u5c06\u5e94\u7528\u7a0b\u5e8f\u7684\u54cd\u5e94\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002\u7531\u4e8e\u91c7\u7528\u5f02\u6b65\u7f16\u7a0b\u6a21\u578b&#xff0c;\u5b83\u80fd\u9ad8\u6548\u5904\u7406\u5927\u91cf\u5e76\u53d1\u8bf7\u6c42&#xff0c;\u63d0\u5347\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u54cd\u5e94\u901f\u5ea6\u3002<\/p>\n<h5>2. \u7b80\u8ff0 ASGI \u4ee5\u53ca Uvicorn \u4e0e ASGI \u7684\u5173\u7cfb\u3002<\/h5>\n<p>\u7b54\u6848&#xff1a;ASGI \u5373\u5f02\u6b65\u670d\u52a1\u5668\u7f51\u5173\u63a5\u53e3&#xff0c;\u662f\u4e3a\u4e86\u652f\u6301 Python \u5f02\u6b65 Web \u5e94\u7528\u7a0b\u5e8f\u800c\u8bbe\u8ba1\u7684\u6807\u51c6\u63a5\u53e3&#xff0c;\u5b83\u5141\u8bb8\u5f02\u6b65 Web \u670d\u52a1\u5668\u3001\u6846\u67b6\u548c\u4e2d\u95f4\u4ef6\u4e4b\u95f4\u8fdb\u884c\u4ea4\u4e92\u3002Uvicorn \u662f\u4e00\u4e2a\u5b9e\u73b0\u4e86 ASGI \u6807\u51c6\u7684\u670d\u52a1\u5668&#xff0c;\u5b83\u53ef\u4ee5\u8fd0\u884c\u7b26\u5408 ASGI \u89c4\u8303\u7684 Web \u5e94\u7528\u7a0b\u5e8f&#xff0c;\u6bd4\u5982 FastAPI\u3001Starlette \u7b49\u6846\u67b6\u6784\u5efa\u7684\u5e94\u7528\u3002<\/p>\n<h4>\u5b89\u88c5\u4e0e\u4f7f\u7528\u7c7b<\/h4>\n<h5>3. \u5982\u4f55\u5b89\u88c5 Uvicorn&#xff1f;<\/h5>\n<p>\u7b54\u6848&#xff1a;\u53ef\u4ee5\u4f7f\u7528 Python \u7684\u5305\u7ba1\u7406\u5de5\u5177 pip \u6765\u5b89\u88c5 Uvicorn&#xff0c;\u5728\u547d\u4ee4\u884c\u4e2d\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4&#xff1a;<\/p>\n<p>pip <span class=\"token function\">install<\/span> uvicorn<\/p>\n<h5>4. \u600e\u6837\u542f\u52a8\u4e00\u4e2a\u7b80\u5355\u7684 Uvicorn \u670d\u52a1\u5668&#xff1f;<\/h5>\n<p>\u7b54\u6848&#xff1a;\u5047\u8bbe\u4f60\u6709\u4e00\u4e2a\u7b80\u5355\u7684 ASGI \u5e94\u7528\u7a0b\u5e8f&#xff0c;\u4f8b\u5982\u4e00\u4e2a\u4f7f\u7528 FastAPI \u6784\u5efa\u7684\u5e94\u7528&#xff0c;\u4fdd\u5b58\u5728 main.py \u6587\u4ef6\u4e2d&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> fastapi <span class=\"token keyword\">import<\/span> FastAPI<\/p>\n<p>app <span class=\"token operator\">&#061;<\/span> FastAPI<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token decorator annotation punctuation\">&#064;app<span class=\"token punctuation\">.<\/span>get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">async<\/span> <span class=\"token keyword\">def<\/span> <span class=\"token function\">read_root<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;Hello&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;World&#034;<\/span><span class=\"token punctuation\">}<\/span><\/p>\n<p>\u5728\u547d\u4ee4\u884c\u4e2d&#xff0c;\u8fdb\u5165\u5305\u542b main.py \u6587\u4ef6\u7684\u76ee\u5f55&#xff0c;\u7136\u540e\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8 Uvicorn \u670d\u52a1\u5668&#xff1a;<\/p>\n<p>uvicorn main:app &#8211;reload<\/p>\n<p>\u8fd9\u91cc\u7684 main:app \u8868\u793a main.py \u6587\u4ef6\u4e2d\u7684 app \u5b9e\u4f8b&#xff0c;&#8211;reload \u7528\u4e8e\u5f00\u542f\u70ed\u91cd\u8f7d\u529f\u80fd&#xff0c;\u65b9\u4fbf\u5f00\u53d1\u8c03\u8bd5\u3002<\/p>\n<h4>\u6027\u80fd\u4e0e\u914d\u7f6e\u7c7b<\/h4>\n<h5>5. Uvicorn \u6709\u54ea\u4e9b\u63d0\u5347\u6027\u80fd\u7684\u65b9\u6cd5&#xff1f;<\/h5>\n<p>\u7b54\u6848&#xff1a;<\/p>\n<ul>\n<li>\u589e\u52a0\u5de5\u4f5c\u8fdb\u7a0b\u6570\u91cf&#xff1a;\u901a\u8fc7 &#8211;workers \u53c2\u6570\u6307\u5b9a\u66f4\u591a\u7684\u5de5\u4f5c\u8fdb\u7a0b&#xff0c;\u53ef\u5145\u5206\u5229\u7528\u591a\u6838 CPU \u7684\u6027\u80fd\u3002\u4f8b\u5982&#xff1a;<\/li>\n<\/ul>\n<p>uvicorn main:app &#8211;workers <span class=\"token number\">4<\/span><\/p>\n<ul>\n<li>\u4f7f\u7528\u5f02\u6b65 I\/O&#xff1a;\u786e\u4fdd\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684 I\/O \u64cd\u4f5c\u4f7f\u7528\u5f02\u6b65\u65b9\u5f0f&#xff0c;\u8fd9\u6837\u53ef\u4ee5\u5728\u7b49\u5f85 I\/O \u5b8c\u6210\u65f6\u5904\u7406\u5176\u4ed6\u8bf7\u6c42\u3002<\/li>\n<li>\u4f18\u5316\u5e94\u7528\u4ee3\u7801&#xff1a;\u907f\u514d\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8fdb\u884c\u963b\u585e\u64cd\u4f5c&#xff0c;\u5982\u957f\u65f6\u95f4\u7684\u8ba1\u7b97\u6216\u540c\u6b65 I\/O \u8c03\u7528\u3002<\/li>\n<\/ul>\n<h5>6. \u5982\u4f55\u914d\u7f6e Uvicorn \u7684\u65e5\u5fd7\u7ea7\u522b&#xff1f;<\/h5>\n<p>\u7b54\u6848&#xff1a;\u53ef\u4ee5\u4f7f\u7528 &#8211;log-level \u53c2\u6570\u6765\u914d\u7f6e Uvicorn \u7684\u65e5\u5fd7\u7ea7\u522b\u3002\u5e38\u89c1\u7684\u65e5\u5fd7\u7ea7\u522b\u6709 debug\u3001info\u3001warning\u3001error \u7b49\u3002\u4f8b\u5982&#xff0c;\u5c06\u65e5\u5fd7\u7ea7\u522b\u8bbe\u7f6e\u4e3a debug&#xff1a;<\/p>\n<p>uvicorn main:app &#8211;log-level debug<\/p>\n<h4>\u95ee\u9898\u6392\u67e5\u4e0e\u5e94\u7528\u573a\u666f\u7c7b<\/h4>\n<h5>7. \u5982\u679c Uvicorn \u670d\u52a1\u5668\u542f\u52a8\u5931\u8d25&#xff0c;\u53ef\u80fd\u7684\u539f\u56e0\u6709\u54ea\u4e9b&#xff1f;<\/h5>\n<p>\u7b54\u6848&#xff1a;<\/p>\n<ul>\n<li>\u7aef\u53e3\u88ab\u5360\u7528&#xff1a;\u82e5\u6307\u5b9a\u7684\u7aef\u53e3\u5df2\u88ab\u5176\u4ed6\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528&#xff0c;Uvicorn \u65e0\u6cd5\u7ed1\u5b9a\u8be5\u7aef\u53e3&#xff0c;\u5bfc\u81f4\u542f\u52a8\u5931\u8d25\u3002\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539 &#8211;port \u53c2\u6570\u6765\u6307\u5b9a\u5176\u4ed6\u7aef\u53e3\u3002<\/li>\n<li>\u5e94\u7528\u4ee3\u7801\u9519\u8bef&#xff1a;\u5e94\u7528\u7a0b\u5e8f\u4ee3\u7801\u5b58\u5728\u8bed\u6cd5\u9519\u8bef\u3001\u5bfc\u5165\u9519\u8bef\u6216\u5176\u4ed6\u903b\u8f91\u9519\u8bef&#xff0c;\u4f1a\u4f7f Uvicorn \u65e0\u6cd5\u6b63\u786e\u52a0\u8f7d\u5e94\u7528\u3002\u9700\u8981\u68c0\u67e5\u5e94\u7528\u4ee3\u7801\u5e76\u4fee\u590d\u9519\u8bef\u3002<\/li>\n<li>\u4f9d\u8d56\u7f3a\u5931&#xff1a;\u5e94\u7528\u7a0b\u5e8f\u4f9d\u8d56\u7684\u5e93\u672a\u6b63\u786e\u5b89\u88c5&#xff0c;\u4f1a\u5bfc\u81f4\u542f\u52a8\u5931\u8d25\u3002\u8981\u786e\u4fdd\u6240\u6709\u4f9d\u8d56\u9879\u90fd\u5df2\u5b89\u88c5\u3002<\/li>\n<\/ul>\n<h5>8. \u4e3e\u4f8b\u8bf4\u660e Uvicorn \u7684\u5e94\u7528\u573a\u666f\u3002<\/h5>\n<p>\u7b54\u6848&#xff1a;<\/p>\n<ul>\n<li>Web \u5e94\u7528\u5f00\u53d1&#xff1a;\u5728\u4f7f\u7528 FastAPI\u3001Starlette \u7b49\u5f02\u6b65 Web \u6846\u67b6\u5f00\u53d1 Web \u5e94\u7528\u65f6&#xff0c;Uvicorn \u53ef\u4f5c\u4e3a\u751f\u4ea7\u73af\u5883\u7684\u670d\u52a1\u5668&#xff0c;\u9ad8\u6548\u5904\u7406\u5927\u91cf\u5e76\u53d1\u8bf7\u6c42\u3002<\/li>\n<li>\u5b9e\u65f6\u5e94\u7528&#xff1a;\u5982\u804a\u5929\u5e94\u7528\u3001\u5b9e\u65f6\u6570\u636e\u76d1\u63a7\u7cfb\u7edf\u7b49&#xff0c;\u9700\u8981\u5904\u7406\u5927\u91cf\u5b9e\u65f6\u8fde\u63a5\u548c\u6d88\u606f&#xff0c;Uvicorn \u7684\u5f02\u6b65\u7279\u6027\u80fd\u591f\u5f88\u597d\u5730\u6ee1\u8db3\u8fd9\u4e9b\u9700\u6c42\u3002<\/li>\n<\/ul>\n<h4>\u539f\u7406\u4e0e\u67b6\u6784\u7c7b<\/h4>\n<h5>9. \u7b80\u8ff0 Uvicorn \u7684\u5de5\u4f5c\u539f\u7406\u3002<\/h5>\n<p>\u7b54\u6848&#xff1a;Uvicorn \u57fa\u4e8e\u5f02\u6b65 I\/O \u6a21\u578b&#xff0c;\u5176\u5de5\u4f5c\u539f\u7406\u4e3b\u8981\u5305\u62ec\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4&#xff1a;<\/p>\n<ul>\n<li>\u76d1\u542c\u7aef\u53e3&#xff1a;\u542f\u52a8\u65f6&#xff0c;Uvicorn \u4f1a\u76d1\u542c\u6307\u5b9a\u7684\u4e3b\u673a\u548c\u7aef\u53e3&#xff0c;\u7b49\u5f85\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u8bf7\u6c42\u3002<\/li>\n<li>\u63a5\u53d7\u8fde\u63a5&#xff1a;\u5f53\u6709\u5ba2\u6237\u7aef\u8fde\u63a5\u8bf7\u6c42\u5230\u8fbe\u65f6&#xff0c;Uvicorn \u4f1a\u5f02\u6b65\u5730\u63a5\u53d7\u8fde\u63a5&#xff0c;\u5c06\u8fde\u63a5\u4ea4\u7ed9\u5f02\u6b65\u5904\u7406\u7a0b\u5e8f\u3002<\/li>\n<li>\u89e3\u6790\u8bf7\u6c42&#xff1a;\u5c06\u5ba2\u6237\u7aef\u53d1\u9001\u7684 HTTP \u8bf7\u6c42\u89e3\u6790\u6210 ASGI \u89c4\u8303\u7684\u4e8b\u4ef6&#xff0c;\u5982 http.request \u4e8b\u4ef6\u3002<\/li>\n<li>\u4f20\u9012\u8bf7\u6c42&#xff1a;\u628a\u89e3\u6790\u540e\u7684\u4e8b\u4ef6\u4f20\u9012\u7ed9\u7b26\u5408 ASGI \u89c4\u8303\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u8fdb\u884c\u5904\u7406\u3002<\/li>\n<li>\u5904\u7406\u54cd\u5e94&#xff1a;\u5e94\u7528\u7a0b\u5e8f\u5904\u7406\u5b8c\u8bf7\u6c42\u540e&#xff0c;\u4f1a\u751f\u6210 ASGI \u89c4\u8303\u7684\u54cd\u5e94\u4e8b\u4ef6&#xff0c;Uvicorn \u63a5\u6536\u8fd9\u4e9b\u4e8b\u4ef6\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a HTTP \u54cd\u5e94\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002<\/li>\n<\/ul>\n<h5>10. Uvicorn \u4e0e\u4f20\u7edf\u7684 WSGI \u670d\u52a1\u5668&#xff08;\u5982 Gunicorn&#xff09;\u6709\u4ec0\u4e48\u533a\u522b&#xff1f;<\/h5>\n<p>\u7b54\u6848&#xff1a;<\/p>\n<ul>\n<li>\u63a5\u53e3\u6807\u51c6&#xff1a;Uvicorn \u57fa\u4e8e ASGI \u6807\u51c6&#xff0c;\u652f\u6301\u5f02\u6b65\u7f16\u7a0b&#xff0c;\u80fd\u66f4\u597d\u5730\u5904\u7406\u9ad8\u5e76\u53d1\u7684 I\/O \u5bc6\u96c6\u578b\u4efb\u52a1&#xff1b;\u800c\u4f20\u7edf\u7684 WSGI \u670d\u52a1\u5668\u57fa\u4e8e WSGI \u6807\u51c6&#xff0c;\u53ea\u652f\u6301\u540c\u6b65\u7f16\u7a0b\u3002<\/li>\n<li>\u6027\u80fd\u8868\u73b0&#xff1a;\u5728\u5904\u7406\u5927\u91cf\u5e76\u53d1\u8fde\u63a5\u65f6&#xff0c;Uvicorn \u7531\u4e8e\u5176\u5f02\u6b65\u7279\u6027&#xff0c;\u6027\u80fd\u901a\u5e38\u4f18\u4e8e WSGI \u670d\u52a1\u5668\u3002WSGI \u670d\u52a1\u5668\u5728\u5904\u7406\u6bcf\u4e2a\u8bf7\u6c42\u65f6\u662f\u540c\u6b65\u7684&#xff0c;\u5728\u5904\u7406 I\/O \u64cd\u4f5c\u65f6\u4f1a\u963b\u585e\u7ebf\u7a0b&#xff0c;\u5f71\u54cd\u5e76\u53d1\u5904\u7406\u80fd\u529b\u3002<\/li>\n<li>\u5e94\u7528\u573a\u666f&#xff1a;Uvicorn \u9002\u7528\u4e8e\u73b0\u4ee3\u7684\u5f02\u6b65 Python Web \u6846\u67b6&#xff0c;\u5982 FastAPI\u3001Starlette \u7b49&#xff1b;\u800c WSGI \u670d\u52a1\u5668\u66f4\u9002\u5408\u57fa\u4e8e\u540c\u6b65\u7f16\u7a0b\u7684 Web \u6846\u67b6&#xff0c;\u5982 Django\u3001Flask \u7b49\u3002<\/li>\n<\/ul>\n<h4>\u90e8\u7f72\u4e0e\u96c6\u6210\u7c7b<\/h4>\n<h5>11. \u5982\u4f55\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u90e8\u7f72 Uvicorn&#xff1f;<\/h5>\n<p>\u7b54\u6848&#xff1a;<\/p>\n<ul>\n<li>\u4f7f\u7528\u8fdb\u7a0b\u7ba1\u7406\u5668&#xff1a;\u53ef\u4ee5\u4f7f\u7528 systemd \u6216 supervisor \u7b49\u8fdb\u7a0b\u7ba1\u7406\u5668\u6765\u7ba1\u7406 Uvicorn \u8fdb\u7a0b&#xff0c;\u786e\u4fdd\u5176\u5728\u670d\u52a1\u5668\u91cd\u542f\u540e\u81ea\u52a8\u542f\u52a8&#xff0c;\u5e76\u4e14\u5728\u51fa\u73b0\u5f02\u5e38\u65f6\u80fd\u591f\u81ea\u52a8\u91cd\u542f\u3002\u4f8b\u5982&#xff0c;\u4f7f\u7528 systemd \u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u670d\u52a1\u6587\u4ef6&#xff0c;\u914d\u7f6e Uvicorn \u670d\u52a1\u7684\u542f\u52a8\u53c2\u6570\u548c\u73af\u5883\u53d8\u91cf\u3002<\/li>\n<li>\u53cd\u5411\u4ee3\u7406&#xff1a;\u5728\u751f\u4ea7\u73af\u5883\u4e2d&#xff0c;\u901a\u5e38\u4f1a\u4f7f\u7528 Nginx \u6216 Apache \u7b49\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\u5c06\u8bf7\u6c42\u8f6c\u53d1\u7ed9 Uvicorn \u670d\u52a1\u5668\u3002\u53cd\u5411\u4ee3\u7406\u53ef\u4ee5\u5904\u7406\u9759\u6001\u6587\u4ef6\u3001\u8d1f\u8f7d\u5747\u8861\u3001SSL \u52a0\u5bc6\u7b49\u4efb\u52a1&#xff0c;\u63d0\u9ad8\u7cfb\u7edf\u7684\u5b89\u5168\u6027\u548c\u6027\u80fd\u3002<\/li>\n<li>\u591a\u8fdb\u7a0b\u914d\u7f6e&#xff1a;\u901a\u8fc7 &#8211;workers \u53c2\u6570\u914d\u7f6e\u591a\u4e2a\u5de5\u4f5c\u8fdb\u7a0b&#xff0c;\u5145\u5206\u5229\u7528\u591a\u6838 CPU \u7684\u6027\u80fd\u3002\u540c\u65f6&#xff0c;\u8981\u6ce8\u610f\u5408\u7406\u8c03\u6574\u5de5\u4f5c\u8fdb\u7a0b\u7684\u6570\u91cf&#xff0c;\u907f\u514d\u8d44\u6e90\u8fc7\u5ea6\u5360\u7528\u3002<\/li>\n<\/ul>\n<h5>12. Uvicorn \u53ef\u4ee5\u548c\u54ea\u4e9b Python Web \u6846\u67b6\u96c6\u6210&#xff1f;<\/h5>\n<p>\u7b54\u6848&#xff1a;Uvicorn \u53ef\u4ee5\u4e0e\u591a\u79cd\u7b26\u5408 ASGI \u6807\u51c6\u7684 Python Web \u6846\u67b6\u96c6\u6210&#xff0c;\u5e38\u89c1\u7684\u6709&#xff1a;<\/p>\n<ul>\n<li>FastAPI&#xff1a;\u4e00\u4e2a\u5feb\u901f\u7684 Web \u6846\u67b6&#xff0c;\u57fa\u4e8e Starlette \u548c Pydantic \u6784\u5efa&#xff0c;\u5177\u6709\u9ad8\u6027\u80fd\u3001\u6613\u7528\u6027\u548c\u81ea\u52a8\u751f\u6210 API \u6587\u6863\u7b49\u7279\u70b9&#xff0c;\u4e0e Uvicorn \u7ed3\u5408\u4f7f\u7528\u80fd\u53d1\u6325\u51fa\u5f3a\u5927\u7684\u6027\u80fd\u4f18\u52bf\u3002<\/li>\n<li>Starlette&#xff1a;\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684 ASGI \u6846\u67b6&#xff0c;\u63d0\u4f9b\u4e86\u57fa\u7840\u7684\u8def\u7531\u3001\u4e2d\u95f4\u4ef6\u548c\u8bf7\u6c42\/\u54cd\u5e94\u5904\u7406\u529f\u80fd&#xff0c;\u975e\u5e38\u9002\u5408\u6784\u5efa\u9ad8\u6027\u80fd\u7684 Web \u5e94\u7528\u548c API\u3002<\/li>\n<li>Quart&#xff1a;\u4e00\u4e2a\u5f02\u6b65\u7248\u672c\u7684 Flask \u6846\u67b6&#xff0c;\u4fdd\u7559\u4e86 Flask \u7684\u7b80\u6d01\u6613\u7528\u6027&#xff0c;\u540c\u65f6\u652f\u6301\u5f02\u6b65\u7f16\u7a0b&#xff0c;\u53ef\u4e0e Uvicorn \u65e0\u7f1d\u96c6\u6210\u3002<\/li>\n<\/ul>\n<h4>\u9ad8\u7ea7\u7279\u6027\u4e0e\u4f18\u5316\u7c7b<\/h4>\n<h5>13. Uvicorn \u7684\u70ed\u91cd\u8f7d\u529f\u80fd\u662f\u5982\u4f55\u5b9e\u73b0\u7684&#xff0c;\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u662f\u5426\u53ef\u4ee5\u4f7f\u7528&#xff1f;<\/h5>\n<p>\u7b54\u6848&#xff1a;Uvicorn \u7684\u70ed\u91cd\u8f7d\u529f\u80fd\u662f\u901a\u8fc7\u76d1\u6d4b\u9879\u76ee\u6587\u4ef6\u7684\u53d8\u5316\u6765\u5b9e\u73b0\u7684\u3002\u5f53 Uvicorn \u542f\u52a8\u65f6&#xff0c;\u5982\u679c\u5f00\u542f\u4e86\u70ed\u91cd\u8f7d&#xff08;\u4f7f\u7528 &#8211;reload \u53c2\u6570&#xff09;&#xff0c;\u5b83\u4f1a\u542f\u52a8\u4e00\u4e2a\u6587\u4ef6\u76d1\u63a7\u5668&#xff0c;\u6301\u7eed\u68c0\u67e5\u9879\u76ee\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u662f\u5426\u6709\u4fee\u6539\u3001\u521b\u5efa\u6216\u5220\u9664\u7b49\u64cd\u4f5c\u3002\u4e00\u65e6\u68c0\u6d4b\u5230\u6587\u4ef6\u53d8\u5316&#xff0c;Uvicorn \u4f1a\u81ea\u52a8\u91cd\u542f\u670d\u52a1\u5668&#xff0c;\u52a0\u8f7d\u6700\u65b0\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u70ed\u91cd\u8f7d\u529f\u80fd\u4e3b\u8981\u7528\u4e8e\u5f00\u53d1\u73af\u5883&#xff0c;\u65b9\u4fbf\u5f00\u53d1\u8005\u5728\u4fee\u6539\u4ee3\u7801\u540e\u65e0\u9700\u624b\u52a8\u91cd\u542f\u670d\u52a1\u5668\u5373\u53ef\u770b\u5230\u4fee\u6539\u540e\u7684\u6548\u679c\u3002\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u4e0d\u5efa\u8bae\u4f7f\u7528\u70ed\u91cd\u8f7d\u529f\u80fd&#xff0c;\u56e0\u4e3a\u6587\u4ef6\u76d1\u63a7\u548c\u91cd\u542f\u670d\u52a1\u5668\u4f1a\u6d88\u8017\u989d\u5916\u7684\u7cfb\u7edf\u8d44\u6e90&#xff0c;\u5e76\u4e14\u53ef\u80fd\u4f1a\u5bfc\u81f4\u670d\u52a1\u4e2d\u65ad&#xff0c;\u5f71\u54cd\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u548c\u6027\u80fd\u3002<\/p>\n<h5>14. \u5982\u4f55\u4f18\u5316 Uvicorn \u5728\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b\u7684\u6027\u80fd&#xff1f;<\/h5>\n<p>\u7b54\u6848&#xff1a;<\/p>\n<ul>\n<li>\u5408\u7406\u914d\u7f6e\u5de5\u4f5c\u8fdb\u7a0b&#xff1a;\u6839\u636e\u670d\u52a1\u5668\u7684 CPU \u6838\u5fc3\u6570\u548c\u5185\u5b58\u8d44\u6e90&#xff0c;\u5408\u7406\u8c03\u6574 &#8211;workers \u53c2\u6570&#xff0c;\u4ee5\u5145\u5206\u5229\u7528\u591a\u6838 CPU \u7684\u6027\u80fd\u3002\u4e00\u822c\u6765\u8bf4&#xff0c;\u5de5\u4f5c\u8fdb\u7a0b\u7684\u6570\u91cf\u53ef\u4ee5\u8bbe\u7f6e\u4e3a CPU \u6838\u5fc3\u6570\u7684 2 \u500d\u5de6\u53f3\u3002<\/li>\n<li>\u4f7f\u7528\u5f02\u6b65\u4e2d\u95f4\u4ef6&#xff1a;\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u5f02\u6b65\u4e2d\u95f4\u4ef6&#xff0c;\u907f\u514d\u4e2d\u95f4\u4ef6\u4e2d\u7684\u963b\u585e\u64cd\u4f5c&#xff0c;\u786e\u4fdd\u8bf7\u6c42\u5904\u7406\u8fc7\u7a0b\u4e2d\u7684\u6bcf\u4e2a\u73af\u8282\u90fd\u662f\u5f02\u6b65\u7684&#xff0c;\u63d0\u9ad8\u5e76\u53d1\u5904\u7406\u80fd\u529b\u3002<\/li>\n<li>\u4f18\u5316\u7f51\u7edc\u914d\u7f6e&#xff1a;\u8c03\u6574\u670d\u52a1\u5668\u7684\u7f51\u7edc\u53c2\u6570&#xff0c;\u5982 TCP \u7f13\u51b2\u533a\u5927\u5c0f\u3001\u6700\u5927\u8fde\u63a5\u6570\u7b49&#xff0c;\u4ee5\u63d0\u9ad8\u7f51\u7edc\u4f20\u8f93\u6027\u80fd\u3002<\/li>\n<li>\u4f7f\u7528\u7f13\u5b58&#xff1a;\u5bf9\u4e8e\u4e00\u4e9b\u9891\u7e41\u8bbf\u95ee\u7684\u6570\u636e\u6216\u8ba1\u7b97\u7ed3\u679c&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u7f13\u5b58\u673a\u5236&#xff08;\u5982 Redis&#xff09;\u6765\u51cf\u5c11\u91cd\u590d\u8ba1\u7b97\u548c\u6570\u636e\u5e93\u67e5\u8be2&#xff0c;\u63d0\u9ad8\u54cd\u5e94\u901f\u5ea6\u3002<\/li>\n<\/ul>\n<h4>\u5b89\u5168\u4e0e\u76d1\u63a7\u7c7b<\/h4>\n<h5>15. Uvicorn \u672c\u8eab\u6709\u54ea\u4e9b\u5b89\u5168\u65b9\u9762\u7684\u8003\u8651&#xff0c;\u5f00\u53d1\u8005\u8fd8\u9700\u8981\u505a\u4ec0\u4e48\u989d\u5916\u7684\u5b89\u5168\u63aa\u65bd&#xff1f;<\/h5>\n<p>\u7b54\u6848&#xff1a;<\/p>\n<ul>\n<li>Uvicorn \u81ea\u8eab\u5b89\u5168\u8003\u8651&#xff1a;Uvicorn \u672c\u8eab\u5728\u8bbe\u8ba1\u4e0a\u9075\u5faa\u4e86\u4e00\u4e9b\u57fa\u672c\u7684\u5b89\u5168\u539f\u5219\u3002\u4f8b\u5982&#xff0c;\u5b83\u53ef\u4ee5\u4e0e\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668&#xff08;\u5982 Nginx \u6216 Apache&#xff09;\u914d\u5408\u4f7f\u7528&#xff0c;\u5229\u7528\u53cd\u5411\u4ee3\u7406\u7684\u5b89\u5168\u529f\u80fd&#xff0c;\u50cf\u8fc7\u6ee4\u6076\u610f\u8bf7\u6c42\u3001\u8fdb\u884c IP \u5c01\u7981\u7b49\u3002\u540c\u65f6&#xff0c;\u5b83\u652f\u6301 HTTPS \u8fde\u63a5&#xff0c;\u53ef\u901a\u8fc7\u914d\u7f6e SSL \u8bc1\u4e66\u6765\u52a0\u5bc6\u6570\u636e\u4f20\u8f93&#xff0c;\u9632\u6b62\u6570\u636e\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u88ab\u7a83\u53d6\u6216\u7be1\u6539\u3002<\/li>\n<li>\u5f00\u53d1\u8005\u989d\u5916\u5b89\u5168\u63aa\u65bd&#xff1a;\u5f00\u53d1\u8005\u9700\u8981\u5728\u5e94\u7528\u5c42\u9762\u8fdb\u884c\u66f4\u591a\u7684\u5b89\u5168\u5904\u7406\u3002\u6bd4\u5982&#xff0c;\u5bf9\u7528\u6237\u8f93\u5165\u8fdb\u884c\u4e25\u683c\u7684\u9a8c\u8bc1\u548c\u8fc7\u6ee4&#xff0c;\u9632\u6b62 SQL \u6ce8\u5165\u3001XSS&#xff08;\u8de8\u7ad9\u811a\u672c\u653b\u51fb&#xff09;\u7b49\u5e38\u89c1\u7684 Web \u5b89\u5168\u6f0f\u6d1e\u3002\u8fd8\u8981\u59a5\u5584\u7ba1\u7406 API \u5bc6\u94a5\u548c\u654f\u611f\u4fe1\u606f&#xff0c;\u907f\u514d\u6cc4\u9732\u3002\u53e6\u5916&#xff0c;\u5b9a\u671f\u66f4\u65b0\u5e94\u7528\u53ca\u5176\u4f9d\u8d56\u7684\u5e93&#xff0c;\u4ee5\u4fee\u590d\u5df2\u77e5\u7684\u5b89\u5168\u6f0f\u6d1e\u3002<\/li>\n<\/ul>\n<h5>16. \u5982\u4f55\u76d1\u63a7 Uvicorn \u670d\u52a1\u5668\u7684\u6027\u80fd\u548c\u8fd0\u884c\u72b6\u6001&#xff1f;<\/h5>\n<p>\u7b54\u6848&#xff1a;<\/p>\n<ul>\n<li>\u65e5\u5fd7\u76d1\u63a7&#xff1a;Uvicorn \u4f1a\u8f93\u51fa\u8be6\u7ec6\u7684\u65e5\u5fd7\u4fe1\u606f&#xff0c;\u901a\u8fc7\u67e5\u770b\u65e5\u5fd7\u53ef\u4ee5\u4e86\u89e3\u670d\u52a1\u5668\u7684\u8fd0\u884c\u72b6\u6001&#xff0c;\u5982\u8bf7\u6c42\u5904\u7406\u65f6\u95f4\u3001\u9519\u8bef\u4fe1\u606f\u7b49\u3002\u53ef\u4ee5\u4f7f\u7528\u65e5\u5fd7\u5206\u6790\u5de5\u5177&#xff08;\u5982 ELK Stack \u6216 Graylog&#xff09;\u6765\u6536\u96c6\u3001\u5b58\u50a8\u548c\u5206\u6790\u8fd9\u4e9b\u65e5\u5fd7&#xff0c;\u4ee5\u4fbf\u53ca\u65f6\u53d1\u73b0\u6f5c\u5728\u7684\u95ee\u9898\u3002<\/li>\n<li>\u6027\u80fd\u6307\u6807\u76d1\u63a7&#xff1a;\u4f7f\u7528\u6027\u80fd\u76d1\u63a7\u5de5\u5177&#xff08;\u5982 Prometheus \u548c Grafana&#xff09;\u6765\u6536\u96c6\u548c\u53ef\u89c6\u5316 Uvicorn \u670d\u52a1\u5668\u7684\u6027\u80fd\u6307\u6807&#xff0c;\u5982 CPU \u4f7f\u7528\u7387\u3001\u5185\u5b58\u4f7f\u7528\u7387\u3001\u8bf7\u6c42\u5904\u7406\u901f\u7387\u3001\u54cd\u5e94\u65f6\u95f4\u7b49\u3002\u53ef\u4ee5\u901a\u8fc7 Prometheus \u76d1\u63a7 Uvicorn \u66b4\u9732\u7684\u6307\u6807\u7aef\u70b9&#xff0c;\u7136\u540e\u4f7f\u7528 Grafana \u6765\u521b\u5efa\u4eea\u8868\u76d8&#xff0c;\u76f4\u89c2\u5c55\u793a\u8fd9\u4e9b\u6307\u6807\u7684\u53d8\u5316\u60c5\u51b5\u3002<\/li>\n<li>\u8fdb\u7a0b\u76d1\u63a7&#xff1a;\u4f7f\u7528\u8fdb\u7a0b\u76d1\u63a7\u5de5\u5177&#xff08;\u5982 systemd \u6216 supervisor&#xff09;\u6765\u76d1\u63a7 Uvicorn \u8fdb\u7a0b\u7684\u8fd0\u884c\u72b6\u6001&#xff0c;\u786e\u4fdd\u8fdb\u7a0b\u5728\u51fa\u73b0\u5f02\u5e38\u65f6\u80fd\u591f\u81ea\u52a8\u91cd\u542f\u3002<\/li>\n<\/ul>\n<h4>\u6269\u5c55\u4e0e\u751f\u6001\u7c7b<\/h4>\n<h5>17. Uvicorn \u6709\u54ea\u4e9b\u63d2\u4ef6\u6216\u6269\u5c55\u53ef\u4ee5\u589e\u5f3a\u5176\u529f\u80fd&#xff1f;<\/h5>\n<p>\u7b54\u6848&#xff1a;<\/p>\n<ul>\n<li>\u65e5\u5fd7\u63d2\u4ef6&#xff1a;\u53ef\u4ee5\u4f7f\u7528 uvicorn[log] \u6765\u6269\u5c55\u65e5\u5fd7\u529f\u80fd&#xff0c;\u4f8b\u5982\u5b9e\u73b0\u66f4\u8be6\u7ec6\u7684\u65e5\u5fd7\u8bb0\u5f55\u3001\u65e5\u5fd7\u5206\u7ea7\u548c\u65e5\u5fd7\u5b58\u50a8\u7b49\u3002<\/li>\n<li>\u4e2d\u95f4\u4ef6\u6269\u5c55&#xff1a;\u5f00\u53d1\u8005\u53ef\u4ee5\u7f16\u5199\u81ea\u5b9a\u4e49\u7684 ASGI \u4e2d\u95f4\u4ef6\u6765\u589e\u5f3a Uvicorn \u7684\u529f\u80fd&#xff0c;\u5982\u6dfb\u52a0\u8bf7\u6c42\u9650\u6d41\u3001\u8eab\u4efd\u9a8c\u8bc1\u3001\u8bf7\u6c42\/\u54cd\u5e94\u8f6c\u6362\u7b49\u529f\u80fd\u3002\u4f8b\u5982&#xff0c;\u4f7f\u7528 slowapi \u5e93\u53ef\u4ee5\u5b9e\u73b0\u8bf7\u6c42\u9650\u6d41\u7684\u4e2d\u95f4\u4ef6\u3002<\/li>\n<li>\u76d1\u63a7\u6269\u5c55&#xff1a;\u901a\u8fc7\u96c6\u6210 prometheus-fastapi-instrumentator \u7b49\u5de5\u5177&#xff0c;\u53ef\u4ee5\u4e3a Uvicorn \u5e94\u7528\u6dfb\u52a0 Prometheus \u76d1\u63a7\u6307\u6807&#xff0c;\u65b9\u4fbf\u5bf9\u5e94\u7528\u7684\u6027\u80fd\u8fdb\u884c\u76d1\u63a7\u548c\u5206\u6790\u3002<\/li>\n<\/ul>\n<h5>18. Uvicorn \u4e0e Docker \u7ed3\u5408\u4f7f\u7528\u65f6&#xff0c;\u6709\u54ea\u4e9b\u6ce8\u610f\u4e8b\u9879&#xff1f;<\/h5>\n<p>\u7b54\u6848&#xff1a;<\/p>\n<ul>\n<li>\u7aef\u53e3\u6620\u5c04&#xff1a;\u5728 Docker \u5bb9\u5668\u4e2d\u8fd0\u884c Uvicorn \u65f6&#xff0c;\u9700\u8981\u786e\u4fdd\u6b63\u786e\u6620\u5c04\u5bb9\u5668\u5185 Uvicorn \u76d1\u542c\u7684\u7aef\u53e3\u5230\u5bbf\u4e3b\u673a\u7684\u7aef\u53e3&#xff0c;\u4ee5\u4fbf\u5916\u90e8\u53ef\u4ee5\u8bbf\u95ee\u5e94\u7528\u3002\u4f8b\u5982&#xff0c;\u5728 Dockerfile \u6216 docker run \u547d\u4ee4\u4e2d\u4f7f\u7528 -p \u53c2\u6570\u8fdb\u884c\u7aef\u53e3\u6620\u5c04\u3002<\/li>\n<li>\u73af\u5883\u53d8\u91cf\u914d\u7f6e&#xff1a;\u53ef\u4ee5\u4f7f\u7528 Docker \u7684\u73af\u5883\u53d8\u91cf\u529f\u80fd\u6765\u914d\u7f6e Uvicorn \u7684\u53c2\u6570&#xff0c;\u5982 &#8211;host\u3001&#8211;port\u3001&#8211;workers \u7b49\u3002\u8fd9\u6837\u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u73af\u5883\u4e2d\u7075\u6d3b\u8c03\u6574 Uvicorn \u7684\u914d\u7f6e&#xff0c;\u800c\u65e0\u9700\u4fee\u6539\u5e94\u7528\u4ee3\u7801\u3002<\/li>\n<li>\u8d44\u6e90\u9650\u5236&#xff1a;\u5728 Docker \u4e2d\u8fd0\u884c Uvicorn \u65f6&#xff0c;\u8981\u6839\u636e\u5bbf\u4e3b\u673a\u7684\u8d44\u6e90\u60c5\u51b5\u5408\u7406\u9650\u5236\u5bb9\u5668\u7684 CPU \u548c\u5185\u5b58\u4f7f\u7528&#xff0c;\u907f\u514d\u5bb9\u5668\u8fc7\u5ea6\u5360\u7528\u8d44\u6e90\u5f71\u54cd\u5176\u4ed6\u670d\u52a1\u7684\u8fd0\u884c\u3002\u53ef\u4ee5\u4f7f\u7528 &#8211;cpus \u548c &#8211;memory \u53c2\u6570\u6765\u8fdb\u884c\u8d44\u6e90\u9650\u5236\u3002<\/li>\n<li>\u955c\u50cf\u6784\u5efa\u4f18\u5316&#xff1a;\u5728\u6784\u5efa Docker \u955c\u50cf\u65f6&#xff0c;\u8981\u6ce8\u610f\u4f18\u5316\u955c\u50cf\u7684\u5927\u5c0f&#xff0c;\u53ea\u5305\u542b\u8fd0\u884c Uvicorn \u5e94\u7528\u6240\u9700\u7684\u4f9d\u8d56\u9879&#xff0c;\u51cf\u5c11\u955c\u50cf\u7684\u4e0b\u8f7d\u548c\u542f\u52a8\u65f6\u95f4\u3002<\/li>\n<\/ul>\n<h4>\u6545\u969c\u6392\u67e5\u4e0e\u8c03\u4f18\u7c7b<\/h4>\n<h5>19. \u5982\u679c Uvicorn \u670d\u52a1\u5668\u54cd\u5e94\u7f13\u6162&#xff0c;\u53ef\u80fd\u7684\u539f\u56e0\u6709\u54ea\u4e9b&#xff0c;\u5982\u4f55\u6392\u67e5\u548c\u89e3\u51b3&#xff1f;<\/h5>\n<p>\u7b54\u6848&#xff1a;<\/p>\n<ul>\n<li>\u53ef\u80fd\u539f\u56e0&#xff1a;\n<ul>\n<li>\u5e94\u7528\u4ee3\u7801\u95ee\u9898&#xff1a;\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5b58\u5728\u963b\u585e\u64cd\u4f5c&#xff0c;\u5982\u957f\u65f6\u95f4\u7684\u6570\u636e\u5e93\u67e5\u8be2\u3001\u6587\u4ef6\u8bfb\u5199\u7b49&#xff0c;\u4f1a\u5bfc\u81f4\u8bf7\u6c42\u5904\u7406\u7f13\u6162\u3002<\/li>\n<li>\u8d44\u6e90\u74f6\u9888&#xff1a;\u670d\u52a1\u5668\u7684 CPU\u3001\u5185\u5b58\u6216\u7f51\u7edc\u5e26\u5bbd\u4e0d\u8db3&#xff0c;\u65e0\u6cd5\u6ee1\u8db3\u9ad8\u5e76\u53d1\u8bf7\u6c42\u7684\u5904\u7406\u9700\u6c42\u3002<\/li>\n<li>\u914d\u7f6e\u4e0d\u5408\u7406&#xff1a;Uvicorn \u7684\u914d\u7f6e\u53c2\u6570&#xff08;\u5982 &#8211;workers \u6570\u91cf&#xff09;\u8bbe\u7f6e\u4e0d\u5408\u7406&#xff0c;\u53ef\u80fd\u5bfc\u81f4\u6027\u80fd\u4e0d\u4f73\u3002<\/li>\n<li>\u5916\u90e8\u670d\u52a1\u95ee\u9898&#xff1a;\u5e94\u7528\u4f9d\u8d56\u7684\u5916\u90e8\u670d\u52a1&#xff08;\u5982\u6570\u636e\u5e93\u3001\u7f13\u5b58\u670d\u52a1\u5668\u7b49&#xff09;\u54cd\u5e94\u7f13\u6162&#xff0c;\u5f71\u54cd\u4e86\u6574\u4f53\u7684\u54cd\u5e94\u65f6\u95f4\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u6392\u67e5\u65b9\u6cd5&#xff1a;\n<ul>\n<li>\u65e5\u5fd7\u5206\u6790&#xff1a;\u67e5\u770b Uvicorn \u548c\u5e94\u7528\u7a0b\u5e8f\u7684\u65e5\u5fd7&#xff0c;\u627e\u51fa\u54cd\u5e94\u7f13\u6162\u7684\u8bf7\u6c42\u548c\u76f8\u5173\u7684\u9519\u8bef\u4fe1\u606f\u3002<\/li>\n<li>\u6027\u80fd\u76d1\u63a7&#xff1a;\u4f7f\u7528\u6027\u80fd\u76d1\u63a7\u5de5\u5177&#xff08;\u5982 top\u3001htop\u3001netstat \u7b49&#xff09;\u68c0\u67e5\u670d\u52a1\u5668\u7684\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5&#xff0c;\u786e\u5b9a\u662f\u5426\u5b58\u5728\u8d44\u6e90\u74f6\u9888\u3002<\/li>\n<li>\u4ee3\u7801\u5ba1\u67e5&#xff1a;\u68c0\u67e5\u5e94\u7528\u4ee3\u7801&#xff0c;\u627e\u51fa\u53ef\u80fd\u5b58\u5728\u7684\u963b\u585e\u64cd\u4f5c\u548c\u6027\u80fd\u74f6\u9888\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u89e3\u51b3\u65b9\u6cd5&#xff1a;\n<ul>\n<li>\u4f18\u5316\u4ee3\u7801&#xff1a;\u5c06\u963b\u585e\u64cd\u4f5c\u6539\u4e3a\u5f02\u6b65\u64cd\u4f5c&#xff0c;\u4f7f\u7528\u5f02\u6b65\u6570\u636e\u5e93\u9a71\u52a8\u548c\u5f02\u6b65\u6587\u4ef6\u64cd\u4f5c\u5e93\u7b49\u3002<\/li>\n<li>\u589e\u52a0\u8d44\u6e90&#xff1a;\u6839\u636e\u76d1\u63a7\u7ed3\u679c&#xff0c;\u589e\u52a0\u670d\u52a1\u5668\u7684 CPU\u3001\u5185\u5b58\u6216\u7f51\u7edc\u5e26\u5bbd\u7b49\u8d44\u6e90\u3002<\/li>\n<li>\u8c03\u6574\u914d\u7f6e&#xff1a;\u5408\u7406\u8c03\u6574 Uvicorn \u7684\u914d\u7f6e\u53c2\u6570&#xff0c;\u5982\u589e\u52a0 &#8211;workers \u6570\u91cf\u3002<\/li>\n<li>\u4f18\u5316\u5916\u90e8\u670d\u52a1&#xff1a;\u68c0\u67e5\u5e76\u4f18\u5316\u5e94\u7528\u4f9d\u8d56\u7684\u5916\u90e8\u670d\u52a1\u7684\u6027\u80fd&#xff0c;\u5982\u8c03\u6574\u6570\u636e\u5e93\u67e5\u8be2\u8bed\u53e5\u3001\u4f18\u5316\u7f13\u5b58\u7b56\u7565\u7b49\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5>20. \u5982\u4f55\u5bf9 Uvicorn \u7684\u914d\u7f6e\u8fdb\u884c\u8c03\u4f18\u4ee5\u9002\u5e94\u4e0d\u540c\u7684\u4e1a\u52a1\u573a\u666f&#xff1f;<\/h5>\n<p>\u7b54\u6848&#xff1a;<\/p>\n<ul>\n<li>I\/O \u5bc6\u96c6\u578b\u573a\u666f&#xff1a;\u5bf9\u4e8e I\/O \u5bc6\u96c6\u578b\u4e1a\u52a1&#xff0c;\u5982 Web \u5e94\u7528\u3001\u5b9e\u65f6\u6570\u636e\u5904\u7406\u7b49&#xff0c;\u5e94\u5145\u5206\u5229\u7528 Uvicorn \u7684\u5f02\u6b65\u7279\u6027\u3002\u53ef\u4ee5\u9002\u5f53\u589e\u52a0 &#8211;workers \u6570\u91cf&#xff0c;\u4e00\u822c\u8bbe\u7f6e\u4e3a CPU \u6838\u5fc3\u6570\u7684 2 &#8211; 4 \u500d&#xff0c;\u4ee5\u63d0\u9ad8\u5e76\u53d1\u5904\u7406\u80fd\u529b\u3002\u540c\u65f6&#xff0c;\u786e\u4fdd\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684 I\/O \u64cd\u4f5c\u90fd\u662f\u5f02\u6b65\u7684&#xff0c;\u907f\u514d\u963b\u585e\u7ebf\u7a0b\u3002<\/li>\n<li>CPU \u5bc6\u96c6\u578b\u573a\u666f&#xff1a;\u5728 CPU \u5bc6\u96c6\u578b\u4e1a\u52a1\u4e2d&#xff0c;\u5982\u5927\u6570\u636e\u5206\u6790\u3001\u673a\u5668\u5b66\u4e60\u6a21\u578b\u63a8\u7406\u7b49&#xff0c;\u8fc7\u591a\u7684\u5de5\u4f5c\u8fdb\u7a0b\u53ef\u80fd\u4f1a\u5bfc\u81f4 CPU \u8d44\u6e90\u7ade\u4e89\u52a0\u5267\u3002\u6b64\u65f6&#xff0c;\u5e94\u51cf\u5c11 &#8211;workers \u6570\u91cf&#xff0c;\u901a\u5e38\u8bbe\u7f6e\u4e3a CPU \u6838\u5fc3\u6570\u6216\u7565\u5c0f\u4e8e\u6838\u5fc3\u6570&#xff0c;\u4ee5\u907f\u514d\u8fc7\u591a\u7684\u4e0a\u4e0b\u6587\u5207\u6362\u3002<\/li>\n<li>\u9ad8\u5e76\u53d1\u5c0f\u6d41\u91cf\u573a\u666f&#xff1a;\u5bf9\u4e8e\u9ad8\u5e76\u53d1\u4f46\u6bcf\u4e2a\u8bf7\u6c42\u5904\u7406\u65f6\u95f4\u8f83\u77ed\u7684\u573a\u666f&#xff0c;\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574 &#8211;backlog \u53c2\u6570\u6765\u589e\u52a0\u670d\u52a1\u5668\u7684\u8bf7\u6c42\u961f\u5217\u957f\u5ea6&#xff0c;\u4ee5\u5e94\u5bf9\u5927\u91cf\u7684\u5e76\u53d1\u8bf7\u6c42\u3002\u540c\u65f6&#xff0c;\u4f18\u5316\u5e94\u7528\u4ee3\u7801\u548c\u4e2d\u95f4\u4ef6&#xff0c;\u51cf\u5c11\u8bf7\u6c42\u5904\u7406\u65f6\u95f4\u3002<\/li>\n<li>\u4f4e\u5e76\u53d1\u5927\u6d41\u91cf\u573a\u666f&#xff1a;\u5728\u4f4e\u5e76\u53d1\u4f46\u6bcf\u4e2a\u8bf7\u6c42\u5904\u7406\u65f6\u95f4\u8f83\u957f\u7684\u573a\u666f\u4e2d&#xff0c;\u8981\u786e\u4fdd\u5e94\u7528\u7a0b\u5e8f\u6709\u8db3\u591f\u7684\u8d44\u6e90\u6765\u5904\u7406\u5355\u4e2a\u8bf7\u6c42\u3002\u53ef\u4ee5\u9002\u5f53\u589e\u52a0\u670d\u52a1\u5668\u7684\u5185\u5b58\u548c CPU \u8d44\u6e90&#xff0c;\u540c\u65f6\u4f18\u5316\u6570\u636e\u5e93\u67e5\u8be2\u548c\u6587\u4ef6\u8bfb\u5199\u64cd\u4f5c&#xff0c;\u63d0\u9ad8\u5904\u7406\u6548\u7387\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb759\u6b21\uff0c\u70b9\u8d5e10\u6b21\uff0c\u6536\u85cf11\u6b21\u3002Uvicorn \u662f\u4e00\u4e2a\u57fa\u4e8e Python \u7684\u5feb\u901f ASGI\uff08\u5f02\u6b65\u670d\u52a1\u5668\u7f51\u5173\u63a5\u53e3\uff09\u670d\u52a1\u5668\u3002\u5b83\u7684\u4e3b\u8981\u4f5c\u7528\u662f\u4f5c\u4e3a Web \u5e94\u7528\u7a0b\u5e8f\u7684\u670d\u52a1\u5668\uff0c\u8d1f\u8d23\u63a5\u6536\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\uff0c\u5e76\u5c06\u8bf7\u6c42\u4f20\u9012\u7ed9\u5e94\u7528\u7a0b\u5e8f\u5904\u7406\uff0c\u7136\u540e\u5c06\u5e94\u7528\u7a0b\u5e8f\u7684\u54cd\u5e94\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002\u7531\u4e8e\u91c7\u7528\u5f02\u6b65\u7f16\u7a0b\u6a21\u578b\uff0c\u5b83\u80fd\u9ad8\u6548\u5904\u7406\u5927\u91cf\u5e76\u53d1\u8bf7\u6c42\uff0c\u63d0\u5347\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u54cd\u5e94\u901f\u5ea6\u3002_vscode\u4f7f\u7528\u8fc7uvicorn\u542f\u52a8\u670d\u52a1\u6ce8\u610f\u4e8b\u9879<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[92,132,43,44],"topic":[],"class_list":["post-18399","post","type-post","status-publish","format-standard","hentry","category-server","tag-github","tag-132","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5927\u6a21\u578b\u5feb\u901f ASGI \u670d\u52a1\u5668uvicorn - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/18399.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5927\u6a21\u578b\u5feb\u901f ASGI \u670d\u52a1\u5668uvicorn - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb759\u6b21\uff0c\u70b9\u8d5e10\u6b21\uff0c\u6536\u85cf11\u6b21\u3002Uvicorn \u662f\u4e00\u4e2a\u57fa\u4e8e Python \u7684\u5feb\u901f ASGI\uff08\u5f02\u6b65\u670d\u52a1\u5668\u7f51\u5173\u63a5\u53e3\uff09\u670d\u52a1\u5668\u3002\u5b83\u7684\u4e3b\u8981\u4f5c\u7528\u662f\u4f5c\u4e3a Web \u5e94\u7528\u7a0b\u5e8f\u7684\u670d\u52a1\u5668\uff0c\u8d1f\u8d23\u63a5\u6536\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\uff0c\u5e76\u5c06\u8bf7\u6c42\u4f20\u9012\u7ed9\u5e94\u7528\u7a0b\u5e8f\u5904\u7406\uff0c\u7136\u540e\u5c06\u5e94\u7528\u7a0b\u5e8f\u7684\u54cd\u5e94\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002\u7531\u4e8e\u91c7\u7528\u5f02\u6b65\u7f16\u7a0b\u6a21\u578b\uff0c\u5b83\u80fd\u9ad8\u6548\u5904\u7406\u5927\u91cf\u5e76\u53d1\u8bf7\u6c42\uff0c\u63d0\u5347\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u54cd\u5e94\u901f\u5ea6\u3002_vscode\u4f7f\u7528\u8fc7uvicorn\u542f\u52a8\u670d\u52a1\u6ce8\u610f\u4e8b\u9879\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/18399.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T16:48:07+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/18399.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/18399.html\",\"name\":\"\u5927\u6a21\u578b\u5feb\u901f ASGI \u670d\u52a1\u5668uvicorn - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T16:48:07+00:00\",\"dateModified\":\"2025-04-18T16:48:07+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/18399.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/18399.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/18399.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5927\u6a21\u578b\u5feb\u901f ASGI \u670d\u52a1\u5668uvicorn\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5927\u6a21\u578b\u5feb\u901f ASGI \u670d\u52a1\u5668uvicorn - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/18399.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5927\u6a21\u578b\u5feb\u901f ASGI \u670d\u52a1\u5668uvicorn - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb759\u6b21\uff0c\u70b9\u8d5e10\u6b21\uff0c\u6536\u85cf11\u6b21\u3002Uvicorn \u662f\u4e00\u4e2a\u57fa\u4e8e Python \u7684\u5feb\u901f ASGI\uff08\u5f02\u6b65\u670d\u52a1\u5668\u7f51\u5173\u63a5\u53e3\uff09\u670d\u52a1\u5668\u3002\u5b83\u7684\u4e3b\u8981\u4f5c\u7528\u662f\u4f5c\u4e3a Web \u5e94\u7528\u7a0b\u5e8f\u7684\u670d\u52a1\u5668\uff0c\u8d1f\u8d23\u63a5\u6536\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\uff0c\u5e76\u5c06\u8bf7\u6c42\u4f20\u9012\u7ed9\u5e94\u7528\u7a0b\u5e8f\u5904\u7406\uff0c\u7136\u540e\u5c06\u5e94\u7528\u7a0b\u5e8f\u7684\u54cd\u5e94\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002\u7531\u4e8e\u91c7\u7528\u5f02\u6b65\u7f16\u7a0b\u6a21\u578b\uff0c\u5b83\u80fd\u9ad8\u6548\u5904\u7406\u5927\u91cf\u5e76\u53d1\u8bf7\u6c42\uff0c\u63d0\u5347\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u54cd\u5e94\u901f\u5ea6\u3002_vscode\u4f7f\u7528\u8fc7uvicorn\u542f\u52a8\u670d\u52a1\u6ce8\u610f\u4e8b\u9879","og_url":"https:\/\/www.wsisp.com\/helps\/18399.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T16:48:07+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/18399.html","url":"https:\/\/www.wsisp.com\/helps\/18399.html","name":"\u5927\u6a21\u578b\u5feb\u901f ASGI \u670d\u52a1\u5668uvicorn - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T16:48:07+00:00","dateModified":"2025-04-18T16:48:07+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/18399.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/18399.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/18399.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5927\u6a21\u578b\u5feb\u901f ASGI \u670d\u52a1\u5668uvicorn"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/18399","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=18399"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/18399\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=18399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=18399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=18399"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=18399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}