优化rmbg抠图服务:改用WebP格式减小文件体积并增加超时时间
This commit is contained in:
parent
46845e5f57
commit
cd2a6ea74c
@ -357,10 +357,10 @@ class RmbgService:
|
|||||||
|
|
||||||
def save_image_to_file(self, image):
|
def save_image_to_file(self, image):
|
||||||
"""保存图片到文件并返回URL"""
|
"""保存图片到文件并返回URL"""
|
||||||
filename = f"rmbg_{uuid.uuid4().hex[:10]}.png"
|
filename = f"rmbg_{uuid.uuid4().hex[:10]}.webp"
|
||||||
file_path = os.path.join(self.save_dir, filename)
|
file_path = os.path.join(self.save_dir, filename)
|
||||||
|
|
||||||
image.save(file_path, format="PNG", optimize=False, compress_level=1)
|
image.save(file_path, format="WEBP", quality=85, method=6)
|
||||||
image_url = f"{self.download_url}/{filename}"
|
image_url = f"{self.download_url}/{filename}"
|
||||||
return image_url
|
return image_url
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,7 @@ class Settings(BaseSettings):
|
|||||||
# 队列聚合配置(方案B:批处理+队列模式)
|
# 队列聚合配置(方案B:批处理+队列模式)
|
||||||
batch_collect_interval: float = 0.05 # 批处理收集间隔(秒),50ms收集一次,平衡延迟和吞吐量
|
batch_collect_interval: float = 0.05 # 批处理收集间隔(秒),50ms收集一次,平衡延迟和吞吐量
|
||||||
batch_collect_timeout: float = 0.5 # 批处理收集超时(秒),即使未满batch_size,500ms后也处理
|
batch_collect_timeout: float = 0.5 # 批处理收集超时(秒),即使未满batch_size,500ms后也处理
|
||||||
request_timeout: float = 30.0 # 单个请求超时时间(秒)
|
request_timeout: float = 60.0 # 单个请求超时时间(秒)
|
||||||
enable_queue_batch: bool = True # 是否启用队列批处理模式(推荐开启)
|
enable_queue_batch: bool = True # 是否启用队列批处理模式(推荐开启)
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user