uvicorn 怎么指定线程数目上限?
class Config: def __init__(
self,
app: Union[ASGIApplication, Callable, str],
host: str = "127.0.0.1",
port: int = 8000,
uds: Optional[str] = None,
fd: Optional[int] = None,
loop: LoopSetupType = "auto",
http: Union[Type[asyncio.Protocol], HTTPProtocolType] = "auto",
ws: Union[Type[asyncio.Protocol], WSProtocolType] = "auto",
ws_max_size: int = 16 * 1024 * 1024,
ws_ping_interval: Optional[float] = 20,
ws_ping_timeout: Optional[float] = 20,
ws_per_message_deflate: Optional[bool] = True,
lifespan: LifespanType = "auto",
env_file: Optional[Union[str, os.PathLike]] = None,
log_config: Optional[Union[dict, str]] = LOGGING_CONFIG,
log_level: Optional[Union[str, int]] = None,
access_log: bool = True,
use_colors: Optional[bool] = None,
interface: InterfaceType = "auto",
debug: bool = False,
reload: bool = False,
reload_dirs: Optional[Union[List[str], str]] = None,
reload_delay: Optional[float] = None,
reload_includes: Optional[Union[List[str], str]] = None,
reload_excludes: Optional[Union[List[str], str]] = None,
workers: Optional[int] = None,
proxy_headers: bool = True,
server_header: bool = True,
date_header: bool = True,
forwarded_allow_ips: Optional[str] = None,
root_path: str = "",
limit_concurrency: Optional[int] = None,
limit_max_requests: Optional[int] = None,
backlog: int = 2048,
timeout_keep_alive: int = 5,
timeout_notify: int = 30,
callback_notify: Callable[..., Awaitable[None]] = None,
ssl_keyfile: Optional[str] = None,
ssl_certfile: Optional[Union[str, os.PathLike]] = None,
ssl_keyfile_password: Optional[str] = None,
ssl_version: int = SSL_PROTOCOL_VERSION,
ssl_cert_reqs: int = ssl.CERT_NONE,
ssl_ca_certs: Optional[str] = None,
ssl_ciphers: str = "TLSv1",
headers: Optional[List[List[str]]] = None,
factory: bool = False,
):
我该用哪个呀?
回答:
Uvicorn是单进程的ASGI server,而Gunicorn是可以管理运行多个Uvicorn,也以达到并发与并行的最好效果。
执行以下命令将启动4个Uvicorn进程:
gunicorn -w 4 -k uvicorn.workers.UvicornWorker
Uvicorn本身也提供一个简单的多进程管理方式,但是并不推荐,官网描述如下:
Uvicorn provides a lightweight way to run multiple worker processes, for example --workers 4, but does not provide any process monitoring.
这个--workers 4
只是一个轻量级的多进程方式,但不提供任何进程监控功能,所以本质上来说uvicorn还是一个单进程单线程的工具,如果想启动多个进程,可以用--workers
参数,也可以用gunicorn这类工具来管理它。
以上是 uvicorn 怎么指定线程数目上限? 的全部内容, 来源链接: utcz.com/p/938371.html