开发者

pymysql vs. pyodbc - pymysql is sloooooooooooow

I've been having an issue trying to get my simple data analysis program that uses MySQL to work correctly.

On my Windows 7 computer I use pyodbc and the program runs fine, using pyodbc to connect to MySQL. On Snow Leopard, couldn't get pyodbc to install correctly so I'm using pymysql instead...

After finally getting pymysql to work, it runs super slow...

Just did a test - ran my program on Mac OS Snow Leopard, through cProfile, and got:

26849449 function calls (26844794 primitive calls) in 103.196 CPU seconds

... (The only method with more than a few seconds total time is recv)

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
   176088   76.960    0.000   76.960    0.000 {method 'recv' of '_socket.socket' objects}

...

Running same program on a Windows 7 virtual machine with pyodbc (connected to same MySQL db running from host computer):

Executing Muncher as the main program. ncalls tottime percall cumtime percall filename:lineno(function) 512873 function calls (508218 primitive calls) in 6.849 CPU seconds

Does anyone know what could be causing this? Looks like most of that time was spent on _socket.socket's 'recv' method, which according to Google is something that receives data. Is that method broken or something? Seems ridicu开发者_JS百科lous it would take almost 15x times as long.

And I guess a better question might be...what's the best way to connect to MySQL on Mac OS? I have tried pyodbc as well as MySQLdb so far with no luck getting them to install.


First you should make sure you are actually comparing the same things.

sockets 'recv' method means that the program is waiting for something, so if your program actually does the same thing on both the W7 machine and the Mac, that could mean that the network latency is different. (For example if your Mac is using Wireless network and the Windows 7 machine uses wired network)

To rule out that you could try comparing pyodbc and pymysql on the Windows machine. Do you still get the same difference in speed then?

Typically, if most of the time is spent in 'recv', the problem is outside your application (and outside pyodbc/pymysql).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜