Primrose Docs
  • Home
    • ⛓️Blockchain
      • Avalanche
        • What is AVAX?
      • Ethereum
        • Ethereum Cancun Upgrade Explained(draft)
        • go-ethereum: gas estimate
        • Blockchain Transaction Lifecycle
        • Mempool
        • Gas optimization in Solidity, Ethereum
      • Solidity DeepDive
        • Meta transaction
        • solidity: patterns
        • UUPS vs Transparent
        • Solidity Interface
        • Smart contract storage
        • ERC-2981 Contract
        • Solidity modifier
        • Solidity delete keyword
        • How To Make NFTs with On-Chain Metadata - Hardhat and JavaScript
        • How to Build "Buy Me a Coffee" DeFi dapp
        • How to Develop an NFT Smart Contract (ERC 721) with Alchemy
        • Upgradeable Contract
        • Smart Contract Verification
      • Common
        • Eigenlayer
        • MultiSig(draft)
        • Chain-Based Proof-of- Stake, BFT-Style Proof-of-Stake
        • Byzantine Fault Tolerance
        • Zero-knowledge
        • Hierarchical Deterministic Wallet
        • Maker DAO
        • Defi
        • Uniswap
        • IBC
        • Cosmos
        • Gossip Protocol
        • Tendermint
        • UTXO vs Account
        • Blockchain Layer
        • Consensus Algorithm
        • How does mining work?
        • Immutable Ledger
        • SHA256 Hash
        • Filecoin
        • IPFS - InterPlanetary File System
        • IPFS와 파일코인
        • Livepeer
        • Layer 0
      • Bitcoin
        • BIP for HD Wallet
        • P2WPKH
        • Segwit vs Native Segwit
    • 📖Languages
      • Javascript/Typescript
        • Hoisting
        • This value in Javascript
        • Execution Context
        • About Javscript
        • tsconfig.json
        • Nest js Provider
        • 'return await promise' vs 'return promise'
      • Python
        • Pythonic
        • Python: Iterable, Iterator
        • Uvicorn & Gunicorn
        • WSGI, ASGI
        • Python docstring
        • Decorator in Python
        • Namespace in Python
        • Python Method
      • Go
        • GORM+MySQL Connection Pool
        • Context in golang
        • How to sign Ethereum EIP-1559 transactions using AWS KMS
        • Mongo DB in golang(draft)
        • Golang HTTP Package
        • Panic
        • Golang new/make
        • golang container package
        • errgroup in golang
        • Generic Programming in Golang
        • Goroutine(draft)
    • 📝Database
      • MongoDB in golang
      • Nested loop join, Hash join
      • DB Query plan
      • Index
      • Optimistic Lock Pessimistic Lock
    • 💻Computer Science
      • N+1 query in go
      • Web server 를 구성할 때 Thread, Process 개수를 어떻게 정할 것인가?
      • CAP
      • Socket programming
      • DNS, IP
      • URL, URI
      • TLS과 SSL
      • Caching(draft)
      • Building Microservices: Micro Service 5 Deploy Principle
      • Red Black Tree
      • AOP
      • Distributed Lock
      • VPC
      • Docker
      • All about Session and JWT
      • Closure
      • Singleton Pattern
      • TCP 3 way handshake & 4 way handshake
      • Race Condition
      • Process Address Space 
      • Call by value, Call by reference, Call by assignment
      • Zookeeper, ETCD
      • URL Shortening
      • Raft consensus
      • Sharding, Partitioning
    • 📒ETC
      • K8S SIGTERM
      • SQS
      • Git Branch Strategy: Ship / Show / Ask
      • Kafka
      • Redis Data Types
      • CI/CD
      • How does Google design APIs?
      • Minishell (42 cursus)
      • Coroutine & Subroutine
      • Redis
Powered by GitBook
On this page
  • Uvicorn and Gunicorn
  • Necessary Concepts
  • Uvicorn
  1. Home
  2. Languages
  3. Python

Uvicorn & Gunicorn

Uvicorn and Gunicorn

Uvicorn and Gunicorn are important concepts when developing applications in Python.

However, there are many concepts to be aware of in order to fully understand Uvicorn and Gunicorn.

The following is a brief summary of the necessary concepts, and the details will be dealt with separately later.


Necessary Concepts

Starlette

Starlette is a Web application server that can run asynchronously. Starlette runs on top of Uvicorn.

FastAPI

FastAPI provides many features on top of Starlette. If you used only Starlette without FastAPI, you have to implement all data validation and serialization.

Because of that, final application may have same overhead as building using the FastAPI.

And in most cases, data validation and serialization are the highest amounts of code written by an application.

FastAPI saves development time, bugs, and cord-lines, and gives you the same performance (or better performance) when you don't.


Asyncio

Asyncio is library which allows to make asynchronous code with using async/await phrase.

Asyncio is used as the basis for several Python asynchronous frameworks that provide high-performance network and web servers, database connection libraries, and distributed task queues.

Asyncio is best suited for IO bottleneck and high-level structured network code.


Uvloop

Uvloop is an event loop replacement for asyncio, making asyncio faster, and more than twice the performance compared to node.js, gevent, and other Python frameworks.

In “uvloop.readthedocs.io”, describes uvloop as follows.

uvloop is a fast, drop-in replacement of the built-in asyncio event loop. uvloop is released under the MIT license.

uvloop and asyncio, combined with the power of async/await in Python 3.5, makes it easier than ever to write high-performance networking code in Python.

uvloop makes asyncio fast. In fact, it is at least 2x faster than nodejs, gevent, as well as any other Python asynchronous framework. The performance of uvloop-based asyncio is close to that of Go programs.

The uvloop was written in Cython based on libuv. Libuv is a high-performance, multi-platform asynchronous I/O library used by node.js, and is fast and stable.

It is no exaggeration to say that the reason why node.js became popular and widely distributed is because of libuv.


Gunicorn

Gunicorn is WSGI server. WSGI is the promised interface or rule between a Python-written web application and a Python-written server.

Simply put, when WSGI servers and web applications are created in accordance with WSGI’s rules, web applications provide the flexibility to freely select and use WSGI servers regardless of internal implementation.

For example, Django provides the wsgi.py for WSGI, you can freely select the WSGI servers, such as gunicorn, uwsgi, without change of internal implementation.

Gunicorn’s process adopts a process-based processing method(프로세스 기반의 처리 방식), which is largely divided into master process and worker process internally.

When gunicorn runs, the process itself is the master process, and the worker process is created based on the number of workers assigned to the setting using forks.

Master process is responsible for managing the worker process, which imports web applications, and receives requests and forwards them to the web application code for processing.


Uvicorn

Uvicorn is a superfast ASGI Web server. Runs uvloop-based asynchronous Python code in a single process.

PreviousPython: Iterable, IteratorNextWSGI, ASGI

Last updated 1 year ago

📖
A brief example of when the http request was made
General web service architecture in Python
ASGI Server Architect