Gunicorn

Gunicorn

  1. 简单使用

    开启服务命令:
    gunicorn -w 4 -b 127.0.0.1:5000 -D manager:app
    
    参数详解:
    -w: worker 代表开启工作者的数量,可以理解为进程(通常 worker 的数量为 cpu 个数的 2-4倍)
    -b: bind 代表开启服务绑定的地址
    -D: 代表后台运行 gunicorn 程序
    manager:app 代表使用 gunicorn 管理 manager 中的 app 应用程序
    
  2. 配置文件使用

    1. 配置文件

      # gunicorn.py
      import logging
      import logging.handlers
      from logging.handlers import WatchedFileHandler
      import os
      import multiprocessing
      *** bind = '127.0.0.1:8000'      #绑定ip和端口号
      backlog = 512                #监听队列
      *** chdir = '/home/ubuntu/Python/project'  # gunicorn执行之前默认跳转的目录位置
      timeout = 30      #超时
      worker_class = 'gevent' #使用gevent模式,还可以使用sync 模式,默认的是sync模式
      
      workers = multiprocessing.cpu_count() * 2 + 1    #进程数
      daemon = 'false'	# 守护进程,将进程交给supervisor管理
      threads = 2 #指定每个进程开启的线程数
      loglevel = 'info' #日志级别,这个日志级别指的是错误日志的级别,而访问日志的级别无法设置
      access_log_format = '%(t)s %(p)s %(h)s "%(r)s" %(s)s %(L)s %(b)s %(f)s" "%(a)s"'    #设置gunicorn访问日志格式,错误日志无法设置
      
      """
      其每个选项的含义如下:
      h          remote address
      l          '-'
      u          currently '-', may be user name in future releases
      t          date of the request
      r          status line (e.g. ``GET / HTTP/1.1``)
      s          status
      b          response length or '-'
      f          referer
      a          user agent
      T          request time in seconds
      D          request time in microseconds
      L          request time in decimal seconds
      p          process ID
      """
      *** accesslog = "/home/Python/project/log/gunicorn_access.log"      #访问日志文件
      *** errorlog = "/home/Python/project/log/gunicorn_error.log"        #错误日志文件
      
      
    2. 配置文件的启动命令

      开启服务命令:
      gunicorn -c gunicorn.py manager:app
      
      参数详解:
      -c: config 代表指定使用配置文件的路径
      
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值