0

我一直在尝试让使用 MySQL 的简单数据分析程序正常工作时遇到问题。

在我的 Windows 7 计算机上,我使用 pyodbc 并且程序运行良好,使用 pyodbc 连接到 MySQL。在雪豹上,无法正确安装 pyodbc,所以我改用 pymysql ......

在终于让 pymysql 工作之后,它运行起来超级慢......

刚刚做了一个测试——通过 cProfile 在 Mac OS Snow Leopard 上运行我的程序,得到:

在 103.196 CPU 秒内进行 26849449 次函数调用(26844794 次原始调用)

...(总时间超过几秒的唯一方法是recv)

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

...

在带有 pyodbc 的 Windows 7 虚拟机上运行相同的程序(连接到从主机运行的相同 MySQL 数据库):

执行 Muncher 作为主程序。ncalls tottime percall cumtime percall filename:lineno(function) 512873 个函数调用(508218 个原始调用)在 6.849 CPU 秒内

有谁知道这可能是什么原因造成的?看起来大部分时间都花在了 _socket.socket 的“recv”方法上,根据谷歌的说法,这是接收数据的东西。这种方法是坏的还是什么?看起来很荒谬,它需要将近 15 倍的时间。

我想一个更好的问题可能是......在 Mac OS 上连接 MySQL 的最佳方式是什么?到目前为止,我已经尝试过 pyodbc 和 MySQLdb,但没有成功安装它们。

4

1 回答 1

0

首先,您应该确保您实际上是在比较相同的事物。

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).

于 2011-06-09T13:51:42.333 回答