Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#6 The speed of SQLObject is slower on the time

closed
Oleg Broytman
None
5
2011-07-20
2011-07-14
Rosa Robles
No

I had a test of a SQLObject and I had found a strange behaviour of SQLObject. On the time, the respond time is lesser.

Here, I put a example of test code :

from sqlobject.sqlbuilder import *
connection = connectionForURI('postgresql://test:test@localhost/test_sql_object')
sqlhub.processConnection = connection

class Person(SQLObject):
firstName = StringCol()
middleInitial = StringCol(length=1, default=None)
lastName = StringCol()

iteration = 0
while 1:
start = datetime.now()
person_list = []
for key in range(1000):
person = Person.selectBy(firstName='name%s%s' % (iteration,key))[0]
person_list.append(person)

for person in person_list:
person.expire()
del person
del person_list
sqlhub.processConnection.cache.clear()

end = datetime.now()

print "TIME ",iteration,':' , end - start
iteration = iteration + 1

In the result I can check that in each iteration the time is bigger. The first iteration has time of 1.37s, then the time increases and the 19 iteration has time of 5.83 s!

TIME 0 : 0:00:01.376392
TIME 1 : 0:00:01.663250
TIME 2 : 0:00:01.978639
TIME 3 : 0:00:02.319939
TIME 4 : 0:00:02.618213
TIME 5 : 0:00:02.723846
TIME 6 : 0:00:02.584007
TIME 7 : 0:00:02.868877
TIME 8 : 0:00:03.051937
TIME 9 : 0:00:03.389757
TIME 10 : 0:00:03.503036
TIME 11 : 0:00:03.563154
TIME 12 : 0:00:04.191539
TIME 13 : 0:00:04.274464
TIME 14 : 0:00:04.813206
TIME 15 : 0:00:04.677002
TIME 16 : 0:00:04.995708
TIME 17 : 0:00:05.126811
TIME 18 : 0:00:05.571279
TIME 19 : 0:00:05.832840

Why is happend this?
Thanks in advance for your attention.
Cheers Rosa

Discussion

<< < 1 2 (Page 2 of 2)
  • Rosa Robles
    Rosa Robles
    2011-07-20

    I didn't know profiler tool, thanks very much, Oleg!!
    I'm agree with you source of problem, in postgres it spends almost all time in
    method 'execute' of 'psycopg2._psycopg.cursor' objects
    however in mysql it spends almost all time in method 'query' of '_mysql.connection' objects.
    The problem is in the use of database, a lots of operations to database spends a lots time.
    Thanks very much, your help has been very useful to me.

     
  • Oleg Broytman
    Oleg Broytman
    2011-07-20

    • status: open --> closed
     
  • Oleg Broytman
    Oleg Broytman
    2011-07-20

    MySQL is different, AFAIU, because it has only client-side cursors instead of server-side; i.e. MySQLdb fetches all results even if SQLObject asks to fetch one row.

     
<< < 1 2 (Page 2 of 2)