Gunicorn 简单使用

Gunicorn 简单使用

  1. 配置文件如下
import multiprocessing

bind = '0.0.0.0:8000'
workers = multiprocessing.cpu_count() * 2 + 1
# 服务连接已满时,可容纳的等待连接数,当超过该值时,服务会直接被拒绝
backlog = 2048
worker_class = "gevent"
# 最大连接数
worker_connections = 1000
threads = 30
# 后台运行
daemon = True
proc_name = 'gunicorn_demo'
# 日志输出
access_log = "./logs/access_guni.log"
error_log = "./logs/error/guni.log"
# pid 用于启停
pidfile = "./logs/guni.pid"
timeout = 600
  1. 服务启停
  • 启动 gunicorn -c guni_config.py manage:app
    • manage 就是 python 文件mange.py
    • 服务对象叫做 app
  • 关闭 kill -9 ./logs/guni.pid
  • 重启 kill -HUP ./logs/guni.pid
  1. 配置 syslog(可输出到 logstash)
syslog = True
syslog_addr = "udp://11.1.1.1:9090"
access_log_format = ''%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"''
  1. 日志格式解释
  • 官方文档 https://docs.gunicorn.org/en/stable/settings.html#access-log-format
变量名释义备注
hremote address
l‘-’
uuser name
tdate of the request
rstatus line (e.g. GET / HTTP/1.1)
mrequest method
UURL path without query string
qquery string
Hprotocol
sstatus
Bresponse length
bresponse length or ‘-’ (CLF format)
freferer
auser agent
Trequest time in seconds
Drequest time in microseconds
Lrequest time in decimal seconds
pprocess ID
{header}irequest header
{header}oresponse header
{variable}eenvironment variable
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值