django/uwsgi slow
I am experiencing slow response on my web server.
I have logged postgresql statements and they seem good.
Doing the same request in a row and I get typically in row (reading uwsgi logs) response time of:
20 seconds
10 second
800 ms
8 seconds
Frist two are always high then I get a fast response then again a high time.
Using linode with ubuntu 11.10.
I am looking on tweaking uwsgi params but anything I try it does not change.
Since I have an old version of uwsgi 0.9.8.1 I am thinking on installing something newer? Should I do it with pip install?
Is this behaviour something known with a known workaround?
Of the most important uwsgi params I am using:
processes=8
master=True
cpu-affinity=1
socket = /run/uwsgi/socket
enable-threads=True
I have tried on profiling the django view I am using for test but I do not see there 20 seconds.
Thanks
Nenad
7 Replies
I didn't uninstiall any package What I did is:
- pip install uwsgi ; after that I got uwsgi in /usr/local/bin
-edited /etc/init.d/uwsgi and changed the line to DAEMON="/usr/local/bin/uwsgi"
-i had to create /run/uwsgi default folder and remove the plugins conf param from my conf file (see
Now the speed is much better and predictable.
Some problems remains:
-conf files are read in inverse order so I changed the /usr/lib/uwsgi/conf/default.ini to have 8 workers
-service uwsgi start does start but reports fail
-service uwsgi stop does not kill the processes
I think the problem is the do_command script which should be changed but I am not expert enoguh to do it. Anyway I can live with these problems.
I passed from uwsgi 0.9.8.1 to 1.9.18.2 quite easily.
hth to someone
Nenad
The thread is here
I have noticed one thing, maybe is normal.
My response times were high till all workers executed once. I suppose each process is loading the django module at their first usage.
Being newbie for web I have to learn many things, but it isn't true that the workers are restarted once a while?
Then I suppose I will have this delay each time a new worker is spawned.
I am posting my complete config for others reference and for you if you spot something wierd.
(the plugin param is missing because I have installed uwsgi from pip so I suppose it is already in there)
[uwsgi]
protocol = uwsgi
virtualenv=/FAVXP_ENV/
workers=8
threads=4
master=True
cpu-affinity=1
env = DJANGOSETTINGSMODULE=settings
module = django.core.handlers.wsgi:WSGIHandler()
chdir = /FAVXP_ENV/favxp/
socket = /run/uwsgi/cp/socket
logto = /var/log/uwsgi/cp.log
pythonpath = /FAVXP_ENV/
pythonpath = /FAVXP_ENV/favxp/
harakiri = 0
env = HTTPS=on
home = /FAVXP_ENV/
reload-mercy=8
max-requests=2000
limit-as=512
reload-on-as=256
reload-on-rss=192
no-orphans=True
vacuum=True
enable-threads=True
stats = /tmp/stats.socket
post-buffering=8192
socket-timeout=120
thunder-lock = True
thanks
Nenad
env = HTTPS=on
Are you serving the site directly from uWSGI?
If you are behind a reverse proxy then the proxy should be setting X-FORWARDED-PROTO=https itself based on whether request came from https or not. Django will set the request.is_secure() flag based on that header.
I haven't seen any methods for forcing workers load up the app before first connection, but I'll be trying to figure that out myself. I suppose the best thing is to fix memory leaks in app and then the only reason to restart is for code updates
The worst thing is how complicated it is to set up serving multiple hosts in production
That mostly comes from the poor documentation, but hopefully they'll get there (anyone remember all the complaints about how the only good nginx docs were all in Russian?).
Anyway, this tidbit about forced reloading is in the 1.9 changelog but doesn't seem to be documented or explained any where else:
Good luck figuring out how to use it
I am using nginx.
I was concerned about the HttpResponseRedirect inside the django I have and with this param my internal link (I have only internal links) are generated with https
Thanks for looking at configs
Nenad