django/uwsgi slow

Hello,

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 had some success so I will post here.

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 http://stackoverflow.com/questions/1593 … n-so-error">http://stackoverflow.com/questions/15936413/pip-installed-uwsgi-python-plugin-so-error)

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

Yes, as Roberto mentioned in another SO question, you won't see good results if you are using uWSGI version < 1.4 :)

The thread is here and mentions something else you might want to try: –thunder-lock may help balance the load better between your workers.

OK, thanks for the tip. Now the request are equally distributed.

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

I'm worried about: 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 :D

Hah, the best thing about uWSGI is how easy it can be to quickly set up serving multiple vhosts on a development machine.

The worst thing is how complicated it is to set up serving multiple hosts in production :D

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:

http://uwsgi-docs.readthedocs.org/en/la … -reloading">http://uwsgi-docs.readthedocs.org/en/latest/Changelog-1.9.html#chain-reloading

Good luck figuring out how to use it :D

The env = HTTPs=on comes from here

http://security.stackexchange.com/quest … its-secure">http://security.stackexchange.com/questions/8964/trying-to-make-a-django-based-site-use-https-only-not-sure-if-its-secure

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

I have already tried lazy_apps but my performances droped a bit so I took it away.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct