Transaction submission optimization method
By adopting a multi-queue asynchronous aggregation and commit architecture, the problem of long-term occupation of working threads in distributed transaction commits is solved, achieving efficient asynchronous processing and improving transaction commit efficiency.
Patent Information
- Application Number
- CN202511369620.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-24
- Publication Date
- 2026-01-23
AI Technical Summary
In the process of distributed transaction commit, the synchronous waiting mechanism of two-phase transaction commit leads to inefficiency, with working threads being occupied for a long time, affecting the efficiency of transaction commit.
A multi-queue asynchronous aggregation and commit architecture is adopted, which collects transaction preparation, commit and response messages through waiting queue, commit queue and response queue respectively, and processes them through asynchronous threads, decoupling the execution of each message queue to achieve asynchronous processing.
It improves the efficiency of distributed transaction commits, allowing working threads to be released in a timely manner to perform other tasks, avoiding synchronous waiting and enhancing the overall transaction processing capability.
Smart Images

Figure CN121387447A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a transaction submission optimization method. BACKGROUND
[0002] With the rapid development of mobile Internet, various systems have been developed. Each system needs corresponding data storage function, and the most common way is to use database for data storage.
[0003] With the rapid increase of users and user data, each system of the server gradually realizes the division of business fields through the micro-service architecture, and each micro-service will access its own database. In order to realize the operation and rollback of transaction data between each database, the function of distributed transaction is developed. In order to meet the function of distributed transaction submission, the two-phase transaction submission ability is generally used at present. That is, each node is ready for local transaction function and sends a preparation completion notification. When all nodes are ready, the transaction is submitted uniformly. If any node has a problem, the transaction rollback operation will be performed on all nodes. When the client node performs transaction preparation submission, the transaction processing center also needs a corresponding working thread to be occupied. That is, a node submits a transaction, and a working thread is occupied. It will wait for all nodes to send preparation messages and complete the submission transaction return before the working thread notifies the client that the transaction submission is successful. In the two-phase submission, the synchronous waiting scene will greatly restrict the efficiency of transaction submission. SUMMARY
[0004] In view of the above problems, the purpose of the present application is to provide a multi-queue asynchronous aggregation submission architecture scheme to greatly improve the efficiency of distributed transaction submission.
[0005] In order to achieve the above technical purpose, the technical scheme adopted by the present application is as follows: a transaction submission optimization method, comprising: collecting distributed transaction messages by using multiple queues, and decoupling and asynchronously executing between each message queue; Among them, the multiple queues mainly include a waiting queue, a submission queue and a response queue; The waiting queue is used to collect the preparation messages of a single transaction, the submission queue is used to collect the transaction submission messages, and the response queue is used to collect the response messages; The working thread sends messages to the corresponding queue after receiving the client message, and then releases the working thread for other transaction submission.
[0006] In some embodiments, the waiting queue is used to collect the preparation messages of a single transaction, in particular, after the start of the distributed transaction, the working thread receives the client message and directly sends the message to the waiting queue; The working thread is released after sending the message to the waiting queue, and the subsequent working thread can continue other tasks.
[0007] In some embodiments, the submission queue is used to collect the transaction submission messages, in particular as follows: An asynchronous thread is set to consume the messages in the waiting queue; for multiple messages in the same transaction, the messages corresponding to the same transaction are packaged as a to-be-submitted message after all the messages corresponding to any transaction are obtained, and the to-be-submitted message is sent to the submission queue.
[0008] In some embodiments, the response queue is used to collect the response messages, in particular as follows: An asynchronous thread is set to consume the messages in the submission queue; the thread performs the submission operation and synchronously waits for the return code; when the return code is obtained, the thread sends the message to the response queue.
[0009] In some embodiments, the optimization method of the transaction submission further comprises: setting an asynchronous thread to consume the messages in the response queue; when the message in the response queue is obtained, the message details corresponding to the transaction are disassembled according to the transaction identifier in the message; According to the corresponding message details, the working thread notifies the client thread that is synchronously blocked and waiting of the success or failure of the transaction submission; if successful, the success logic is executed, and if failed, the local rollback operation is executed.
[0010] In some embodiments, the submission queue is further used for the conversion of the message format, and the message format is uniformly converted into an executable format of the submission queue.
[0011] In some embodiments, the optimization method of the transaction submission comprises the following steps: After the start of the distributed transaction, the working thread receives the client message and directly sends the message to the waiting queue, and then the working thread is released, and the subsequent working thread can continue other tasks; An asynchronous thread is set to consume the messages in the waiting queue; for multiple messages in the same transaction, the messages corresponding to the same transaction are packaged as a to-be-submitted message after all the messages corresponding to any transaction are obtained, and the to-be-submitted message is sent to the submission queue; An asynchronous thread is set for consuming the message in the submission queue; the thread executes the submission operation and synchronously waits for the return code; when the return code is obtained, the thread sends a message to the response queue; An asynchronous thread is set for consuming the message in the response queue; when the message in the response queue is obtained, the message details corresponding to the transaction identification in the message are disassembled; and according to the corresponding message details, the working thread notifies the client thread which is synchronously blocked and waiting that the current transaction submission is successful or failed; if successful, the success logic is executed, and if failed, the local rollback operation is executed.
[0012] Compared with the prior art, the technical scheme has the beneficial effects that: The application collects the messages of the distributed transaction by using multiple queues, collects the preparation messages of a single transaction by using a waiting queue, collects the transaction submission messages by using a submission queue, and collects the response messages by using a response queue, the message queues are decoupled and can be executed asynchronously, the problem of the working synchronous waiting in the old mode is solved, the working thread can be released to perform the submission work of other transactions after receiving the client message and sending the message to the corresponding queue, and the efficiency of the distributed transaction submission is greatly improved by using the method. BRIEF DESCRIPTION OF DRAWINGS
[0013] In order to more clearly illustrate the technical scheme in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or the prior art description will be briefly introduced. Obviously, the drawings in the following description only some embodiments of the present application, and all other drawings obtained by those skilled in the art without creative labor are within the scope of the present application.
[0014] Figure 1 The method flowchart of the embodiments of the present application. DETAILED DESCRIPTION
[0015] The present application will be further described in detail below in combination with the drawings and embodiments. It is particularly pointed out that the following embodiments are only used to illustrate the present application, but do not limit the scope of the present application. Similarly, the following embodiments are only some embodiments of the present application, not all embodiments, and all other embodiments obtained by those skilled in the art without creative labor are within the scope of the present application.
[0016] The present embodiment provides an optimization method for transaction submission, comprising: By using multiple queues to collect distributed transactions, the preparation messages of a single transaction are collected by a waiting queue, the transaction submission messages are collected by a submission queue, and the response messages are collected by a response queue. The message queues are decoupled and can be executed asynchronously.
[0017] In this embodiment, the submission queue is a queue that can be directly executed after aggregation of messages: by using the submission queue to aggregate messages in batches, compared with independent processing of each message, the network I / O can be significantly reduced, thereby improving the efficiency of transaction submission. The aggregation of messages here is the aggregation of multiple messages within the same transaction, so each message processed is a message within the same transaction, and no waiting is required. (In the old way, there are multiple sub-messages within the same transaction, and there is a sequence of messages, so there will be waiting.) In addition, in a distributed scenario, the submission queue can also function as a message format conversion, for example: converting to a submission queue executable format, thereby improving the efficiency of transaction submission.
[0018] After the working thread receives the client message, it sends the message to the corresponding queue, and after completion, it releases the working thread for the submission of other transactions.
[0019] Referring to FIG. 1, Figure 1 The transaction submission optimization method in this embodiment specifically includes the following steps: After the distributed transaction starts, the working thread receives the client message, directly sends the message to the waiting queue, and then releases the working thread. The working thread can continue to perform other tasks.
[0020] An asynchronous thread is set to consume the messages in the waiting queue; multiple messages within the same transaction are aggregated, and when all the messages corresponding to any transaction are obtained, the messages corresponding to the transaction are packaged as a to-be-submitted message and sent to the submission queue.
[0021] An asynchronous thread is set to consume the messages in the submission queue; the thread performs a submission operation and synchronously waits for a return code; when the return code is obtained, the thread sends a message to the response queue.
[0022] An asynchronous thread is set to consume the messages in the response queue; when the messages in the response queue are obtained, the messages are disassembled into corresponding message details according to the transaction identifier in the message; and according to the corresponding message details, the working thread notifies the client thread that is synchronously blocked and waiting that the current transaction submission is successful or failed; if successful, the success logic is executed, and if failed, a local rollback operation is performed.
[0023] The above methods can greatly improve the efficiency of distributed transaction commits.
[0024] For ease of understanding, the following example of a distributed system with three nodes will be used to further illustrate the solution of this invention: 1) Assume a distributed system with 3 nodes. When a distributed transaction begins, these 3 nodes will send 3 preparation messages. In the old approach, 3 working threads would process these 3 messages and then be blocked again. The new solution provided in this invention also requires 3 working threads to process these 3 messages; however, after receiving a message, the working thread directly sends it to the waiting queue, thus releasing the working thread. Subsequent working threads can then continue performing other tasks without being blocked.
[0025] 2) An asynchronous thread consumes messages in the waiting queue. Once all messages in a transaction have been retrieved (e.g., the 3 messages in step 1), these 3 messages are packaged into a single message to be committed and sent to the commit queue.
[0026] 3) An asynchronous thread consumes messages from the commit queue. At this time, all messages in this queue are ready to be committed. This consuming thread performs the commit operation and synchronously waits for the return code. Once the return code is received, this thread sends a message to the response queue.
[0027] 4) An asynchronous thread consumes messages from the response queue. When a message is retrieved from the response queue, it is broken down into corresponding message details [here, it is broken down into 3 message details] based on the transaction identifier in the message. Then, based on the corresponding message details, the working thread notifies the client thread that is synchronously blocked and waiting, informing it whether the transaction commit was successful or failed. If successful, the success logic is executed; if it fails, a local rollback operation is performed.
[0028] "Splitting the response information into multiple pending messages and returning it to the client": Compared to the simple ACK returned by a conventional queue, response splitting in this invention can accurately locate failed messages, thereby avoiding retries for the entire batch. Compared to the resource waste caused by the overall rollback required by conventional queues, response splitting enables retries for failed messages and immediate responses for successful messages, thus improving the efficiency of transaction commit. The purpose of splitting in this step is to ensure that all messages within the same transaction are completed simultaneously, without unnecessary waiting. Therefore, each sub-message within the same transaction must be successfully executed before notifying the client; no additional waiting is required.
[0029] The above merely describes some embodiments of the present application, and is not intended to limit the protection scope of the present application, and any equivalent device or equivalent process transformation, or direct or indirect application in other related technical fields, which are made by using the content of the present application specification and drawings, are also included in the patent protection scope of the present application.
Claims
1. An optimization method for transaction commit, characterized in that, include: By using multiple queues to collect messages from distributed transactions, the message queues are decoupled and can be executed asynchronously. The multiple queues mainly include waiting queues, submission queues, and response queues; The wait queue is used to collect preparation messages for a single transaction, the commit queue is used to collect transaction commit messages, and the response queue is used to collect response messages. After receiving a message from the client, the working thread sends the message to the corresponding queue. Once finished, the working thread can be released to commit other transactions.
2. The transaction commit optimization method according to claim 1, characterized in that, The waiting queue is used to collect preparation messages for a single transaction. Specifically, after a distributed transaction begins, the working thread receives a message from the client and sends the message directly to the waiting queue. Once the message is sent to the waiting queue, the working thread can be released, and the working thread can then continue to perform other tasks.
3. The optimized transaction commit method according to claim 1, characterized in that, The commit queue is used to collect transaction commit messages, as follows: Set up an asynchronous thread to consume messages in the waiting queue; aggregate multiple messages within the same transaction, and once all messages corresponding to any transaction have been obtained, package the messages corresponding to that transaction into a message to be committed and send it to the commit queue.
4. The transaction commit optimization method according to claim 1, characterized in that, The response queue is used to collect response messages, as follows: An asynchronous thread is set up to consume messages in the commit queue; this thread will perform the commit operation and synchronously wait for the return code; when the return code is obtained, the thread sends a message to the response queue.
5. The transaction commit optimization method according to claim 1, characterized in that, Also includes: Set up an asynchronous thread to consume messages in the response queue; When a message is retrieved from the response queue, it is broken down into the corresponding message details based on the transaction identifier in the message; Based on the corresponding message details, the working thread notifies the client thread that is currently blocked and waiting for synchronization whether the transaction commit was successful or failed. If successful, execute the success logic; if it fails, execute the local rollback operation.
6. The transaction commit optimization method according to claim 1, characterized in that, The submission queue is also used for message format conversion, uniformly converting message formats into a submission queue executable format.
7. The transaction commit optimization method according to claim 1, characterized in that, Specifically, the steps include the following: Once a distributed transaction begins, the working thread receives a message from the client, sends the message to the waiting queue, and then releases the working thread, which can then continue to perform other tasks. Set up an asynchronous thread to consume messages in the waiting queue; aggregate multiple messages within the same transaction, and when all messages corresponding to any transaction have been obtained, package the messages corresponding to that transaction into a message to be committed and send it to the commit queue. An asynchronous thread is set up to consume messages in the commit queue; this thread will perform the commit operation and synchronously wait for the return code; when the return code is obtained, the thread sends a message to the response queue. An asynchronous thread is set up to consume messages in the response queue. When a message is received in the response queue, it is broken down into corresponding message details according to the transaction identifier in the message. Based on the corresponding message details, the working thread notifies the client thread that is synchronously blocked and waiting of the message details, informing it whether the transaction commit was successful or failed. If successful, execute the success logic; if it fails, execute the local rollback operation.