55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
from pydantic_settings import BaseSettings
|
||
from typing import Optional
|
||
from functools import lru_cache
|
||
|
||
class Settings(BaseSettings):
|
||
# Japi Server 配置
|
||
host: str = "0.0.0.0"
|
||
port: int = 8106
|
||
debug: bool = False
|
||
|
||
# API路由配置
|
||
router_prefix: str = "/tools/rmbg"
|
||
file_route: str = "/file"
|
||
file_free_route: str = "/file/free"
|
||
batch_route: str = "/batch"
|
||
api_name: str = "remove_background"
|
||
|
||
upload_url: str = "http://images.jingrow.com:8080/api/v1/image"
|
||
|
||
# 图片保存配置
|
||
save_dir: str = "/home/1panel/www/sites/files.jingrow.com/index"
|
||
# Japi 静态资源下载URL
|
||
download_url: str = "http://files.jingrow.com"
|
||
|
||
# Jingrow Jcloud API 配置
|
||
jingrow_api_url: str = "https://cloud.jingrow.com"
|
||
jingrow_api_key: Optional[str] = None
|
||
jingrow_api_secret: Optional[str] = None
|
||
|
||
# 模型配置
|
||
model_path: str = "./models" # 本地模型文件夹路径(包含 model.safetensors 和 config.json)
|
||
|
||
# HTTP 客户端连接池配置(用于下载图片)
|
||
http_max_connections: int = 200 # httpx 最大并发连接数(根据上行带宽和对端能力调整)
|
||
http_max_keepalive_connections: int = 100 # httpx 最大 keep-alive 空闲连接数
|
||
|
||
# 并发控制配置(推理侧)
|
||
max_workers: int = 60 # 线程池最大工作线程数(根据CPU核心数调整,22核44线程可设置20-30)
|
||
batch_size: int = 8 # GPU批处理大小(模型显存占用较大,8是安全值,16会导致OOM)
|
||
|
||
# 队列聚合配置(方案B:批处理+队列模式)
|
||
batch_collect_interval: float = 0.05 # 批处理收集间隔(秒),50ms收集一次,平衡延迟和吞吐量
|
||
batch_collect_timeout: float = 0.5 # 批处理收集超时(秒),即使未满batch_size,500ms后也处理
|
||
request_timeout: float = 60.0 # 单个请求超时时间(秒)
|
||
enable_queue_batch: bool = True # 是否启用队列批处理模式(推荐开启)
|
||
|
||
class Config:
|
||
env_file = ".env"
|
||
|
||
@lru_cache()
|
||
def get_settings() -> Settings:
|
||
return Settings()
|
||
|
||
# 创建全局配置实例
|
||
settings = get_settings() |