Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » query fast on command line - slow via url [RSS Feed]

#1 Dec. 19, 2010 18:43:07

N.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

query fast on command line - slow via url


I'm trying to determine why our search queries return so slow.

We are not doing anything fancy in our searches, simply searching
for author, or title in a table of about 6000 books.http://www.rareorientalbooks.com/searchadv/On the command line using the exact code in the views.py everything
returns instantly.

When accessing the same code via url browser access all searches take
a minimum of 10 seconds whether it returning 10 or 500 titles.

__If via the command line the queries return instantly

* am I right in thinking the bottleneck is somewhere else in the
process?

* where might that bottleneck be and how can i streamline it?

Any ideas appreciated.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 20, 2010 11:02:31

Tom E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

query fast on command line - slow via url


On Sun, Dec 19, 2010 at 6:43 PM, NoviceSortOf <dljonsson2...@gmail.com> wrote:
> I'm trying to determine why our search queries return so slow.
>
> We are not doing anything fancy in our searches, simply searching
> for author, or title in a table of about 6000 books.
>
>http://www.rareorientalbooks.com/searchadv/>
> On the command line using the exact code in the views.py everything
> returns instantly.
>
> When accessing the same code via url browser access all searches take
> a minimum of 10 seconds whether it returning 10 or 500 titles.
>
> __If via the command line the queries return instantly
>
> * am I right in thinking the bottleneck is somewhere else in the
>  process?
>
> * where might that bottleneck be and how can i streamline it?
>
> Any ideas appreciated.
>

When you evaluate a query on the command line, what you do not get
exactly the same behaviour as in a view context, an automatic limit of
maximum 21 items is added to the query. Many SQL queries can be
considerably faster with a limit statement on them without.

If you evaluate the queryset as a list, then you will get the
behaviour you get in your view, and the query should take much longer
to complete. As an example:

>>> from django.db import connection
>>> connection.queries=
>>> User.objects.filter()

>>> print connection.queries
SELECT `auth_user`.`id`, `auth_user`.`username`,
`auth_user`.`first_name`, `auth_user`.`last_name`,
`auth_user`.`email`, `auth_user`.`password`, `auth_user`.`is_staff`,
`auth_user`.`is_active`, `auth_user`.`is_superuser`,
`auth_user`.`last_login`, `auth_user`.`date_joined` FROM `auth_user`
LIMIT 21
>>> list(User.objects.filter())

>>> print connection.queries
SELECT `auth_user`.`id`, `auth_user`.`username`,
`auth_user`.`first_name`, `auth_user`.`last_name`,
`auth_user`.`email`, `auth_user`.`password`, `auth_user`.`is_staff`,
`auth_user`.`is_active`, `auth_user`.`is_superuser`,
`auth_user`.`last_login`, `auth_user`.`date_joined` FROM `auth_user`


Cheers

Tom

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » query fast on command line - slow via url [RSS Feed]

Board footer

Moderator control

Enjoy the 17th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support