[storm] Storm and MySQL in WSGI environment - MySQL server run away
Steve Kieu
msh.computing at gmail.com
Thu Jan 27 13:32:59 UTC 2011
Hi everyone,
I have read some where that do sql test like this causing more load. I tried
to make a new store like below
class MyStore(Store):
def get(self,cls,key):
retries = 0
while retries < DB_CON_RETRY:
try:
return super(MyStore, self).get(cls,key)
break
except Exception, e:
retries += 1
print >> sys.stderr, "Get Exception: %s Retries: %s" % (e, retries)
self.get_database().connect()
def find(self, cls_spec, *args, **kwargs):
retries = 0
while retries < DB_CON_RETRY:
try:
return super(MyStore, self).find(cls_spec, *args, **kwargs)
break
except Exception, e:
retries += 1
print >> sys.stderr, "Find Exception: %s Retries: %s" % (e, retries)
self.get_database().connect()
and then create my store as MyStore. Which works pretty well so far. (In my
modem I use the get and find method most). This way avoids me to wrap all
over places and still reuse the existing connection.
Not quiet sure anything wrong with that approach though. Any comment please?
Cheers.
On Thu, Jan 27, 2011 at 10:00 PM, Jamu Kakar <jkakar at kakar.ca> wrote:
> Hi Steve,
>
> On Thu, Jan 27, 2011 at 1:01 AM, Steve Kieu <msh.computing at gmail.com>
> wrote:
> > Is there any method that allow me to check the connection status from the
> > Store object? I think of a way like do a store.execute("some lowest cost
> sql
> > here") and catch the exception then if has then recreate the store object
> > but it does look clean to me.
>
> Nope, the only way to test the connection is to use it. You can run a
> simple query like:
>
> store.execute("SELECT * FROM $table WHERE 1=2")
>
> Thanks,
> J.
>
--
Steve Kieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/storm/attachments/20110127/ec933de2/attachment.html>
More information about the storm
mailing list