Skip to content

๐Ÿ’ฝ ๐Ÿ‘จโ€๐Ÿญ - ๐Ÿ โฎ๏ธ Uvicorn

โžก๏ธ โœ… ๐Ÿ”™ ๐Ÿ‘ˆ ๐Ÿ› ๏ธ ๐Ÿ”ง โšช๏ธโžก๏ธ โญ:

  • ๐Ÿ’‚โ€โ™‚ - ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”
  • ๐Ÿƒโ€โ™‚ ๐Ÿ”› ๐Ÿ•ด
  • โ
  • ๐Ÿงฌ (๐Ÿ”ข ๐Ÿ› ๏ธ ๐Ÿƒ)
  • ๐Ÿ’พ
  • โฎ๏ธ ๐Ÿ” โญ โ–ถ๏ธ

๐Ÿ†™ ๐Ÿ‘‰ โ˜, โฎ๏ธ ๐ŸŒ ๐Ÿ”ฐ ๐Ÿฉบ, ๐Ÿ‘† โœ”๏ธ ๐ŸŽฒ ๐Ÿƒโ€โ™‚ ๐Ÿ’ฝ ๐Ÿ“‹ ๐Ÿ’– Uvicorn, ๐Ÿƒโ€โ™‚ ๐Ÿ‘ ๐Ÿ› ๏ธ.

๐Ÿ•โ” ๐Ÿ› ๏ธ ๐Ÿˆธ ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’š โœ”๏ธ ๐Ÿงฌ ๐Ÿ› ๏ธ โœŠ ๐Ÿ“ˆ ๐Ÿ’— ๐Ÿš & ๐Ÿ’ช ๐Ÿต ๐ŸŒ… ๐Ÿ“จ.

๐Ÿ‘† ๐Ÿ‘€ โฎ๏ธ ๐Ÿ“ƒ ๐Ÿ”ƒ ๐Ÿ› ๏ธ ๐Ÿ”ง, ๐Ÿ“ค ๐Ÿ’— ๐ŸŽ› ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ.

๐Ÿ“ฅ ๐Ÿ‘ค ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ‘† โ” โš™๏ธ ๐Ÿ โฎ๏ธ Uvicorn ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ.

Info

๐Ÿšฅ ๐Ÿ‘† โš™๏ธ ๐Ÿ“ฆ, ๐Ÿ–ผ โฎ๏ธ โ˜ โš–๏ธ Kubernetes, ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ’ฌ ๐Ÿ‘† ๐ŸŒ… ๐Ÿ”ƒ ๐Ÿ‘ˆ โญ ๐Ÿ“ƒ: FastAPI ๐Ÿ“ฆ - โ˜.

๐ŸŽฏ, ๐Ÿ•โ” ๐Ÿƒ ๐Ÿ”› Kubernetes ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿšซ ๐Ÿ’š โš™๏ธ ๐Ÿ & โ†ฉ๏ธ ๐Ÿƒ ๐Ÿ‘ Uvicorn ๐Ÿ› ๏ธ ๐Ÿ“ ๐Ÿ“ฆ, โœ‹๏ธ ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ’ฌ ๐Ÿ‘† ๐Ÿ”ƒ โšซ๏ธ โช ๐Ÿ‘ˆ ๐Ÿ“ƒ.

๐Ÿ โฎ๏ธ Uvicorn ๐Ÿ‘จโ€๐Ÿญ

๐Ÿ โœด๏ธ ๐Ÿˆธ ๐Ÿ’ฝ โš™๏ธ ๐Ÿ‡จ๐Ÿ‡ป ๐Ÿฉ. ๐Ÿ‘ˆ โ›“ ๐Ÿ‘ˆ ๐Ÿ ๐Ÿ’ช ๐Ÿฆ ๐Ÿˆธ ๐Ÿ’– ๐Ÿบ & โœณ. ๐Ÿ โšซ๏ธ ๐Ÿšซ ๐Ÿ”— โฎ๏ธ FastAPI, FastAPI โš™๏ธ ๐Ÿ†• ๐Ÿ”ซ ๐Ÿฉ.

โœ‹๏ธ ๐Ÿ ๐Ÿ•โ€๐Ÿฆบ ๐Ÿ‘ท ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ & ๐Ÿค ๐Ÿ‘ฉโ€๐Ÿ’ป ๐Ÿ’ฌ โšซ๏ธ โ” ๐ŸŽฏ ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ ๐ŸŽ“ โš™๏ธ. โคด๏ธ ๐Ÿ ๐Ÿ”œ โ–ถ๏ธ 1๏ธโƒฃ โš–๏ธ ๐ŸŒ– ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ โš™๏ธ ๐Ÿ‘ˆ ๐ŸŽ“.

& Uvicorn โœ”๏ธ ๐Ÿ-๐Ÿ”— ๐Ÿ‘จโ€๐Ÿญ ๐ŸŽ“.

โš™๏ธ ๐Ÿ‘ˆ ๐ŸŒ€, ๐Ÿ ๐Ÿ”œ ๐Ÿšซ ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ, ๐Ÿ‘‚ ๐Ÿ”› โ›ด & ๐Ÿ“ข. & โšซ๏ธ ๐Ÿ”œ ๐Ÿ“ถ ๐Ÿ“ป ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ ๐Ÿƒ Uvicorn ๐ŸŽ“.

& โคด๏ธ ๐Ÿ-๐Ÿ”— Uvicorn ๐Ÿ‘จโ€๐Ÿญ ๐ŸŽ“ ๐Ÿ”œ ๐Ÿˆš ๐Ÿญ ๐Ÿ“Š ๐Ÿ“จ ๐Ÿ ๐Ÿ”ซ ๐Ÿฉ FastAPI โš™๏ธ โšซ๏ธ.

โŽ ๐Ÿ & Uvicorn

$ pip install "uvicorn[standard]" gunicorn

---> 100%

๐Ÿ‘ˆ ๐Ÿ”œ โŽ ๐Ÿ‘ฏโ€โ™‚๏ธ Uvicorn โฎ๏ธ standard โž• ๐Ÿ“ฆ (๐Ÿคš โ†• ๐ŸŽญ) & ๐Ÿ.

๐Ÿƒ ๐Ÿ โฎ๏ธ Uvicorn ๐Ÿ‘จโ€๐Ÿญ

โคด๏ธ ๐Ÿ‘† ๐Ÿ’ช ๐Ÿƒ ๐Ÿ โฎ๏ธ:

$ gunicorn main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:80

[19499] [INFO] Starting gunicorn 20.1.0
[19499] [INFO] Listening at: http://0.0.0.0:80 (19499)
[19499] [INFO] Using worker: uvicorn.workers.UvicornWorker
[19511] [INFO] Booting worker with pid: 19511
[19513] [INFO] Booting worker with pid: 19513
[19514] [INFO] Booting worker with pid: 19514
[19515] [INFO] Booting worker with pid: 19515
[19511] [INFO] Started server process [19511]
[19511] [INFO] Waiting for application startup.
[19511] [INFO] Application startup complete.
[19513] [INFO] Started server process [19513]
[19513] [INFO] Waiting for application startup.
[19513] [INFO] Application startup complete.
[19514] [INFO] Started server process [19514]
[19514] [INFO] Waiting for application startup.
[19514] [INFO] Application startup complete.
[19515] [INFO] Started server process [19515]
[19515] [INFO] Waiting for application startup.
[19515] [INFO] Application startup complete.

โžก๏ธ ๐Ÿ‘€ โšซ๏ธโ” ๐Ÿ”  ๐Ÿ‘ˆ ๐ŸŽ› โ›“:

  • main:app: ๐Ÿ‘‰ ๐ŸŽ โ• โš™๏ธ Uvicorn, main โ›“ ๐Ÿ ๐Ÿ•น ๐Ÿ“› "main",, ๐Ÿ“ main.py. & app ๐Ÿ“› ๐Ÿ”ข ๐Ÿ‘ˆ FastAPI ๐Ÿˆธ.

    • ๐Ÿ‘† ๐Ÿ’ช ๐ŸŒˆ ๐Ÿ‘ˆ main:app ๐ŸŒ“ ๐Ÿ import ๐Ÿ“„ ๐Ÿ’–:

      from main import app
      
    • , โค main:app ๐Ÿ”œ ๐ŸŒ“ ๐Ÿ import ๐Ÿ• from main import app.

    • --workers: ๐Ÿ”ข ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ โš™๏ธ, ๐Ÿ”  ๐Ÿ”œ ๐Ÿƒ Uvicorn ๐Ÿ‘จโ€๐Ÿญ, ๐Ÿ‘‰ ๐Ÿ’ผ, 4๏ธโƒฃ ๐Ÿ‘จโ€๐Ÿญ.
    • --worker-class: ๐Ÿ-๐Ÿ”— ๐Ÿ‘จโ€๐Ÿญ ๐ŸŽ“ โš™๏ธ ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ.
    • ๐Ÿ“ฅ ๐Ÿ‘ฅ ๐Ÿšถโ€โ™€๏ธ ๐ŸŽ“ ๐Ÿ‘ˆ ๐Ÿ ๐Ÿ’ช ๐Ÿ—„ & โš™๏ธ โฎ๏ธ:

      import uvicorn.workers.UvicornWorker
      
  • --bind: ๐Ÿ‘‰ ๐Ÿ’ฌ ๐Ÿ ๐Ÿ“ข & โ›ด ๐Ÿ‘‚, โš™๏ธ โค (:) ๐ŸŽ ๐Ÿ“ข & โ›ด.

    • ๐Ÿšฅ ๐Ÿ‘† ๐Ÿƒโ€โ™‚ Uvicorn ๐Ÿ”—, โ†ฉ๏ธ --bind 0.0.0.0:80 (๐Ÿ ๐ŸŽ›) ๐Ÿ‘† ๐Ÿ”œ โš™๏ธ --host 0.0.0.0 & --port 80.

๐Ÿ”ข, ๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ‘ˆ โšซ๏ธ ๐ŸŽฆ ๐Ÿ•น (๐Ÿ› ๏ธ ๐Ÿ†”) ๐Ÿ”  ๐Ÿ› ๏ธ (โšซ๏ธ ๐Ÿ”ข).

๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ‘ˆ:

  • ๐Ÿ ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ โ–ถ๏ธ โฎ๏ธ ๐Ÿ•น 19499 (๐Ÿ‘† ๐Ÿ’ผ โšซ๏ธ ๐Ÿ”œ ๐ŸŽ ๐Ÿ”ข).
  • โคด๏ธ โšซ๏ธ โ–ถ๏ธ Listening at: http://0.0.0.0:80.
  • โคด๏ธ โšซ๏ธ ๐Ÿ” ๐Ÿ‘ˆ โšซ๏ธ โœ”๏ธ โš™๏ธ ๐Ÿ‘จโ€๐Ÿญ ๐ŸŽ“ uvicorn.workers.UvicornWorker.
  • & โคด๏ธ โšซ๏ธ โ–ถ๏ธ 4๏ธโƒฃ ๐Ÿ‘จโ€๐Ÿญ, ๐Ÿ”  โฎ๏ธ ๐Ÿšฎ ๐Ÿ‘ ๐Ÿ•น: 19511, 19513, 19514, & 19515.

๐Ÿ ๐Ÿ”œ โœŠ ๐Ÿ’… ๐Ÿ› ๏ธ โ˜ ๏ธ ๐Ÿ› ๏ธ & ๐Ÿ” ๐Ÿ†• ๐Ÿ• ๐Ÿšฅ ๐Ÿ’š ๐Ÿšง ๐Ÿ”ข ๐Ÿ‘จโ€๐Ÿญ. ๐Ÿ‘ˆ โ„น ๐Ÿ• โฎ๏ธ โ ๐Ÿ”ง โšช๏ธโžก๏ธ ๐Ÿ“‡ ๐Ÿ”›.

๐Ÿ‘, ๐Ÿ‘† ๐Ÿ”œ ๐ŸŽฒ ๐Ÿ’š โœ”๏ธ ๐Ÿ•ณ ๐Ÿž โš’ ๐Ÿ’ญ โ ๐Ÿ ๐Ÿšฅ ๐Ÿ’ช, & ๐Ÿƒ โšซ๏ธ ๐Ÿ”› ๐Ÿ•ด, โ™’๏ธ.

Uvicorn โฎ๏ธ ๐Ÿ‘จโ€๐Ÿญ

Uvicorn โœ”๏ธ ๐ŸŽ› โ–ถ๏ธ & ๐Ÿƒ ๐Ÿ“š ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ.

๐Ÿ‘, ๐Ÿ”œ, Uvicorn ๐Ÿ› ๏ธ ๐Ÿšš ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ ๐ŸŒ… ๐Ÿ“‰ ๐ŸŒ˜ ๐Ÿ. , ๐Ÿšฅ ๐Ÿ‘† ๐Ÿ’š โœ”๏ธ ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ ๐Ÿ‘‰ ๐ŸŽš (๐Ÿ ๐ŸŽš), โคด๏ธ โšซ๏ธ ๐Ÿ’ช ๐Ÿ‘ ๐Ÿ”„ โฎ๏ธ ๐Ÿ ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ.

๐Ÿ™† ๐Ÿ’ผ, ๐Ÿ‘† ๐Ÿ”œ ๐Ÿƒ โšซ๏ธ ๐Ÿ’– ๐Ÿ‘‰:

$ uvicorn main:app --host 0.0.0.0 --port 8080 --workers 4
<font color="#A6E22E">INFO</font>:     Uvicorn running on <b>http://0.0.0.0:8080</b> (Press CTRL+C to quit)
<font color="#A6E22E">INFO</font>:     Started parent process [<font color="#A1EFE4"><b>27365</b></font>]
<font color="#A6E22E">INFO</font>:     Started server process [<font color="#A1EFE4">27368</font>]
<font color="#A6E22E">INFO</font>:     Waiting for application startup.
<font color="#A6E22E">INFO</font>:     Application startup complete.
<font color="#A6E22E">INFO</font>:     Started server process [<font color="#A1EFE4">27369</font>]
<font color="#A6E22E">INFO</font>:     Waiting for application startup.
<font color="#A6E22E">INFO</font>:     Application startup complete.
<font color="#A6E22E">INFO</font>:     Started server process [<font color="#A1EFE4">27370</font>]
<font color="#A6E22E">INFO</font>:     Waiting for application startup.
<font color="#A6E22E">INFO</font>:     Application startup complete.
<font color="#A6E22E">INFO</font>:     Started server process [<font color="#A1EFE4">27367</font>]
<font color="#A6E22E">INFO</font>:     Waiting for application startup.
<font color="#A6E22E">INFO</font>:     Application startup complete.

๐Ÿ•ด ๐Ÿ†• ๐ŸŽ› ๐Ÿ“ฅ --workers ๐Ÿ’ฌ Uvicorn โ–ถ๏ธ 4๏ธโƒฃ ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ.

๐Ÿ‘† ๐Ÿ’ช ๐Ÿ‘€ ๐Ÿ‘ˆ โšซ๏ธ ๐ŸŽฆ ๐Ÿ•น ๐Ÿ”  ๐Ÿ› ๏ธ, 27365 ๐Ÿ‘ช ๐Ÿ› ๏ธ (๐Ÿ‘‰ ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ) & 1๏ธโƒฃ ๐Ÿ”  ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ: 27368, 27369, 27370, & 27367.

๐Ÿ› ๏ธ ๐Ÿ”ง

๐Ÿ“ฅ ๐Ÿ‘† ๐Ÿ‘€ โ” โš™๏ธ ๐Ÿ (โš–๏ธ Uvicorn) ๐Ÿ› ๏ธ Uvicorn ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ› ๏ธ ๐Ÿ” ๐Ÿ› ๏ธ ๐Ÿˆธ, โœŠ ๐Ÿ“ˆ ๐Ÿ’— ๐Ÿš ๐Ÿ’ฝ, & ๐Ÿ’ช ๐Ÿฆ ๐ŸŒ… ๐Ÿ“จ.

โšช๏ธโžก๏ธ ๐Ÿ“‡ ๐Ÿ› ๏ธ ๐Ÿ”ง โšช๏ธโžก๏ธ ๐Ÿ”›, โš™๏ธ ๐Ÿ‘จโ€๐Ÿญ ๐Ÿ”œ โœด๏ธ โ„น โฎ๏ธ ๐Ÿงฌ ๐Ÿ•, & ๐Ÿฅ ๐Ÿ– โฎ๏ธ โ, โœ‹๏ธ ๐Ÿ‘† ๐Ÿ’ช โœŠ ๐Ÿ’… ๐ŸŽ:

  • ๐Ÿ’‚โ€โ™‚ - ๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ”
  • ๐Ÿƒโ€โ™‚ ๐Ÿ”› ๐Ÿ•ด
  • โ
  • ๐Ÿงฌ (๐Ÿ”ข ๐Ÿ› ๏ธ ๐Ÿƒ)
  • ๐Ÿ’พ
  • โฎ๏ธ ๐Ÿ” โญ โ–ถ๏ธ

๐Ÿ“ฆ & โ˜

โญ ๐Ÿ“ƒ ๐Ÿ”ƒ FastAPI ๐Ÿ“ฆ - โ˜ ๐Ÿ‘ค ๐Ÿ”œ ๐Ÿ’ฌ ๐ŸŽ› ๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿต ๐ŸŽ ๐Ÿ› ๏ธ ๐Ÿ”ง.

๐Ÿ‘ค ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ‘† ๐Ÿ›‚ โ˜ ๐Ÿ–ผ ๐Ÿ‘ˆ ๐Ÿ”Œ ๐Ÿ โฎ๏ธ Uvicorn ๐Ÿ‘จโ€๐Ÿญ & ๐Ÿ”ข ๐Ÿ“ณ ๐Ÿ‘ˆ ๐Ÿ’ช โš  ๐Ÿ™… ๐Ÿ’ผ.

๐Ÿ“ค ๐Ÿ‘ค ๐Ÿ”œ ๐ŸŽฆ ๐Ÿ‘† โ” ๐Ÿ— ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ–ผ โšช๏ธโžก๏ธ ๐Ÿ–Œ ๐Ÿƒ ๐Ÿ‘ Uvicorn ๐Ÿ› ๏ธ (๐Ÿต ๐Ÿ). โšซ๏ธ ๐Ÿ™… ๐Ÿ› ๏ธ & ๐ŸŽฒ โšซ๏ธโ” ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ’š ๐Ÿ•โ” โš™๏ธ ๐Ÿ“Ž ๐Ÿ“ฆ ๐Ÿงพ โš™๏ธ ๐Ÿ’– Kubernetes.

๐ŸŒƒ

๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ (โš–๏ธ Uvicorn) ๐Ÿ› ๏ธ ๐Ÿ‘จโ€๐Ÿ’ผ โฎ๏ธ Uvicorn ๐Ÿ‘จโ€๐Ÿญ โœŠ ๐Ÿ“ˆ ๐Ÿ‘-๐Ÿš ๐Ÿ’ฝ, ๐Ÿƒ ๐Ÿ’— ๐Ÿ› ๏ธ ๐Ÿ”—.

๐Ÿ‘† ๐Ÿ’ช โš™๏ธ ๐Ÿ‘‰ ๐Ÿงฐ & ๐Ÿ’ญ ๐Ÿšฅ ๐Ÿ‘† โš’ ๐Ÿ†™ ๐Ÿ‘† ๐Ÿ‘ ๐Ÿ› ๏ธ โš™๏ธ โช โœŠ ๐Ÿ’… ๐ŸŽ ๐Ÿ› ๏ธ ๐Ÿ”ง ๐Ÿ‘†.

โœ… ๐Ÿ‘… โญ ๐Ÿ“ƒ ๐Ÿ’ก ๐Ÿ”ƒ FastAPI โฎ๏ธ ๐Ÿ“ฆ (โœ… โ˜ & Kubernetes). ๐Ÿ‘† ๐Ÿ”œ ๐Ÿ‘€ ๐Ÿ‘ˆ ๐Ÿ‘ˆ ๐Ÿงฐ โœ”๏ธ ๐Ÿ™… ๐ŸŒŒ โŽ ๐ŸŽ ๐Ÿ› ๏ธ ๐Ÿ”ง ๐Ÿ‘. ๐Ÿ‘ถ