diff --git a/fir_ser/api/management/commands/services/command.py b/fir_ser/api/management/commands/services/command.py index aeac4c9..99e7a2d 100644 --- a/fir_ser/api/management/commands/services/command.py +++ b/fir_ser/api/management/commands/services/command.py @@ -99,8 +99,8 @@ class BaseActionCommand(BaseCommand): 'services', nargs='+', choices=Services.export_services_values(), help='Service', ) parser.add_argument('-d', '--daemon', nargs="?", const=True) - parser.add_argument('-up', '--uwsgi_processes', type=int, nargs="?", default=4) - parser.add_argument('-ut', '--uwsgi_threads', type=int, nargs="?", default=2) + parser.add_argument('-up', '--uwsgi_processes', type=int, nargs="?", default=get_sys_process_num()) + parser.add_argument('-ut', '--uwsgi_threads', type=int, nargs="?", default=get_sys_thread_num()) parser.add_argument('-usm', '--uwsgi_socket_mode', nargs="?", const=True, help='run to bind socket mode, default http mode, only uwsgi service') parser.add_argument('-f', '--force', nargs="?", const=True) diff --git a/fir_ser/api/management/commands/services/hands.py b/fir_ser/api/management/commands/services/hands.py index 288c47a..1f9c271 100644 --- a/fir_ser/api/management/commands/services/hands.py +++ b/fir_ser/api/management/commands/services/hands.py @@ -3,6 +3,7 @@ import sys import logging from django.conf import settings from config import BASE_DIR +import psutil import time import subprocess @@ -65,3 +66,11 @@ def prepare(): check_database_connection() check_migrations() perform_db_migrate() + + +def get_sys_thread_num(): + return psutil.cpu_count(False) if psutil.cpu_count(False) else 2 + + +def get_sys_process_num(): + return psutil.cpu_count(True) if psutil.cpu_count(True) else 4 diff --git a/fir_ser/api/management/commands/services/utils.py b/fir_ser/api/management/commands/services/utils.py index 510929e..acc8ab5 100644 --- a/fir_ser/api/management/commands/services/utils.py +++ b/fir_ser/api/management/commands/services/utils.py @@ -1,6 +1,5 @@ import threading import signal -import time import daemon from daemon import pidfile from .hands import *