# ！/usr/bin/python
# -*- coding: utf-8 -*-
'''
@Project    : lq-agent-api
@File       :gunicorn_config.py
@IDE        :PyCharm
@Author     :
@Date       :2025/7/23 09:07
'''


import multiprocessing

# 基础配置
bind = "0.0.0.0:8001"
workers = multiprocessing.cpu_count() + 1  # 推荐公式
worker_class = "uvicorn.workers.UvicornWorker"
timeout = 120
keepalive = 5

# 日志配置
accesslog = "./gunicorn_log/access_log.log"  # 输出到 stdout
errorlog = "./gunicorn_log/error_log.log"   # 错误日志到 stderr
loglevel = "info"

# 性能优化
max_requests = 1000     # 防止内存泄漏
max_requests_jitter = 50
graceful_timeout = 30   # 优雅停机时间

# MCP 特定优化
preload_app = True  # 减少内存占用，加速启动

# 安全增强
limit_request_line = 4094  # 防止过大请求头