gunicorn_config.py 812 B

1234567891011121314151617181920212223242526272829303132333435
  1. # !/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. '''
  4. @Project : lq-agent-api
  5. @File :gunicorn_config.py
  6. @IDE :PyCharm
  7. @Author :
  8. @Date :2025/7/23 09:07
  9. '''
  10. import multiprocessing
  11. # 基础配置
  12. bind = "0.0.0.0:8001"
  13. workers = multiprocessing.cpu_count() + 1 # 推荐公式
  14. worker_class = "uvicorn.workers.UvicornWorker"
  15. timeout = 120
  16. keepalive = 5
  17. # 日志配置
  18. accesslog = "./gunicorn_log/access_log.log" # 输出到 stdout
  19. errorlog = "./gunicorn_log/error_log.log" # 错误日志到 stderr
  20. loglevel = "info"
  21. # 性能优化
  22. max_requests = 1000 # 防止内存泄漏
  23. max_requests_jitter = 50
  24. graceful_timeout = 30 # 优雅停机时间
  25. # MCP 特定优化
  26. preload_app = True # 减少内存占用,加速启动
  27. # 安全增强
  28. limit_request_line = 4094 # 防止过大请求头