mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-05 00:33:03 +08:00
[BugFix] fix too many open files problem (#3256)
Some checks failed
Deploy GitHub Pages / deploy (push) Has been cancelled
Some checks failed
Deploy GitHub Pages / deploy (push) Has been cancelled
* Update cache_messager.py * fix too many open files problem * fix too many open files problem * fix too many open files problem * fix ci bugs * Update api_server.py * add parameter * format * format * format * format * Update parameters.md * Update parameters.md * Update serving_completion.py * Update serving_chat.py * Update envs.py --------- Co-authored-by: Jiang-Jia-Jun <163579578+Jiang-Jia-Jun@users.noreply.github.com>
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import codecs
|
||||
import importlib
|
||||
import logging
|
||||
@@ -304,6 +305,16 @@ def set_random_seed(seed: int) -> None:
|
||||
paddle.seed(seed)
|
||||
|
||||
|
||||
def get_limited_max_value(max_value):
|
||||
def validator(value):
|
||||
value = float(value)
|
||||
if value > max_value:
|
||||
raise argparse.ArgumentTypeError(f"The value cannot exceed {max_value}")
|
||||
return value
|
||||
|
||||
return validator
|
||||
|
||||
|
||||
def download_model(url, output_dir, temp_tar):
|
||||
"""
|
||||
下载模型,并将其解压到指定目录。
|
||||
@@ -653,6 +664,61 @@ def deprecated_kwargs_warning(**kwargs):
|
||||
console_logger.warning(f"Deprecated argument is detected: {arg}, which may be removed later")
|
||||
|
||||
|
||||
class StatefulSemaphore:
|
||||
__slots__ = ("_semaphore", "_max_value", "_acquired_count", "_last_reset")
|
||||
|
||||
"""
|
||||
StatefulSemaphore is a class that wraps an asyncio.Semaphore and provides additional stateful information.
|
||||
"""
|
||||
|
||||
def __init__(self, value: int):
|
||||
"""
|
||||
StatefulSemaphore constructor
|
||||
"""
|
||||
if value < 0:
|
||||
raise ValueError("Value must be non-negative.")
|
||||
self._semaphore = asyncio.Semaphore(value)
|
||||
self._max_value = value
|
||||
self._acquired_count = 0
|
||||
self._last_reset = time.monotonic()
|
||||
|
||||
async def acquire(self):
|
||||
await self._semaphore.acquire()
|
||||
self._acquired_count += 1
|
||||
|
||||
def release(self):
|
||||
self._semaphore.release()
|
||||
|
||||
self._acquired_count = max(0, self._acquired_count - 1)
|
||||
|
||||
def locked(self) -> bool:
|
||||
return self._semaphore.locked()
|
||||
|
||||
@property
|
||||
def available(self) -> int:
|
||||
return self._max_value - self._acquired_count
|
||||
|
||||
@property
|
||||
def acquired(self) -> int:
|
||||
return self._acquired_count
|
||||
|
||||
@property
|
||||
def max_value(self) -> int:
|
||||
return self._max_value
|
||||
|
||||
@property
|
||||
def uptime(self) -> float:
|
||||
return time.monotonic() - self._last_reset
|
||||
|
||||
def status(self) -> dict:
|
||||
return {
|
||||
"available": self.available,
|
||||
"acquired": self.acquired,
|
||||
"max_value": self.max_value,
|
||||
"uptime": round(self.uptime, 2),
|
||||
}
|
||||
|
||||
|
||||
llm_logger = get_logger("fastdeploy", "fastdeploy.log")
|
||||
data_processor_logger = get_logger("data_processor", "data_processor.log")
|
||||
scheduler_logger = get_logger("scheduler", "scheduler.log")
|
||||
|
Reference in New Issue
Block a user