Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
 Post subject: django/uwsgi slow
PostPosted: Wed Oct 30, 2013 3:14 pm 
Offline
Junior Member

Joined: Tue Oct 01, 2013 11:31 am
Posts: 21
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


Top
   
 Post subject: Re: django/uwsgi slow
PostPosted: Thu Oct 31, 2013 1:13 am 
Offline
Junior Member

Joined: Tue Oct 01, 2013 11:31 am
Posts: 21
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)

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


Top
   
 Post subject: Re: django/uwsgi slow
PostPosted: Thu Oct 31, 2013 3:42 pm 
Offline
Senior Member

Joined: Fri Jul 03, 2009 2:31 am
Posts: 54
ICQ: 897607
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.


Top
   
 Post subject: Re: django/uwsgi slow
PostPosted: Fri Nov 01, 2013 1:37 am 
Offline
Junior Member

Joined: Tue Oct 01, 2013 11:31 am
Posts: 21
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 = DJANGO_SETTINGS_MODULE=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


Top
   
 Post subject: Re: django/uwsgi slow
PostPosted: Fri Nov 01, 2013 2:32 pm 
Offline
Senior Member

Joined: Fri Jul 03, 2009 2:31 am
Posts: 54
ICQ: 897607
I'm worried about:
Code:
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


Top
   
 Post subject: Re: django/uwsgi slow
PostPosted: Fri Nov 01, 2013 5:28 pm 
Offline
Senior Member

Joined: Fri Jul 03, 2009 2:31 am
Posts: 54
ICQ: 897607
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

Good luck figuring out how to use it :D


Top
   
 Post subject: Re: django/uwsgi slow
PostPosted: Sat Nov 02, 2013 1:30 am 
Offline
Junior Member

Joined: Tue Oct 01, 2013 11:31 am
Posts: 21
The env = HTTPs=on comes from here
http://security.stackexchange.com/quest ... 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


Top
   
 Post subject: Re: django/uwsgi slow
PostPosted: Sat Nov 02, 2013 1:33 am 
Offline
Junior Member

Joined: Tue Oct 01, 2013 11:31 am
Posts: 21
I have already tried lazy_apps but my performances droped a bit so I took it away.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group