From: jose <jo...@cy...> - 2005-02-24 07:15:47
|
Dear webware community, I'm perplexed, I have been playing around with XMLRPC as a way to = connect to a database and deliver content. Please see the code below:(one is a XMLRPCServlet and the second is a regular servlet) The is issue is that the XMLRPC servlet is about 8 times slower then the regular servlet. This doesn't make any sense to me. If I kill the = sleep method, and not close the db connection, then it is really fast, but = somehow that does not feel right. I don't seem to be taking much of a hit by getting a new connection every time with the regular servlet, so why = should it be so with the xmlrpc servlet? Am I doing something fundamentally = wrong in the xmlrpc? Any help would be great, and thanks in advance Jose =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D server.py: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D from WebKit.XMLRPCServlet import XMLRPCServlet as XS import psycopg as pg class server(XS): =20 def __init__(self): XS.__init__(self) self.db =3D None =20 def awake(self, trans): XS.awake(self, trans) self.db =3D pg.connect(user =3D 'postgres', = database=3D'phonebook') def sleep(self, trans): XS.sleep(self, trans) if self.db: self.db.close() def cur(self): return self.db.cursor() =20 def exposedMethods(self): return [ 'echo', 'listPeople' ] =20 def echo(self, what=3D'you need to enter something'): return what =20 def listPeople(self): sql =3D ''' select fname, lname from people ''' cur =3D self.cur() cur.execute(sql) people =3D cur.fetchall() return people =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D test.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D from WebKit.Page import Page import psycopg as pg class test(Page): =20 def __init__(self): Page.__init__(self) self.db =3D None =20 def awake(self, trans): Page.awake(self, trans) self.db =3D pg.connect(user =3D 'postgres', = database=3D'phonebook') =20 def sleep(self, trans): Page.sleep(self, trans) if self.db: self.db.close() def cur(self): return self.db.cursor() =20 def writeContent(self): sql =3D ''' select fname, lname from people ''' cur =3D self.cur() cur.execute(sql) people =3D cur.dictfetchall() self.write(people) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D =3D=3D=3D=3D=3D=3D=3D=3D=3D |