{"id":621,"date":"2026-07-25T06:54:34","date_gmt":"2026-07-24T21:54:34","guid":{"rendered":"https:\/\/www.marchboy.xyz\/wordpress\/archives\/621"},"modified":"2026-07-25T06:54:34","modified_gmt":"2026-07-24T21:54:34","slug":"uvicorn%e3%81%a8%e3%81%af%ef%bc%9f%e9%ab%98%e9%80%9fasgi%e3%82%b5%e3%83%bc%e3%83%90%e3%81%ae%e7%89%b9%e5%be%b4%e3%81%a8%e6%b4%bb%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.marchboy.xyz\/wordpress\/archives\/621","title":{"rendered":"Uvicorn\u3068\u306f\uff1f\u9ad8\u901fASGI\u30b5\u30fc\u30d0\u306e\u7279\u5fb4\u3068\u6d3b\u7528\u6cd5"},"content":{"rendered":"<h2>Uvicorn\u3068\u306f<\/h2>\n<p><strong>Uvicorn<\/strong>\u306f\u3001Python\u3067\u66f8\u304b\u308c\u305f <strong>ASGI\uff08Asynchronous Server Gateway Interface\uff09<\/strong> \u30b5\u30fc\u30d0\u3067\u3059\u3002\u8efd\u91cf\u3067\u9ad8\u901f\u306a\u975e\u540c\u671fIO\u3092\u6d3b\u7528\u3057\u3001FastAPI\u3001Starlette\u3001Django\uff08ASGI\u30e2\u30fc\u30c9\uff09\u306a\u3069\u306e\u30e2\u30c0\u30f3\u306aWeb\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002<\/p>\n<h2>\u4e3b\u306a\u7279\u5fb4<\/h2>\n<ul>\n<li>\u30b7\u30f3\u30b0\u30eb\u30b9\u30ec\u30c3\u30c9\u30fb\u30b7\u30f3\u30b0\u30eb\u30d7\u30ed\u30bb\u30b9\u3067\u52d5\u4f5c\u3057\u3001<strong>async\/await<\/strong> \u306b\u6700\u9069\u5316\u3055\u308c\u305f\u8a2d\u8a08\u3002<\/li>\n<li>uvloop \u3068 httptools \u3092\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u5229\u7528\u3057\u3001\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u51e6\u7406\u3092\u9ad8\u901f\u5316\u3002<\/li>\n<li>\u6a19\u6e96\u7684\u306a <code>--host<\/code>\u3001<code>--port<\/code>\u3001<code>--workers<\/code> \u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u67d4\u8edf\u306b\u8a2d\u5b9a\u53ef\u80fd\u3002<\/li>\n<li>\u30db\u30c3\u30c8\u30ea\u30ed\u30fc\u30c9\uff08<code>--reload<\/code>\uff09\u6a5f\u80fd\u306b\u3088\u308a\u3001\u958b\u767a\u4e2d\u306e\u30b3\u30fc\u30c9\u5909\u66f4\u304c\u5373\u5ea7\u306b\u53cd\u6620\u3002<\/li>\n<li>Docker \u30b3\u30f3\u30c6\u30ca\u3084 Kubernetes \u3068\u306e\u76f8\u6027\u304c\u826f\u304f\u3001\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u306e\u30c7\u30d7\u30ed\u30a4\u306b\u9069\u3057\u3066\u3044\u308b\u3002<\/li>\n<\/ul>\n<h2>\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/h2>\n<h3>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<p>pip \u3067\u7c21\u5358\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><code>pip install uvicorn<\/code><\/pre>\n<h3>\u30b7\u30f3\u30d7\u30eb\u306a\u30a2\u30d7\u30ea\u306e\u8d77\u52d5<\/h3>\n<p>\u4ee5\u4e0b\u306f <code>app.py<\/code> \u306b\u5b9a\u7fa9\u3057\u305f\u6700\u5c0f\u9650\u306e ASGI \u30a2\u30d7\u30ea\u3067\u3059\u3002<\/p>\n<pre><code># app.py\nimport asyncio\nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get(\"\/hello\")\nasync def hello():\n    await asyncio.sleep(0.1)\n    return {\"message\": \"Hello, Uvicorn!\"}\n<\/code><\/pre>\n<p>\u8d77\u52d5\u30b3\u30de\u30f3\u30c9\u306f\u6b21\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<pre><code>uvicorn app:app --host 0.0.0.0 --port 8000<\/code><\/pre>\n<h3>\u958b\u767a\u30e2\u30fc\u30c9\u3067\u306e\u81ea\u52d5\u30ea\u30ed\u30fc\u30c9<\/h3>\n<p>\u30b3\u30fc\u30c9\u3092\u5909\u66f4\u3057\u305f\u969b\u306b\u30b5\u30fc\u30d0\u3092\u518d\u8d77\u52d5\u3057\u305f\u304f\u306a\u3044\u5834\u5408\u306f <code>--reload<\/code> \u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u4ed8\u4e0e\u3057\u307e\u3059\u3002<\/p>\n<pre><code>uvicorn app:app --reload<\/code><\/pre>\n<h2>\u672c\u756a\u74b0\u5883\u3067\u306e\u30c7\u30d7\u30ed\u30a4<\/h2>\n<h3>\u30de\u30eb\u30c1\u30ef\u30fc\u30ab\u30fc\u69cb\u6210<\/h3>\n<p>CPU \u30b3\u30a2\u6570\u306b\u5408\u308f\u305b\u3066\u8907\u6570\u30ef\u30fc\u30ab\u30fc\u3092\u7acb\u3061\u4e0a\u3052\u308b\u3053\u3068\u3067\u3001\u30ea\u30af\u30a8\u30b9\u30c8\u51e6\u7406\u80fd\u529b\u3092\u5411\u4e0a\u3055\u305b\u307e\u3059\u3002<\/p>\n<pre><code>uvicorn app:app --workers 4 --host 0.0.0.0 --port 80<\/code><\/pre>\n<h3>Gunicorn + UvicornWorker \u306e\u7d44\u307f\u5408\u308f\u305b<\/h3>\n<p>Gunicorn \u306e\u30d7\u30ed\u30bb\u30b9\u30de\u30cd\u30b8\u30e1\u30f3\u30c8\u6a5f\u80fd\u3068 Uvicorn \u306e\u975e\u540c\u671f\u6027\u80fd\u3092\u4f75\u7528\u3059\u308b\u3053\u3068\u3082\u4e00\u822c\u7684\u3067\u3059\u3002<\/p>\n<pre><code>pip install gunicorn\n\n# \u8d77\u52d5\u4f8b\ngunicorn app:app -k uvicorn.workers.UvicornWorker -w 4 -b 0.0.0.0:80<\/code><\/pre>\n<h2>\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0\u306e\u30dd\u30a4\u30f3\u30c8<\/h2>\n<ul>\n<li>\u30dd\u30fc\u30c8\u304c\u65e2\u306b\u4f7f\u7528\u4e2d\u306e\u5834\u5408\u306f <code>--port<\/code> \u3092\u5909\u66f4\u3002<\/li>\n<li>uvloop \u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u306a\u3044\u3068\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u4f4e\u4e0b\u3059\u308b\u3053\u3068\u304c\u3042\u308b\u306e\u3067\u3001<code>pip install uvloop<\/code> \u3092\u691c\u8a0e\u3002<\/li>\n<li>HTTPS \u304c\u5fc5\u8981\u306a\u5834\u5408\u306f\u3001\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\uff08Nginx\/Traefik\uff09\u3067 TLS \u7d42\u7aef\u3092\u884c\u3046\u306e\u304c\u63a8\u5968\u3002<\/li>\n<\/ul>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>Uvicorn \u306f\u3001\u30b7\u30f3\u30d7\u30eb\u3055\u3068\u9ad8\u901f\u6027\u3092\u517c\u306d\u5099\u3048\u305f ASGI \u30b5\u30fc\u30d0\u3068\u3057\u3066\u3001\u30e2\u30c0\u30f3\u306a Python Web \u958b\u767a\u306e\u4e2d\u5fc3\u7684\u306a\u4f4d\u7f6e\u4ed8\u3051\u306b\u3042\u308a\u307e\u3059\u3002\u958b\u767a\u74b0\u5883\u3067\u306f <code>--reload<\/code> \u3092\u6d3b\u7528\u3057\u3001\u672c\u756a\u74b0\u5883\u3067\u306f\u30de\u30eb\u30c1\u30ef\u30fc\u30ab\u30fc\u3084 Gunicorn \u3068\u306e\u9023\u643a\u3067\u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3\u3092\u78ba\u4fdd\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Uvicorn\u3068\u306f Uvicorn\u306f\u3001Python\u3067\u66f8\u304b\u308c\u305f ASGI\uff08Asynchronous Server Gateway Interface\uff09 \u30b5\u30fc\u30d0\u3067\u3059\u3002\u8efd\u91cf\u3067\u9ad8\u901f\u306a\u975e\u540c\u671fIO\u3092\u6d3b\u7528\u3057\u3001FastAPI\u3001Starl [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[],"class_list":["post-621","post","type-post","status-publish","format-standard","hentry","category-uvicorn"],"_links":{"self":[{"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/posts\/621","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/comments?post=621"}],"version-history":[{"count":0,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/posts\/621\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/media?parent=621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/categories?post=621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/tags?post=621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}