- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
那么,对于具有高度可扩展基础设施并进行大量数据库查询的高性能应用程序,在 Tornado 中进行数据库调用的最佳方法是什么?
方法 1:所以我遇到了异步数据库驱动程序/客户端,如 TorMySQL、Tornado-Mysql、asynctorndb 等,它们可以执行异步数据库调用。
方法二:使用通用的MySQLdb或mysqlclient(by PyMySQL)驱动程序,进行数据库调用,分离后端服务,并用nginx对调用进行负载均衡。类似于他们在其中一个小组中提到的原始 Friendfeed 人员所做的事情,
原作者之一布雷特·泰勒 (Bret Taylor) 写道:
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),我们可以
执行器 = ThreadPoolExecutor(4)
result = yield executor.submit(mysqldb_operation)
方法 4:只需使用 MySQLdb 等同步驱动程序并启动足够的 Tornado 实例并使用 nginx 进行负载平衡,应用程序在更广泛的层面上保持异步,一些调用被阻止,但其他请求有益于异步性质通过大量 Tornado 实例。
“解释”:
有关详细信息,请访问此链接 - www.jjinux.com/2009/12/python-asynchronous-networking-apis-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.
最佳答案
FriendFeed 使用了您所谓的“方法 4”:没有单独的后端服务;该进程刚刚在数据库调用期间被阻止。
通常最好使用完全异步的驱动程序(“方法 1”)。但是,这意味着您不能使用像 SQLAlchemy 这样包装数据库操作的同步库。在这种情况下,您可能必须使用线程(“方法 3”),这几乎和“方法 2”一样好(并且比“方法 2”更容易)。
“方法4”的优点是简单。过去这足以推荐它,因为到处引入回调很乏味;随着协同程序的出现,方法 3 几乎同样简单,因此通常使用线程比阻塞进程更好。
关于python - 如何在 Tornado 中为具有高度可扩展基础架构的应用程序调用 MySQL 数据库,从而进行大量数据库查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34799594/
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 4 个月前关闭。 Improve
我已经为这个概念苦苦挣扎了一段时间。我正在尝试提出一种松散耦合的 Azure 组件设计,该设计可以使用队列和辅助角色完全可扩展,从而使项目出列并处理。我可以随意扩展工作角色,并且发布到队列从来都不是问
尝试在 android 中创建可扩展 ListView 。我希望每个组都扩展到一个预设的 XML 布局文件。例如。 A组{ 展开时显示 XML 文件 A:按钮、搜索栏、微调器等 } 乙组{ 展开时显示
在 android 可扩展 ListView 中,我需要显示子项,仅在按下展开折叠节点时..即;我不想让 children 按下可扩展 ListView 的行。我该如何完成? 问候,罗尼 最佳答案 我
我正在开发一个Android代码编辑器,但是当我对它应用语法突出显示时,它会变得很滞后,是否有任何方法可以对其进行优化? 这是我的代码: protected void onCreate(Bundle
我正在开发安卓应用程序。我发现下面的输出图像显示了以下问题。请帮我解决我的问题。 Xml file 输出截图- 最佳答案 使用 setIndicatorBounds。 开发链接:http://deve
最近我在尝试使用 android 的可扩展 ListView ,所以我四处搜索并偶然发现了这个 http://about-android.blogspot.com/2010/04/steps-to-i
在 Control.Exception 的文档中在 base 4.4.0.0 中有一个如何创建异常层次结构的示例。该示例展示了如何通过根据父异常声明 Exception 类的实例来捕获特定异常的概括。
我正在开发一个将显示一些可扩展列表的应用程序。事实上,有时该对象不会有任何子对象。所以我想在我的可扩展列表中仅显示具有子元素的元素。我尝试在 getGroupView 函数中放入 if ,如果该对象没
这是一个有点开放式的问题,但是,制作良好的可扩展 Electron 应用程序的好方法是什么? VSCode、Atom 和许多其他工具都支持扩展,但它们的代码库太大,我无法理解发生了什么。我对 Jupy
我和一些 friend 为 Facebook 编写了一款游戏,但没有过多考虑游戏的实际架构 - 想象一下当我们每月吸引超过 300,000 名独立玩家并且我们的服务器崩溃时我们的惊喜。 现在我们正在努
您好,我正在使用 Android Expandable listview 并在其中用不同的 View 膨胀 child 。我遇到的问题是,当我展开一个 View 然后打开另一个父 View 时,布局中
我的场景是,我有一个可扩展 ListView ,在列表中动态添加我和 child 。我的子布局就是这样。 当我点击相应项目的编辑按钮时,我打开对话框从用户那里获取输入,然后点击更新相应的详细信息更新到
我想使用 RecyclerView 创建项目列表,并希望在单击时展开特定项目(如电话列表)。我想在不使用任何库的情况下实现这一目标。谁能帮忙? 最佳答案 获取子数据列表作为数据集中父数据的成员。并且,
我使用 ExpandableListview ... 我能够将从 Web 服务检索到的值设置为子布局的单个 Textview。现在需要在 Web 服务的子布局中设置两个不同的 Textviews 值我
我的可扩展 ListView 的顺序似乎不正确。 这是我的数据提供者: public class DataProvider { public static HashMap> getInfo() {
所以我试图在我的可扩展列表的子项列表中创建一行,但它不起作用,这是我的布局:
我有一个需要自定义箭头的可扩展 ListView 。我尝试将 groupIndicator 设置为这样的选择器: 但是,出于某种原因,这会扭曲箭头的尺寸,请参见下文: 知道它们为
我正在尝试实现具有 2 种不同布局的 ExpandableListView,到目前为止,我花了一段时间才真正让 1 个 View 组使用一个布局,而其他 2 个 View 组使用另一个。到目前为止,外
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我是一名优秀的程序员,十分优秀!