manage.py: Save an extra Django startup by converting one script to a library.

This saves us from spending 200-250ms of CPU time importing Django
again just to log that we're running a management command.  On
`scripts/restart-server`, this saves us from one thundering herd of
Django startups when all the queue workers are restarted; but there's
still the Django startup for the `manage.py` process itself for each
worker, so on a machine with e.g. 2 (virtual) cores the restart is
still painful.
This commit is contained in:
Greg Price
2017-08-17 21:36:37 -07:00
committed by Tim Abbott
parent 517d9b7594
commit f73e898874
3 changed files with 19 additions and 31 deletions

View File

@@ -4,8 +4,6 @@ from __future__ import print_function
import os
import sys
import logging
import subprocess
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(BASE_DIR)
@@ -20,10 +18,9 @@ if __name__ == "__main__":
from django.conf import settings
from django.core.management.base import CommandError
from scripts.lib.zulip_tools import log_management_command
logger = logging.getLogger("zulip.management")
subprocess.check_call([os.path.join(BASE_DIR, "scripts", "lib", "log-management-command"),
" ".join(sys.argv)])
log_management_command(" ".join(sys.argv), settings.MANAGEMENT_LOG_PATH)
if "--no-traceback" not in sys.argv and len(sys.argv) > 1:
sys.argv.append("--traceback")