Apache2 및 WSGI에서 실행되는 장고 앱이 있습니다. 개발 용 IDE로 PyCharm을 사용합니다.Django : WSGI, apps.populate 실행 속도가 느리다. 가끔씩 만 실행됩니다.
아래 wsgi python 모듈이 있으며 application = get_wsgi_application()
뒤에 print 문을 추가했습니다. 로그를 볼 때이 프로세스는 약 1 초가 걸립니다. 혼란 스러울 때, 이것이 발동 될 때입니다. 간단한 텍스트 출력을 보내는 페이지가 있습니다. 새로 고침을 여러 번하고,이 인쇄물을 한 번 로그에 기록합니다. 잠시 기다리면 다음 페이지 요청시 작성됩니다. 계속해서 새로 고치면 다시 한 번 기다릴 때까지 기다리지 않습니다.
내 전화와 응답은 약 10 밀리 초이지만,이 작업이 실행되면 (로그의 인쇄에 의해 확인 된 것처럼) 약 1 초가 소요됩니다. 이것은 엄청난 양의 불필요한 부하를 서버에 추가하고 작업 속도를 저하시킵니다. django.setup()
메서드에서 호출되는 apps.populate(settings.INSTALLED_APPS)
으로 좁혀졌습니다. 이 작업이 너무 자주 실행되거나 실행 속도가 빨라지는 것을 막을 수있는 방법이 있습니까?
어떤 지침이나 조언을 제공해 주셔서 감사 드리며이를 방지 할 수 있습니다.
wsgi.py :
import datetime
import os
import sys
from django.core.wsgi import get_wsgi_application
root_path = os.path.abspath(os.path.split(__file__)[0])
sys.path.insert(0, os.path.join(root_path, 'project_name'))
sys.path.insert(0, root_path)
path = '/var/www/project'
if path not in sys.path:
sys.path.append(path)
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
start = datetime.datetime.now()
application = get_wsgi_application()
print('Time to Populate: ' + str(datetime.datetime.now() - start))
settings.INSTALLED_APPS :
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'report_builder', # Third-party tool
'business', # Internal app
'slab', # Internal app
'file', # Internal app
'training_topic', # Internal app
'item', # Internal app
'person', # Internal app
'employee', # Internal app
'school', # Internal app
'training', # Internal app
'services', # Internal app
'incident', # Internal app
'report', # Internal app
'notice', # Internal app
'county_notification', # Internal app
'utilities.fax', # Internal app
'log', # Internal app
'helptext', # Internal app
'search', # Internal app
'compensation', # Internal app
'data_export', # Internal app
'record_review', # Internal app
)
/var/log/apache2/error.log :
[Tue Apr 25 14:07:22.917665 2017] [wsgi:error] [pid 21810] Time to Populate: 0:00:00.826958
[Tue Apr 25 14:07:34.715745 2017] [wsgi:error] [pid 21817] Time to Populate: 0:00:00.822580