diff --git a/lightllm/server/api_start.py b/lightllm/server/api_start.py index a42acef884..b5aadc981f 100644 --- a/lightllm/server/api_start.py +++ b/lightllm/server/api_start.py @@ -3,7 +3,7 @@ import uuid import subprocess import math -from lightllm.utils.start_utils import process_manager +from lightllm.utils.start_utils import configure_decode_open_file_limit, process_manager from .metrics.manager import start_metric_manager from .httpserver.req_id_generator_server import start_req_id_generator_server from .embed_cache.manager import start_cache_manager @@ -45,6 +45,7 @@ def _set_envs_and_config(args: StartArgs): def _launch_subprocesses(args: StartArgs): _validate_pd_features(args) + configure_decode_open_file_limit(args) _set_envs_and_config(args) if args.target_vocab_topk_sampling is not None: diff --git a/lightllm/utils/start_utils.py b/lightllm/utils/start_utils.py index 93bc95a436..28a0e5566e 100644 --- a/lightllm/utils/start_utils.py +++ b/lightllm/utils/start_utils.py @@ -1,5 +1,6 @@ import os import ctypes +import resource import signal import subprocess import sys @@ -253,4 +254,23 @@ def kill_recursive(proc): logger.warning(f"Process {process.pid} does not exist.") +def configure_decode_open_file_limit(args): + if args.run_mode != "decode": + return + + # Each admitted request keeps several shared memory mappings open. + soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE) + preferred = 65536 + target = preferred if hard == resource.RLIM_INFINITY else min(preferred, hard) + if soft != resource.RLIM_INFINITY and soft < target: + try: + resource.setrlimit(resource.RLIMIT_NOFILE, (target, hard)) + except (OSError, ValueError): + logger.warning("Could not raise Decode open-file soft limit from %d to %d", soft, target, exc_info=True) + else: + logger.info("Raised the Decode open-file soft limit from %d to %d", soft, target) + if hard != resource.RLIM_INFINITY and hard < preferred: + logger.warning("Decode open-file hard limit is %d; a burst of requests may exhaust it", hard) + + process_manager = SubmoduleManager()