简体   繁体   English

分布式(XA)事务的性能调整-如何?

[英]Performance tuning of Distributed ( XA ) transaction - How?

In relation to another post of mine , I realized that there is more we can say on stackoverflow in relation to the Distributed, XA transactions and its internals. 关于我的另一个职位 ,我意识到关于分布式,XA事务及其内部的更多问题,我们可以说更多。 Common opinion is that distributed transactions are slow. 普遍的看法是,分布式事务处理速度很慢。

What are the XA transactions internals and how can we tune them ? XA事务的内部是什么,我们如何调整它们?

First lets put some common vocabulary. 首先让我们放一些常用词汇。 We have two or more parties 我们有两个或多个聚会

  • Transaction Coordinator this is where our business logic resides. 交易协调员,这就是我们的业务逻辑所在。 This is the side that orchestrates the distributed transaction. 这是协调分布式事务的一面。
  • Transaction Participant (XAResource) this can be any Dababase supporting distributed transactions or some other entity supporting the XA protocol like messaging service. 交易参与者 (XAResource),可以是任何支持分布式交易的Dababase,也可以是其他支持XA协议的实体,例如消息服务。

Lets highlight the main API functions performed during XA transaction. 让我们重点介绍XA事务期间执行的主要API函数。 - start(XID) - end(XID) - prepare(XID) - commit(XID) -开始(XID)-结束(XID)-准备(XID)-提交(XID)

在此处输入图片说明

The first 2 operations are visible in our source code. 前两个操作在我们的源代码中可见。 This is when we initiate the transaction do some work and then say commit. 这是我们启动事务时做的一些工作,然后说提交。 Once we send the commit message from the source code the Transaction Coordinator and the transaction Participant take over and do some work. 一旦我们从源代码发送了提交消息,事务处理协调器和事务参与方就会接管并做一些工作。

XID parameter is used as a unique key identifying the transaction. XID参数用作标识事务的唯一密钥。 Each transaction coordinator and each participant at any time can participate in more than one transaction so this is needed in order to identify them. 每个交易协调员和每个参与者在任何时候都可以参与一个以上的交易,因此需要进行身份识别。 The XID has two parts one part identifies the global transaction, the second part identifies the participant. XID有两部分,一部分标识全局事务,第二部分标识参与者。 This mean that each participant in the same transaction will have its own sub identifier. 这意味着同一笔交易中的每个参与者都将拥有自己的子标识符。 Once we reach the transaction prepare phase , each transaction participant writes its work to the transaction log and each Transaction Participant(XARersource) votes if its part is OK or FAILED. 一旦我们进入交易准备阶段,每个交易参与者将其工作写入交易日志,并且每个交易参与者(XARersource)的投票如果合格或失败,则进行投票。 Once all votes are received the transaction is committed. 一旦收到所有选票,交易即告完成。 If the power goes down the both the Transaction Coordinator and the Transaction Participant keep their transaction logs durable and can presume their work. 如果断电,事务协调器和事务参与者都将保持事务日志的持久性并可以假定其工作。 If one of the participant vote FAILED during transaction commit then subsequent rollback will be initiated. 如果参与者之一在事务提交期间投票失败,则将启动后续回滚。

Implications in terms of performance 对性能的影响

According to the CAP theorem each application(functionality) falls somewhere in between the triangle defined by Consistency, Partitioning and Availability. 根据CAP定理,每个应用程序(功能)都位于由一致性,分区和可用性定义的三角形之间的某个位置。 The main issue with the XA/ Distributed transaction is that it requires extreme consistency. XA /分布式事务的主要问题是它要求极端的一致性。

This requirement results into very high network and disk IO activity. 此要求导致很高的网络和磁盘IO活动。

Disk activity Both the transaction coordinator and the transaction participant need to maintain a transaction log. 磁盘活动事务协调器和事务参与者都需要维护事务日志。 This log is held on the disk each transaction needs to force information withing this disklog, this information is not buffered information. 该日志保存在磁盘上,每个事务都需要将此磁盘日志强制信息,该信息不是缓冲信息。 Having large parallelism will result in high amount of small messages forced to the disk in each transaction log. 具有较大的并行性将导致大量小消息被强制发送到每个事务日志中的磁盘。 Normally if we copy one 1GB file from one hard disk to another hard disk this will be very fast operation. 通常,如果我们将一个1GB的文件从一个硬盘复制到另一个硬盘,这将是非常快速的操作。 If we split the file into 1 000 000 parts of couple of bytes each the file transfer will be extremely slow. 如果我们将文件分割成1 000 000个字节,每个文件传输将非常慢。

Disk forcing grows with the number of participants. 磁盘强制随着参与者的数量而增长。

1 participant is treated as normal transaction 1位参与者被视为正常交易
2 participants the disk forcing is 5 2位参与者磁盘强制为5
3 equals 7 3等于7

Network Activity In order to draw a parallel for distributed XATransaction we need to compare it to something. 网络活动为了绘制并行的XATransaction,我们需要将其与某些对象进行比较。 The network activity during normal transaction is the following. 正常交易期间的网络活动如下。 3 network trips -enlist transaction, send some SQLs, commit. 3次网络旅行-登记事务,发送一些SQL,然后提交。

For a XA transaction it is one idea more complicated. 对于XA事务,这是一个更复杂的想法。 If we have 2 Participants. 如果我们有2个参与者。 We enlist the resources in a transaction 2 network trips. 我们将资源纳入交易2网络旅行中。 Then we send prepare message another 2 trips then we commit with another 2 trips. 然后我们再发送准备消息2次,然后再提交2次。

The actual network activity that is happening for 2 resources grows even more the more participants you enlist in the transaction. 您在事务中登记的参与者越多,则2种资源正在发生的实际网络活动就越大。

The conclusion on how to get a distributed transaction fast 关于如何快速获得分布式交易的结论

  • To do this you need to ensure you have a fast network with minimum latency 为此,您需要确保您的网络快速且延迟最小
  • Ensure you have Hard drives with minimum latency and maximum random write speed. 确保您的硬盘具有最小的延迟和最大的随机写入速度。 A good SSD can do miracle. 好的SSD可以创造奇迹。 -Try to enlist as minimum as possible distributed resources in the transaction -尝试在事务中争取最少的分布式资源
  • Try to divide your data into data that has strong requirement for Consistency and Availability (Live data) and data that has low consistency requirements. 尝试将数据分为对一致性和可用性有严格要求的数据(实时数据)和对一致性要求较低的数据。 Live data use Distributed transaction. 实时数据使用分布式事务。 For offline data use normal transaction, or no transaction if your data does not require it. 对于脱机数据,请使用常规交易,如果您的数据不需要,则不进行任何交易。

My answer is based on what I have read in " XA exposed " (and personal experience) which appears to be no longer available on internet which triggered me to write this. 我的答案是基于我在“ XA暴露 ”(以及个人经验)中所读的内容,该内容似乎不再在Internet上提供,因此我不得不写这篇文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM