-
Notifications
You must be signed in to change notification settings - Fork 300
Add shm size check #978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add shm size check #978
Changes from 2 commits
da6077d
4ebea76
9cf8751
0f3630d
0f2d2ee
32c7ebd
f27347b
3b65f9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |||||||||||||||||||||||||||||||||||||||||
| import uuid | ||||||||||||||||||||||||||||||||||||||||||
| import subprocess | ||||||||||||||||||||||||||||||||||||||||||
| import signal | ||||||||||||||||||||||||||||||||||||||||||
| import shutil | ||||||||||||||||||||||||||||||||||||||||||
| from lightllm.utils.net_utils import alloc_can_use_network_port, PortLocker | ||||||||||||||||||||||||||||||||||||||||||
| from lightllm.utils.start_utils import process_manager, kill_recursive | ||||||||||||||||||||||||||||||||||||||||||
| from .metrics.manager import start_metric_manager | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -19,6 +20,37 @@ | |||||||||||||||||||||||||||||||||||||||||
| logger = init_logger(__name__) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def get_shm_size_gb(): | ||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||
| 获取 /dev/shm 的总大小(以GB为单位)。 | ||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||
| shm_path = "/dev/shm" | ||||||||||||||||||||||||||||||||||||||||||
| if not os.path.exists(shm_path): | ||||||||||||||||||||||||||||||||||||||||||
| logger.error(f"{shm_path} not exist, this may indicate a system or Docker configuration anomaly.") | ||||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # shutil.disk_usage 返回 (total, used, free) | ||||||||||||||||||||||||||||||||||||||||||
| total_bytes = shutil.disk_usage(shm_path).total | ||||||||||||||||||||||||||||||||||||||||||
| total_gb = total_bytes / (1024 ** 3) | ||||||||||||||||||||||||||||||||||||||||||
| return total_gb | ||||||||||||||||||||||||||||||||||||||||||
| except Exception as e: | ||||||||||||||||||||||||||||||||||||||||||
| logger.error(f"Error getting /dev/shm size: {e}") | ||||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def check_shm_size(): | ||||||||||||||||||||||||||||||||||||||||||
| RED = "\033[91m" | ||||||||||||||||||||||||||||||||||||||||||
| GREEN = "\033[92m" | ||||||||||||||||||||||||||||||||||||||||||
| ENDC = "\033[0m" | ||||||||||||||||||||||||||||||||||||||||||
| shm_size = get_shm_size_gb() | ||||||||||||||||||||||||||||||||||||||||||
| required_size = 128 # 128G | ||||||||||||||||||||||||||||||||||||||||||
| if shm_size < required_size: | ||||||||||||||||||||||||||||||||||||||||||
| logger.warning(f"{RED}Available shm size is less than 128G: {shm_size:.2f}G{ENDC}") | ||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||
| logger.info(f"{GREEN}/dev/shm available space is sufficient ({shm_size:.2f} GB >= {required_size} GB).{ENDC}") | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
| required_size = 128 # 128G | |
| if shm_size < required_size: | |
| logger.warning(f"{RED}Available shm size is less than 128G: {shm_size:.2f}G{ENDC}") | |
| else: | |
| logger.info(f"{GREEN}/dev/shm available space is sufficient ({shm_size:.2f} GB >= {required_size} GB).{ENDC}") | |
| REQUIRED_SIZE_GB = 128 # 128G | |
| if shm_size < REQUIRED_SIZE_GB: | |
| logger.warning(f"{RED}Available shm size is less than {REQUIRED_SIZE_GB}G: {shm_size:.2f}G{ENDC}") | |
| else: | |
| logger.info(f"{GREEN}/dev/shm available space is sufficient ({shm_size:.2f} GB >= {REQUIRED_SIZE_GB} GB).{ENDC}") |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For style and maintainability:
- Move
import threadingto the top of the file (PEP 8). - Define the sleep interval
120as a named constant (e.g.,SHM_CHECK_INTERVAL_S = 120) at the module level.
Since I can't suggest changes outside the diff, I'll define the constant locally, but consider moving both the import and the constant to the module level.
| import threading | |
| def periodic_shm_warning(): | |
| while True: | |
| check_shm_size() | |
| time.sleep(120) # 每 120 秒打印一次警告日志 | |
| shm_warning_thread = threading.Thread(target=periodic_shm_warning, daemon=True) | |
| shm_warning_thread.start() | |
| import threading | |
| SHM_CHECK_INTERVAL_S = 120 # Consider moving this to a module-level constant | |
| def periodic_shm_warning(): | |
| while True: | |
| check_shm_size() | |
| time.sleep(SHM_CHECK_INTERVAL_S) # 每 120 秒打印一次警告日志 | |
| shm_warning_thread = threading.Thread(target=periodic_shm_warning, daemon=True) | |
| shm_warning_thread.start() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function calculates the total SHM size but the PR description refers to "available" space. This can be misleading. To check for available space, use
shutil.disk_usage(shm_path).freeand rename the function toget_shm_free_size_gbfor clarity.