任何建议在Python3使用的龙卷风非阻塞MySQL的API? [英] Any suggestion for using non-blocking MySQL api on Tornado in Python3?

查看:749
本文介绍了任何建议在Python3使用的龙卷风非阻塞MySQL的API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望异步SQL数据库opertion龙卷风支持下,经过我阅读源$ C ​​$ C,

i was hoping tornado support for asynchronous sql database opertion ,after i read the source code,

http://www.tornadoweb.org/documentation/_modules/tornado/database.html#Connection

感叹,他们封锁version.here的一些选择。

sigh,they are blocking version.here's some choice .

A计划:找到一套类似的API,除了他们使用的回调返回reuslt.sorry我没有找到一个例子显示这是他们的API可以处理MySQLdb的模块的非阻塞操作MySQL

Plan A: find a set of api similar to mysqldb module except they use callback to return the reuslt.sorry i didn't find one that show examples that's their api can handle non-blocking mysql operation

B计划:使用块版本。我听到龙卷风的作者建议开发者使用块版本,和极其优化您的SQL查询缩短间歇时间

Plan B: use the block version .i heard the writer of tornado suggest developers use block version,and extremely optimize your sql query for shorten the blocking period.

在我的情况:服务器需要处理收到高峰时段每秒2K的请求,其中大部分需要从数据库查询和更新,建议每一个操作需要10毫秒,10毫秒* 2K超过20岁,这将是一个nightmare.in多线程编程,至少我可以让更多的连接更多的平均响应时间。

in my case: the server need to handle receive 2k request per second in peak hour and most of them need query and update from database ,suggest every operation take 10ms,10ms*2k over 20s ,that would be a nightmare.in multi thread programming at least i can make more connections for more average response time.

也许我在这里错过了一些点,我对后端发展。但是我仍然认为使用阻塞IO的API的同时框架是非阻塞一吸的想法没有太多经验。

maybe i missed some point here,i have not much experience for backend development.however i still think using blocking io api is a suck idea while the framework is non-blocking.

C计划:删除MySQL使用MongoDB中,我听到的MongoDB有一个异步的Python实现API asyncmongo命名,但林不知道学习的MongoDB,并采取MongoDB的作为我们企业选择的风险

Plan C: drop MySql use mongoDB, i heard mongoDB has an asynchronous Python implement api named asyncmongo, but im not sure the risk to learn mongoDB and take mongoDB as our business choice

推荐答案

另一种选择是设置多处理(的http://docs.python.org/library/multiprocessing.html?highlight=multiprocessing#multiprocessing ),并使用的过程,作为一个队列管理器为DB的。

Another option is to setup Multiprocessing ( http://docs.python.org/library/multiprocessing.html?highlight=multiprocessing#multiprocessing ) and use on of the processes as a Queue manager for the DB.

高效的SQL查询相结合多重,你应该尽量减少你的整体影响。阻塞调用将只在DB处理队列管理器进程来完成和应用程序的其它部分可以不被阻止运行。唯一受影响的人是试图运行在同一时间一个数据库查询的人。

Combine Multiprocessing with efficient SQL queries and you should minimize your overall impact. The blocking calls will only be done on the DB Processing Queue Manager process and the rest of the application can run without being blocked. The only people affected are the ones attempting to run a DB query at the same time.

这篇关于任何建议在Python3使用的龙卷风非阻塞MySQL的API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆