tornado mysql 变量_如何在Tornado中为一个具有高度可扩展基础设施的应用程序进行MySQL数据库调用,从而产生大量的数据库查询?...

那么,对于一个高性能的应用程序,在Tornado中进行数据库调用,哪一种方法更好?该应用程序具有高度可扩展的基础结构,可以进行大量的数据库查询?在

方法1:因此,我遇到过一些异步数据库驱动程序/客户机,如TorMySQL、Tornado Mysql、asynctorndb等,它们可以执行异步数据库调用。在

方法2:使用通用和通用的MySQLdb或mysqlclient(by PyMySQL)驱动程序,调用数据库以分离后端服务,并使用nginx进行负载平衡。

就像他们在其中一个小组里提到的,Friendfeed最初的做法一样

原著作者之一布雷特·泰勒写道:groups.google.com/group/python-tornado/browse_thread/thread/9a08f5f08cdab108

We experimented with different async DB approaches, but settled on

synchronous at FriendFeed because generally if our DB queries were

backlogging our requests, our backends couldn't scale to the load

anyway. Things that were slow enough were abstracted to separate

backend services which we fetched asynchronously via the async HTTP

module.

方法2的其他支持链接可以更好地理解我要说的内容:

方法3:通过使用线程和IOLoop并使用通用同步库。在

支持例子链接来解释我的意思Do it synchronously and block the IOLoop. This is most appropriate for

things like memcache and database queries that are under your control

and should always be fast. If it's not fast, make it fast by adding

the appropriate indexes to the database, etc.另一种示例方法:

对于同步数据库(mysqldb),我们可以

执行器=线程池执行器(4)

结果=产量执行人.提交(mysqldb_操作)

方法4:只需使用MySQLdb等同步驱动程序,并使用nginx启动足够的Tornado实例和负载平衡,使应用程序在更广泛的层面上保持异步,一些调用被阻止,但其他请求通过大量Tornado实例受益于异步性质。在

“解释”:

有关详细信息,请访问此链接-www.jjinux.com/2009/12/python-asynchronous-networking-api-and.html,上面写着:They allow MySQL queries to block the entire process. However, they

compensate in two ways. They lean heavily on their asynchronous web

client wherever possible. They also make use of multiple Python

processes. Hence, if you're handling 500 simultaneous request, you

might use nginx to split them among 10 different Tornado Web

processes. Each process is handling 50 simultaneous requests. If one

of those requests needs to make a call to the database, only 50

(instead of 500) requests are blocked.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值