falsk + gunicornが並行性を実現

-GunicornはWINをサポートしていません。すべてLinuxで実行されます。


-__ name__ == "__main__"の場合は次のようにスクリプトを実行するだけです:
    #app.run(debug = False、host = '0.0.0.0'、port = 8886、threaded = True)
    app.run()

--pip install gunicorn 

--gunicorn -w 4 -b 0.0.0.0:8080 main:app

-wは作業数、4つの-bを設定してポートを指定し、mainはスクリプトの名前、appはフラスコアプリケーションの名前です。

図4プロセス

ビデオメモリは当然4倍です。

 

 補足:

ピップインストールベント

新しい構成ファイル:vim gunicorn.py


import os
import gevent.monkey
gevent.monkey.patch_all()
import multiprocessing

# backlog = 512    #监听队列
# debug = True  # debug开启
# threads = 2 # 指定每个进程开启的线程数
# daemon = True # 表示开启后台运行,默认False
loglevel = 'debug'
bind = "0.0.0.0:5001" # 绑定的ip和端口号

# /var/log/WEB_APP 目录必须存在
# pidfile = "/var/log/WEB_APP/gunicorn.pid"
# accesslog = "/var/log/WEB_APP/access.log"
# access_log_format = '%(t)s %(p)s %(h)s "%(r)s" %(s)s %(L)s %(b)s %(f)s" "%(a)s"' 

#设置守护进程
#daemon=True

#设置超时时间120s。默认为30s
timeout=120

#设置访问日志与错误信息日志路径
errorlog = "./error.log"

# 启动的进程数
#workers = multiprocessing.cpu_count() # 这里取的是CPU的数量
workers = 4   # 进程数,

worker_class = 'gevent'   # worker_class是指开启的每个工作进程的模式类型,默认为sync模式,这里使用gevent模式

x_forwarded_for_header = 'X-FORWARDED-FOR'

gunicorn manager02:app -c gunicorn.py(manager02はスクリプトの名前、appはフラスコ内のアプリケーションの名前)を実行します。非常に高い同時実行性(CPUのボトルネックに達するまで?)

 

## 2021 01 25 

--fastapi

--pip install fastapi 
pip install uvicorn

uvicorn fast_api:app --workers 3 --port 5000

おすすめ

転載: blog.csdn.net/xkx_07_10/article/details/108081483