Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
Django: WSGI, slow when running apps.populate, only runs occasionally

I have a django app running on Apache2 and WSGI. I use PyCharm as my IDE for development.

I have the wsgi python module below, and added a print statement after application = get_wsgi_application(). When watching the logs this process takes about 1 second. What is confusing, is when this gets triggered. I have a page that sends a simple text output. I hit refresh a bunch of times, and this print gets written to the log once. If I wait a few seconds, it gets written on the next page request. If I refresh successively, it does not until I wait for a period again.

My call and response is about 10 milliseconds, but when this is executed (as verified by the print in the log) it takes about a second. This is adding a tremendous amount of unnecessary load to my server and slowing things down. I have it narrowed down to the apps.populate(settings.INSTALLED_APPS) that is called in the django.setup() method. Is there a way I can prevent this from running so often or make it run faster?

Thanks for any guidance, or advice you can offer to figure this out or prevent it.

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
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I was using PyCharm IDE and it was saving the files in real time, each save would prompt a recompile and this log would show up. I closed it and reran the tests and everything is fine. It only logs this function when I reload Apache2.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda