I will explain here how to increase latency of apache2 server,using Django deployment example.At the end of the article you'll get to know that this can be applies to any backend server be it Django or node server.
Installing mod_wsgi the easy way
pip install mod_wsgi
mod_wsgi - module for apache web server
No Apache Configuration Required
$ mod_wsgi-express start-server hello.wsgi
Django Framework Integration
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
.....
.....
'mod_wsgi.server',
]
Send logging to terminal
settings.py
LOGGING = {
# ... omitting the formatters and handlers for brevity ...
'loggers': {
# ... you may have other loggers here as well ...
'django': {
'handlers': ['name_of_your_file_handler_goes_here'],
'level': 'DEBUG',
'propagate': True,
}
}
Or
LOGGING = {
'version':1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class' : 'logging.StreamHandler',
},
},
'loggers' : {
'django' : {
'handlers' : ['console'],
'level' : os.getenv('DJANGO_LOG_LEVEL','INFO'),
},
},
}
Run Django With Management command
python [manage.py](http://manage.py) runmodwsgi
Automatic code reloading
python [manage.py](http://manage.py) runmodwsgi —reload-on-changes
Django DEBUG settings
settings.py
if os.environ.get('MOD_WSGI_DEBUG_MODE'):
DEBUG = True
if os.environ.get('MOD_WSGI_DEBUGGER_ENABLED'):
DEBUG_PROPAGATE_EXCEPTIONS = True
Interactive Debugger
python [manage.py](http://manage.py) runmodwsgi —enable-debugger
Production configuration
python [manage.py](http://manage.py) runmodwsgi \
--server-root /etc/wsgi-port-80 \
--user www-data --group www-data\
--port 80 --setup-only
/etc/wsgi-port-80/apachectl start
/etc/wsgi-port-80/apachectl restart
/etc/wsgi-port-80/apachectl stop
Use daemon mode of mod_wsgi
WSGIRestrictedEmbedded On
WSGIDaemonProcess myapp python-home=/../env
WSGIScriptAlias / /../src/wsgi.py \
process-group=myapp application-group=%{GLOBAL}
<Directory /../src>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Just add whatever the backend server Django or Node anything, putting this above virtualhost on line-1 will boost your latency.
WSGIRestrictedEmbedded On
Top comments (0)