最近新接觸了一個FastAPI的小項目,發現HTTP SERVER是采用的docker,對應的基礎鏡像是tiangolo/uvicorn-gunicorn-fastapi:python3.7。
這里有個問題,FastAPI官網demo中使用的是uvicorn,這里的tiangolo/uvicorn-gunicorn-fastapi:python3.7應該是uvicorn+gunicorn做HTTP SERVER,為何?
關於Uvicorn和Gunicorn的區別,大家可以參考
https://stackshare.io/stackups/gunicorn-vs-unicorn
其要點是:
Gunicorn是"A Python WSGI HTTP Server for UNIX";
Uvicorn 是"Rack HTTP server for fast clients and Unix"
這里還是有些疑問,因為Uvicorn官網對Uvicorn的定義是:
Uvicorn is a lightning-fast ASGI server implementation, using uvloop and httptools.
這一點和Gunicorn的定義就很接近了。
從tiangolo/uvicorn-gunicorn-fastapi:python3.7的介紹(https://github.com/tiangolo/uvicorn-gunicorn-docker)中可以看到:
Uvicorn
Uvicorn is a lightning-fast "ASGI" server.
It runs asynchronous Python web code in a single process.
Gunicorn
You can use Gunicorn to manage Uvicorn and run multiple of these concurrent processes.
That way, you get the best of concurrency and parallelism.
這里把Uvicorn描述為單進程的ASGI server,而Gunicorn是管理運行多個Uvicorn,以達到並發與並行的最好效果。
如果大家有其他見解請留言。