473,383 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

postgresql modules and performance

Hello,

I started to write my PostgreSQL layer. I tried pyPgSQL and PyGreSQL. I
made a *very minimal* performance test and comparsion with the same
thing in php. Table "movie" has 129 record and many fields.

I found PyGreSQL / DB-API / fetchall horrible slow (32 sec in my test).
PHP did 13 secs and it gave the result in associative array. Maybe I did
something bad.

pyPgSQL / DB-API raised a futurewarning and didn't worked.

pyPgSQL / libpg worked well. I can create php-like dictionary result in
14 secs.

Here is the code. It's only a test...

Mage

------ test.py --------
import mpypg
import datetime

print 'This is a python postgesql module'

db = mpypg.mpypgdb('dbname=test host=localhost')

def test():
res = db.query('select * from movie')
#print res['fields']
#print res['rows']
#pass

def test2():
res = db.query('select * from movie')
#print res['fields']
#print len(res['rows'])
#print res['rows']
print len(res)
print res[1]

start = datetime.datetime.now()

for i in range(100):
test()
#pass

end = datetime.datetime.now()

print end - start

test2()

------ mpypg.py --------
from pyPgSQL import libpq
from pyPgSQL import PgSQL
import sys
import pgdb

mpypg_connect_error_message = 'Could not connect to the database'
mpypg_query_error_message = 'Could not run the query'

class mpypgdb:
'my database class'
def __init__(self,str):
try:
self.database = libpq.PQconnectdb(str)
except:
mpypg_error_msg(mpypg_connect_error_message)

def query(self,query):
try:
res = self.database.query(query)
fields = tuple([res.fname(i) for i in range(res.nfields)])
rows = []

'''
for name in fields:
rows[name] = []
for i in range(res.ntuples):
for j in range(len(fields)):
rows[fields[j]].append(res.getvalue(i,j))
'''
'''
for j in range(len(fields)):
rows[fields[j]] = tuple([res.getvalue(i,j) for i in
range(res.ntuples)])
'''

for i in range(res.ntuples):
rows.append(dict([(fields[j], res.getvalue(i,j)) for j
in range(len(fields))]))

res.clear()
result = {'fields': fields, 'rows': rows}
return result;
except:
mpypg_error_msg(mpypg_query_error_message)
class mpgdb:
'my database class'
def __init__(self,str):
try:
self.database = pgdb.connect(database='test')
except:
mpypg_error_msg(mpypg_connect_error_message)

def query(self,query):
try:
cursor = self.database.cursor()
res = cursor.execute(query)

#result = {'fields': fields, 'rows': cursor.fetchall()}
result = [cursor.fetchone() for i in range(cursor.rowcount)]

#result = cursor.fetchall()
return result;
except:
mpypg_error_msg(mpypg_query_error_message)

def mpypg_error_msg(message):
'Database error handler'
sys.exit(message)
Jul 19 '05 #1
2 1918
Mage wrote:
Hello,

I started to write my PostgreSQL layer. I tried pyPgSQL and PyGreSQL. I
made a *very minimal* performance test and comparsion with the same
thing in php. Table "movie" has 129 record and many fields.

I found PyGreSQL / DB-API / fetchall horrible slow (32 sec in my test).
PHP did 13 secs and it gave the result in associative array. Maybe I did
something bad.


Have you tried psycopg?

Reinhold
Jul 19 '05 #2
Reinhold Birkenfeld wrote:

Have you tried psycopg?

Thank you. It did the fetchall() in 11 secs and 13 secs with dictionary
creating. It's the fastest so far.

Mage

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Rada Chirkova | last post by:
Hi, at NC State University, my students and I are working on a project called "self-organizing databases," please see description below. I would like to use an open-source database system for...
29
by: Mainlander | last post by:
An ISP I belong to uses Majordomo for their mailing list system. I'd like to encourage them to move to a system that uses a database, preferably psql which they already run on their server....
33
by: Joshua D. Drake | last post by:
Hello, I think the below just about says it all: http://www.commandprompt.com/images/mammoth_versus_dolphin_500.jpg Sincerely, Joshua Drake
4
by: Ryan Mack | last post by:
First, I want to confirm my understanding that the "without fee" clause in the PostgreSQL license means that a party may not sell PostgreSQL or works derived from the PostgreSQL source code. ...
10
by: Josué Maldonado | last post by:
Hello list, I have 7.3.4 on RH 8, server hardware is a dual processor Intel Xeon 2.4 Ghz, 2G RAM. I was reading about tunning and would like to get some help from you, I changed some of the...
0
by: Chris Travers | last post by:
Hi all; This seems at least somewhat on-topic here, so at the risk of seeming shamelessly self-promoting, I figured I would ask. I am the main developer of an open source CRM suite...
9
by: Andy B | last post by:
If I bought one of these boxes/OS combos as a postgresql database server, would postgresql be able to make the best use of it with a huge (e.g. 40GB) database? Box: HP ProLiant DL585, with ...
17
by: Jim Strickland | last post by:
We currently are running a data intensive web service on a Mac using 4D. The developers of our site are looking at converting this web service to PostgreSQL. We will have a backup of our three...
0
by: Patvs | last post by:
I use poker software (HoldemManager) to keep track of the statistics (and show nice graphs) of millions of poker hand histories. This software (also PokerTracker 3) imports all the poker hands in...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.