performance issue with psycopg

From: Sushant Sinha <sushant354(at)gmail(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: performance issue with psycopg
Date: 2011-12-12 16:41:22
Message-ID: 1323708082.2132.6.camel@dragflick
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

I am using psycopg 2.4.2 and facing performance issue. An explain
analyze of the query on the database shows 0.75secs. But when used
through the psycopg layer I am seeing 1.5 secs. Any idea why the extra
cost and how to optimize it?

from psycopg2.extras import DictCursor
from psycopg2.extensions import UNICODE, UNICODEARRAY
psycopg2.extensions.register_type(UNICODE)
psycopg2.extensions.register_type(UNICODEARRAY)

cursor = dbCnx.cursor(cursor_factory=DictCursor)
cursor.execute(query, params)
results = cursor.fetchall()

Here is the profiling for extras.py:

35 0.896 0.026 0.896 0.026 extras.py:118(execute)
35 0.296 0.008 0.778 0.022 extras.py:80(fetchall)
276433 0.270 0.000 0.314 0.000 extras.py:148(__setitem__)
1 0.001 0.001 0.129 0.129 extras.py:5(<module>)
25153 0.112 0.000 0.116 0.000 extras.py:139(__init__)
17176 0.018 0.000 0.028 0.000 extras.py:143(__getitem__)
1 0.000 0.000 0.002 0.002
extras.py:566(HstoreAdapter)
1 0.000 0.000 0.002 0.002
extras.py:762(CompositeCaster)
4001 0.001 0.000 0.001 0.000 extras.py:162(has_key)
35 0.000 0.000 0.000 0.000
extras.py:128(_build_index)
35 0.000 0.000 0.000 0.000 extras.py:113(__init__)
35 0.000 0.000 0.000 0.000 extras.py:50(__init__)
46 0.000 0.000 0.000 0.000 extras.py:914(<lambda>)
1 0.000 0.000 0.000 0.000
extras.py:254(NamedTupleCursor)
10 0.000 0.000 0.000 0.000 extras.py:156(keys)
1 0.000 0.000 0.000 0.000 extras.py:134(DictRow)
1 0.000 0.000 0.000 0.000
extras.py:373(LoggingCursor)
1 0.000 0.000 0.000 0.000
extras.py:47(DictCursorBase)
1 0.000 0.000 0.000 0.000
extras.py:433(UUID_adapter)
1 0.000 0.000 0.000 0.000
extras.py:389(MinTimeLoggingConnection)
1 0.000 0.000 0.000 0.000 extras.py:110(DictCursor)
1 0.000 0.000 0.000 0.000 extras.py:493(Inet)
1 0.000 0.000 0.000 0.000 extras.py:233(RealDictRow)
1 0.000 0.000 0.000 0.000
extras.py:203(RealDictCursor)
1 0.000 0.000 0.000 0.000
extras.py:326(LoggingConnection)
1 0.000 0.000 0.000 0.000
extras.py:248(NamedTupleConnection)
1 0.000 0.000 0.000 0.000
extras.py:195(RealDictConnection)
1 0.000 0.000 0.000 0.000
extras.py:416(MinTimeLoggingCursor)
1 0.000 0.000 0.000 0.000
extras.py:102(DictConnection)

Responses

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2011-12-12 17:20:01 Re: performance issue with psycopg
Previous Message Federico Di Gregorio 2011-12-12 09:18:01 Re: RELEASE: psycopg 2.4.3