我有一個在Apache2和WSGI上運行的django應用程序。我使用PyCharm作爲我的IDE進行開發。Django:WSGI,運行apps.populate時很慢,只能偶爾運行
我有下面的wsgi python模塊,並在application = get_wsgi_application()
之後添加了打印語句。在觀看日誌時,這個過程大約需要1秒。什麼是混淆,是什麼時候觸發。我有一個發送簡單文本輸出的頁面。我打了很多次刷新,並且這個打印被寫入日誌一次。如果我等幾秒鐘,它會寫入下一頁的請求。如果我連續刷新,直到我再次等待一段時間。
我的調用和響應大約爲10毫秒,但執行此操作時(通過日誌中的打印驗證)大約需要一秒。這給我的服務器增加了大量不必要的負載,並且降低了速度。我已將其縮小到,該方法在django.setup()
方法中調用。有沒有辦法阻止這種頻繁運行或使其運行速度更快?
感謝您提供任何指導或建議,以解決這個問題或防止它。
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