Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda