Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyodbc is very slow on my machine but not on other machines

I am accessing a db2 (9.7) server running on the same network as my computer using python 2.7 and pyodbc 3.0.6.

The following is a very stripped down example of something similar to what i am trying to do.

import pyodbc as db

def dbcur(connectname):
    con = db.connect(connectname)
    cur = con.cursor()
    return cur,con


def main():

    print 'a'
    cur,con = dbcur('DSN=MYODBCCON')
    print 'b'


    # X.name is a short varchar
    qry = """
        select
        X.name as N
        from schema.table as X
        """

    print 'c'

    cur.execute(qry)

    print 'd'

    c = 0
    for row in cur:
        c+=1
        if not c%100:
            print c, row

    return

if __name__ == '__main__': main()

This code runs very slow on my windows 8 computer (100 rows in 10 seconds). However, on my colleagues computer with windows 7 this is lightning fast. His computer is simmilarly specced to mine, and he has the same versions of pyodbc and python, so i do not belive this to be an issue.

The problem persists when i use both IBM DB2 ODBC DRIVER and IBM DATA SERVER DRIVER FOR ODBC.

Any suggsetions as to why this is so slow?

I am aware of things such as cur.fetchmany(), but i still expect this code to be much faster without using this.

UPDATE:

It turns out that ODBC was slow because tracing was turned on. I disabled tracing and the performance was back to what I expected it to be. (Tracing can be found under ODBC Data Sources in Windows 7 and 8.)

like image 950
inconvergent Avatar asked Jan 03 '13 09:01

inconvergent


People also ask

What is the alternative to Pyodbc?

Top Alternatives to pyodbcPython wrapper for the Cloudflare v4 API. Powerful data structures for data analysis, time series, and statistics. The modular source code checker: pep8, pyflakes and co. Python 2 and 3 compatibility utilities.

What is Pyodbc driver?

pyodbc is an open source Python module that provides access to ODBC databases. pyodbc implements the Python DB API 2.0 specification. The Python DB API defines a database-neutral interface to data stored in relational databases.


1 Answers

It turns out that ODBC was slow because tracing was turned on. I disabled tracing and the performance was back to what I expected it to be. (Tracing can be found under ODBC Data Sources in Windows 7 and 8.)

like image 188
Gord Thompson Avatar answered Sep 27 '22 21:09

Gord Thompson