Thread: [SQLObject] Connection instance ignored ?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Stef T. <st...@um...> - 2009-02-08 23:16:05
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hey Oleg, Everyone, So, I have currently subclassed SQLObject to MySQLObject, as I am trying to basically do one connection to a slave, another to a master. Hopefully, that makes sense so far. In my class I have subclassed get and select to use an existing connection. Eg; > @classmethod > def select(self, clause=None, **kwargs): > ''' All selects should go through the slave connection ''' > global slaveConnection > if slaveConnection: > kwargs['connection']=slaveConnection > return super(CompassObject, self).select(clause, **kwargs) and the same for 'get' as well.. the curious thing is, I am still seeing about 190 connects/disconnects on the postgreSQL side. Now, since a connection is costly (believe me, it is ;), how can I get these down to (in theory) 1. I know that may seem unrealistic, but still, there shouldn't be 190 connects/disconnects. This -is- a single threaded environment, I do print out during the select in main.py and the connection -is- the same (same memory ref), I don't use selectBy either. I am kind of scratching my head here. Could it be that the joins in the class don't honor the classes connection ? (would be kind of strange and not at all what I would expect.. nor do I see that the code is creating a new connection). Any thoughts/ideas gratefully welcomed ;) Regards Stef -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFJj2exANG7uQ+9D9URApPRAKCFyMWs7eM4DDB1wYSQsGcRbbvoZgCdEPOQ Ru1Xc6xHVkceP0Hd21eLIMM= =WPA5 -----END PGP SIGNATURE----- |
From: Oleg B. <ph...@ph...> - 2009-02-09 14:44:14
|
On Sun, Feb 08, 2009 at 06:16:01PM -0500, Stef Telford wrote: > seeing about 190 connects/disconnects on the postgreSQL side. Now, > since a connection is costly (believe me, it is ;), how can I get > these down to (in theory) 1. I know that may seem unrealistic, but > still, there shouldn't be 190 connects/disconnects. > > This -is- a single threaded environment, I do print out during the > select in main.py and the connection -is- the same (same memory ref), > I don't use selectBy either. > > I am kind of scratching my head here. Could it be that the joins > in the class don't honor the classes connection? Whatever joins use - they use SQLObject's DBConnection objects that are high-level wrapper around Python DB API connections. Every DBConnection instance maintains a pool of opened DB API connections and opens a new DB API connection only if the pool is empty (the first query or all DB API connections are busy in other threads). Hence there shouldn't be connects/disconnects, especially in a single-threaded program. The only way to make implicit connects/disconnects is to disable connection pooling. You haven't done that, have you? connection._pool is not None? Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Stef T. <st...@um...> - 2009-02-09 17:35:49
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Oleg Broytmann wrote: > On Sun, Feb 08, 2009 at 06:16:01PM -0500, Stef Telford wrote: >> seeing about 190 connects/disconnects on the postgreSQL side. >> Now, since a connection is costly (believe me, it is ;), how can >> I get these down to (in theory) 1. I know that may seem >> unrealistic, but still, there shouldn't be 190 >> connects/disconnects. >> >> This -is- a single threaded environment, I do print out during >> the select in main.py and the connection -is- the same (same >> memory ref), I don't use selectBy either. >> >> I am kind of scratching my head here. Could it be that the joins >> in the class don't honor the classes connection? > > Whatever joins use - they use SQLObject's DBConnection objects that > are high-level wrapper around Python DB API connections. Every > DBConnection instance maintains a pool of opened DB API connections > and opens a new DB API connection only if the pool is empty (the > first query or all DB API connections are busy in other threads). > Hence there shouldn't be connects/disconnects, especially in a > single-threaded program. The only way to make implicit > connects/disconnects is to disable connection pooling. You haven't > done that, have you? connection._pool is not None? > > Oleg. Hello again Oleg, Actually, I -have- done this.. both with and without it seems to make no difference, I still get a tonne of connections :(. I have tried doing; > slaveConnection = getConnectionURI() slaveConnection._pool = None I have also tried specifically changing dbconnection.py self._pool = [] to self._pool = None .. no joy there either :( If I am doing something wrong, feel free to smack me upside the head and tell me ;) I am inheriting inside myclass from SQLObject, I am passing in the single connection via the overloaded get, _init and select/selectBy (not that I use selectBy but.. yes) Regards Stef -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFJkGltANG7uQ+9D9URAvFwAKCEHbonXnqgNSqCKrFW0RaUtFKHqACff+sZ b3Ud/xwYc86imYtDRNXwWFE= =Cagq -----END PGP SIGNATURE----- |
From: Oleg B. <ph...@ph...> - 2009-02-09 17:50:38
|
On Mon, Feb 09, 2009 at 12:35:47PM -0500, Stef Telford wrote: > slaveConnection._pool = None It must be exactly opposite: slaveConnection._pool = [] Well, an empty list is the default value, so by default SQLObject should not disconnect but use a low-level connection from the pool. Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Stef T. <st...@um...> - 2009-02-09 18:04:03
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Oleg Broytmann wrote: > Oh, BTW, do you use transactions? And call transaction.commit()? > > Oleg. Hello again Oleg, Nope, well, I mean I -plan- to, but currently, the connection is being made at the start of the page and then I go through get'ting and init'ing objects. There isn't even any saving done, this is purely rendering content stage. Also, if I print out the memory location, it's always the same throughout the entire page rendering (eg; 8f000c). I don't see why/how wrapping everything in a transaction would change things.. but then.. that's jst me :) Regards Stef -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFJkHAFANG7uQ+9D9URAp9RAJ4qckdiDz4qYzYcPgxvS38AkNGPLQCfW9B2 kS+qqCMw5evqf+rDGUdvGhM= =9x/A -----END PGP SIGNATURE----- |
From: Oleg B. <ph...@ph...> - 2009-02-09 18:08:51
|
On Mon, Feb 09, 2009 at 01:03:53PM -0500, Stef Telford wrote: > Oleg Broytmann wrote: > > Oh, BTW, do you use transactions? And call transaction.commit()? > > > I don't see why/how wrapping everything in a transaction would > change things.. but then.. that's jst me :) Transaction object in SQLObject closes the connection on commit. To prevent it to do so call transaction.commit(close=False) But you don't use transactions, so I am out of ideas. Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Oleg B. <ph...@ph...> - 2009-02-09 17:57:33
|
Oh, BTW, do you use transactions? And call transaction.commit()? Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |