snower / TorMySQL

The highest performance asynchronous MySQL driver by PyMySQL
MIT License
308 stars 63 forks source link

pymysql.err.OperationalError with tornado 4.5 #17

Closed zhang0ZGC closed 7 years ago

zhang0ZGC commented 7 years ago

在tornado 4.5上使用TorMysql会报pymysql.err.OperationalError错误。我试了一下example pool的例子:

appledeAir:test apple$ python3 tornado4.5.py
ERROR:tornado.application:Exception in callback None
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tornado/ioloop.py", line 888, in start
    handler_func(fd_obj, events)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tornado/stack_context.py", line 277, in null_wrapper
    return fn(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tormysql/connections.py", line 41, in _handle_events
    self._handle_read()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tormysql/connections.py", line 71, in _handle_read
    self._read_buffer.append(chunk)
TypeError: an integer is required
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tormysql/connections.py", line 260, in connect
    self._get_server_information()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pymysql/connections.py", line 1245, in _get_server_information
    packet = self._read_packet()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pymysql/connections.py", line 987, in _read_packet
    packet_header = self._read_bytes(4)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tormysql/connections.py", line 334, in _read_bytes
    return main.switch()
pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query (Stream is closed)')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tornado4.5.py", line 28, in <module>
    ioloop.run_sync(test)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tornado/ioloop.py", line 458, in run_sync
    return future_cell[0].result()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tornado/concurrent.py", line 238, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 4, in raise_exc_info
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tornado/gen.py", line 1063, in run
    yielded = self.gen.throw(*exc_info)
  File "tornado4.5.py", line 19, in test
    with (yield pool.Connection()) as conn:
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tornado/gen.py", line 1055, in run
    value = future.result()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tornado/concurrent.py", line 238, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 4, in raise_exc_info
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tormysql/util.py", line 14, in finish
    result = fun(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tormysql/connections.py", line 284, in connect
    raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 127.0.0.1:3306 (OperationalError(2013, 'Lost connection to MySQL server during query (Stream is closed)'))")
snower commented 7 years ago

fixed, thanks.

shi-cong commented 6 years ago

请问你是怎么做的?我的tornado程序和tormysql无法相连

zhang0ZGC commented 6 years ago

@shi-cong Readme里面就是例子呀

shi-cong commented 6 years ago

@zhang0ZGC tornado本身有一个ioloop对象,而tormysql也有一个,如果不启动tornado只启动tormysql就没有问题;如果两个同时启动,就是说由tornado来启动tormysql,这就程序就会报错,"ioloop is already running"

zhang0ZGC commented 6 years ago

@shi-cong 额。。4.5还不能用吗?我当时发现4.5不能用然后就切回4.4了--....

shi-cong commented 6 years ago

@zhang0ZGC
image

shi-cong commented 6 years ago

@zhang0ZGC 你用tormysql后端crud效率高吗?我现在用的是同步的自己写的连接池.

zhang0ZGC commented 6 years ago

@shi-cong 刚刚特地去试了一下以前写的代码,在4.5上面还是没跑通。。不知道是不是因为我没升级tormysql的原因,我的是0.3.2,现在是0.3.5;还是我代码原因

zhang0ZGC commented 6 years ago

@shi-cong baidushurufa_2017-12-4_12-22-1

baidushurufa_2017-12-4_12-23-35

在我电脑上,单线程跑server,用ab测试去读获取数据,差不多是这个样子,数据库是在阿里云,如果是内网数据应该能好不少

shi-cong commented 6 years ago

@zhang0ZGC 你阿里云的机器是多少的配置,每秒完成的次数怎么那么多,我每秒的吞吐量最多只有85

shi-cong commented 6 years ago

@zhang0ZGC 你的连接池设置的好大啊,都有100

shi-cong commented 6 years ago

@zhang0ZGC 请问你的tornado4.5和tormysql一起每有报错吗?

zhang0ZGC commented 6 years ago

@shi-cong centos7 1核1GB的,获取你里面还有什么操作阻塞了一下没准呢;感觉100还好吧。。;4.5的和tormysql会报错。。。不知道是不是我tormysql没升级的原因