Transaction request processing method, device and electronic device

By using concurrent working threads to process transaction requests in batches and dynamically adjusting the number of threads in a distributed database system, the problem of low transaction request processing efficiency in a distributed database system is solved, and the response speed and performance are improved.

CN113268327BActive Publication Date: 2024-09-27BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110574800.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-05-25
Publication Date
2024-09-27
Estimated Expiration
2041-05-25

AI Technical Summary

Technical Problem

In a distributed database system, the method of obtaining the global transaction ID is usually on-demand, which results in multiple client transaction requests requiring multiple network interactions, resulting in high traffic and calculation pressure on the metadata nodes of the network and server, and slow response speed. Slow and low distributed transaction performance.

Method used

By presetting multiple concurrently executing working threads in the server, batch processing of transaction request combinations is used, the listening thread is used to regularly obtain transaction requests within a specified time period, and the number of working threads is dynamically adjusted to adapt to network delay and processing status, using asynchronous The processing method reduces the amount of data interaction.

Benefits of technology

It reduces the amount of data interaction of transaction processing nodes, reduces the traffic and computing pressure of the network and nodes, improves the efficiency and response speed of transaction request processing, and improves the performance of distributed transactions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113268327B
    Figure CN113268327B
Patent Text Reader

Abstract

The present invention provides a transaction request processing method, device and electronic device, wherein a first working thread is allocated to a transaction request combination from a plurality of concurrently executable working threads; the transaction request combination includes at least one transaction request received within a first specified time period; a transaction processing request is sent to a transaction processing node through the first working thread, so that the transaction processing node processes the transaction requests in the transaction request combination. In this manner, the transaction request combination includes all transaction requests received within a certain time period, and by batch processing transaction requests, the data interaction amount of the transaction processing node can be reduced, and the traffic and computing pressure of the network and nodes can be reduced; in addition, the concurrent execution of multiple working threads can reduce the delay in transaction request processing, thereby improving the efficiency of request transaction processing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of distributed systems, and in particular to a method, device and electronic device for processing a transaction request. Background Art

[0002] In a distributed database system, it is usually necessary to assign a global transaction ID to the transaction to be processed in order to achieve global consistency reading; for a two-stage distributed database system, the way to obtain the global transaction ID is usually to obtain it on demand. In each stage, for each transaction request issued by the client, the client needs to interact with the metadata node through the network to obtain the global transaction ID of the transaction request; for transaction requests from multiple clients, multiple network interactions are required to obtain the global transaction ID of each transaction request; when multiple clients send a large number of transaction requests to the server, it will cause a large amount of traffic and computing pressure on the network and the metadata nodes of the server, resulting in a slow response of the server to the client request and low performance of distributed transactions. Summary of the invention

[0003] In view of this, an object of the present invention is to provide a method, device and electronic device for processing transaction requests, so as to increase the speed at which a server responds to a client request, thereby improving the performance of distributed transactions.

[0004] An embodiment of the present invention provides a method for processing transaction requests, which is applied to a server; a plurality of concurrently executable working threads are preset in the server; the method comprises: obtaining a transaction request combination, and allocating a first working thread to the transaction request combination from the plurality of working threads; wherein the transaction request combination comprises at least one transaction request received within a first specified time period; and sending a transaction processing request to a transaction processing node through the first working thread, wherein the transaction processing request is used to process the transaction requests in the transaction request combination.

[0005] Furthermore, a listening thread is preset in the server; the step of obtaining a transaction request combination and allocating a first working thread to the transaction request combination from multiple working threads includes: through the listening thread, every time the length of the first specified time period passes, cyclically executing the following operations: obtaining transaction requests received within the first specified time period, and determining the obtained transaction requests as the transaction request combination; determining a working thread in an idle state among the multiple working threads as the first working thread, and sending the transaction request combination to the first working thread.

[0006] Furthermore, before the step of obtaining a transaction request combination and allocating a first working thread to the transaction request combination from a plurality of working threads, the method further includes: determining an initial number of threads of the plurality of working threads based on a first specified time period and an initial network delay time.

[0007] Furthermore, the step of determining the initial number of threads of multiple working threads based on the first specified time period and the initial network delay time includes: calculating the ratio of the initial network delay time to the first specified time period, and determining the initial number of threads based on the ratio; wherein the first specified time period is less than the initial network delay time; and determining the initial number of threads as the initial number of threads of the multiple working threads.

[0008] Furthermore, the step of determining the initial number of threads according to the ratio includes: if the ratio is an integer, determining the ratio as the initial number of threads; if the ratio includes a non-zero decimal, adding one to the integer of the ratio to obtain the initial number of threads.

[0009] Furthermore, after the step of sending a transaction processing request to a transaction processing node through the first working thread, where the transaction processing request is used to process a transaction request in a transaction request combination, the method further includes: updating an initial number of threads of multiple working threads based on a current network delay time and the number of transaction requests being processed.

[0010] Furthermore, the step of updating the initial number of threads of multiple working threads based on the current network delay time and the number of transaction requests being processed includes: within a preset timing duration, every time a second specified time period passes, cyclically executing the following operations: obtaining the current network delay time and the number of transaction requests currently being processed; calculating the ratio of the current network delay time to the first specified time period, and determining the target number of threads based on the ratio; comparing the target number of threads with the initial number of threads of multiple working threads to obtain a comparison result; when the timing duration is reached, updating the initial number of threads of multiple working threads based on the comparison result.

[0011] Furthermore, based on the comparison results, the step of updating the initial number of threads of the multiple working threads includes: if the comparison results all indicate that the target number of threads is greater than the initial number of threads of the multiple working threads, and the number of transaction requests currently being processed meets a preset number, increasing the initial number of threads of the multiple working threads to the target number of threads; if the comparison results all indicate that the target number of threads is less than the initial number of threads of the multiple working threads, reducing the initial number of threads of the multiple working threads to the target number of threads.

[0012] Furthermore, the step of reducing the initial number of threads of the multiple worker threads to the target number of threads includes: deleting the worker threads whose current working state is idle among the multiple worker threads, so that the initial number of threads of the multiple worker threads after update is consistent with the target number of threads.

[0013] Furthermore, a transaction processing request is sent to the transaction processing node through the first working thread, and the transaction processing request is used to process the transaction requests in the transaction request combination, including: sending at least one transaction request in the transaction request combination to the transaction processing node through the first working thread in an asynchronous processing manner, generating a response message corresponding to each transaction request; and returning each response message to the client corresponding to the response message.

[0014] Furthermore, the method also includes: based on a third specified time period, periodically obtaining the number of threads of the current working thread; if the number of threads of the current working thread is greater than the specified number of threads, reducing the number of threads of the current working thread to the specified number of threads; wherein the specified number of threads is pre-set according to the performance of the server.

[0015] An embodiment of the present invention also provides a transaction request processing device, which is arranged in a server; a plurality of concurrently executable working threads are preset in the server; the device comprises: an acquisition module, which is used to acquire a transaction request combination, and allocate a first working thread to the transaction request combination from a plurality of working threads; wherein the transaction request combination comprises at least one transaction request received within a specified time period; and a processing module, which is used to send a transaction processing request to a transaction processing node through the first working thread, wherein the transaction processing request is used to process the transaction requests in the transaction request combination.

[0016] An embodiment of the present invention further provides an electronic device, including a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the transaction request processing method of any one of the first aspects.

[0017] An embodiment of the present invention also provides a machine-readable storage medium, which stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the transaction request processing method of any one of the first aspects.

[0018] The embodiments of the present invention bring the following beneficial effects:

[0019] The present invention provides a transaction request processing method, device and electronic device, firstly obtaining a transaction request combination, and assigning a first working thread to the transaction request combination from a plurality of working threads; wherein the transaction request combination includes at least one transaction request received within a first specified time period; then sending a transaction processing request to a transaction processing node through the first working thread, and the transaction processing request is used to process the transaction requests in the transaction request combination. In this method, the transaction request combination may include all transaction requests received within a certain time period, and a working thread is assigned to the transaction request combination from a plurality of concurrently executable working threads, and then the transaction processing node is requested to process the transaction requests in the transaction request combination. This method of batch processing transaction requests can reduce the amount of data interaction of the transaction processing node, thereby reducing the traffic and computing pressure of the network and nodes; in addition, the concurrent execution of multiple working threads can reduce the delay in transaction request processing, thereby improving the efficiency of request transaction processing.

[0020] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention are realized and obtained by the structures particularly pointed out in the description, claims and drawings.

[0021] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.

[0023] Figure 1 A schematic diagram of an application scenario of a transaction request processing method provided by an embodiment of the present invention;

[0024] Figure 2 A flowchart of a method for processing a transaction request provided by an embodiment of the present invention;

[0025] Figure 3 An architecture diagram of a specific transaction request processing method provided by an embodiment of the present invention;

[0026] Figure 4 A schematic diagram of the structure of a transaction request processing device provided by an embodiment of the present invention;

[0027] Figure 5A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0028] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0029] At present, when designing and deploying systems in a distributed environment, there are usually three core requirements, which can also be called the CAP theorem, namely Consistency, Availability and Partition Tolerance; Among them, Consistency means consistency, and the data on all data nodes are consistent and correct; Availability means availability, ensuring that each request has a response regardless of success or failure; Partition Tolerance means partition tolerance, and the loss or failure of any information in the system will not affect the continued operation of the system. Secondly, there are four isolation levels for database transactions, namely uncommitted read, committed read, repeatable read, and serialization; Among them, uncommitted read means that a transaction can read data that other transactions have not committed; committed read means that if other transactions modify the corresponding table during transaction processing, multiple query statements of the same transaction may return different results; repeatable read means that during the transaction processing process, when the same data is read multiple times, its value is consistent with the transaction start time, but phantom data may also appear, that is, the same transaction operation, the same data read in two time periods before and after the results are different; serialization means that all transactions are required to be executed serially and cannot be executed concurrently.

[0030] In addition, distributed transactions include two-phase commits. The first phase is the request phase (or prepare phase). That is, in the request phase, the coordinator will notify the transaction participants to prepare to commit or cancel the transaction, and then enter the voting process. During the voting process, the participants will inform the coordinator of their decisions: agree (the transaction participant's local job execution is successful) or cancel (local job execution failure). In the second phase (or commit phase), the coordinator will make a decision (commit or cancel) based on the voting results of the first phase. If and only if all participants agree to commit the transaction, the coordinator will notify all participants to commit the transaction, otherwise the coordinator will notify all participants to cancel the transaction. After receiving the message from the coordinator, the participants will perform the corresponding operation.

[0031] In a distributed database system, consistency and partition tolerance are usually required. The transaction isolation level is usually committed read or repeatable read, and the transaction is a two-phase commit. In a distributed database system, it is usually necessary to assign a global transaction ID to the transaction to be processed to achieve global consistent read. For a two-phase distributed database system, the way to obtain the global transaction ID is usually to obtain it on demand. First, start the transaction; second, obtain the global transaction ID (defined as start_ts) and execute SQL (Structured Quer y Language); third, obtain the global transaction ID (defined as prepare_ts) and enter the request phase; fourth, obtain the global transaction ID (defined as commit_ts) and enter the commit phase. In each phase, for each transaction request issued by the client, the client needs to interact with the metadata node over the network to obtain the global transaction ID of the transaction request; for transaction requests from multiple clients, multiple network interactions are required to obtain the global transaction ID of each transaction request; when multiple clients send a large number of transaction requests to the server, it will cause greater traffic and computing pressure on the network and the metadata nodes of the server, resulting in a slower response of the server to client requests and lower performance of distributed transactions.

[0032] Based on this, an embodiment of the present invention provides a transaction request processing method, device and electronic device. The technology can be applied to electronic devices such as servers with distributed database systems.

[0033] To facilitate understanding of this embodiment, a method for processing a transaction request disclosed in an embodiment of the present invention is described in detail. Figure 1 A schematic diagram of an application scenario of a method for processing transaction requests is shown, in which the first electronic device in the figure may be a client device, which may generally include one or more devices for sending transaction requests; the second electronic device may be a server provided with a thread, for receiving or obtaining transaction requests sent by the client device; the third electronic device may be a metadata node provided in a database, for processing transaction requests sent by the server, and sending a response message corresponding to each transaction request to the second electronic device, which then sends the response message to the corresponding client device.

[0034] like Figure 2 The flowchart of a method for processing a transaction request is shown, and the method is applied to a server; the server is preset with multiple working threads that can be executed concurrently; the method comprises the following steps:

[0035] Step S202, obtaining a transaction request combination, and assigning a first working thread to the transaction request combination from a plurality of working threads; wherein the transaction request combination includes at least one transaction request received within a first specified time period;

[0036] The transaction request combination usually includes multiple transaction requests sent by multiple clients; the multiple worker threads can be executed concurrently, that is, they can process the received transaction requests at the same time; the first worker thread is usually an idle worker thread. In actual implementation, one or more transaction requests received within the first specified time period can be obtained in batches every time the first specified time period passes; after each transaction request combination is obtained, an idle worker thread can be selected from the multiple worker threads as the first worker thread.

[0037] For example, when there are 4 multiple working threads, the above-mentioned first specified time period is 0.5 milliseconds, and transaction requests are obtained in batches every 0.5 milliseconds. After the transaction request combination is obtained for the first time, since the multiple working threads are in an idle state, a working thread can be directly selected from the multiple working threads as the first first working thread; after another 0.5 milliseconds has passed, since the server network will have a delay, if the delay time is 2 milliseconds, at this time, the time for the first first working thread to process the transaction request has passed 0.5 milliseconds, so the first first working thread is still in the state of processing the transaction request, and at this time, after the transaction request combination is obtained for the second time, the second first working thread can be selected from the remaining three working threads; after another 0.5 milliseconds has passed, at this time, the time for the first first working thread to process the transaction request has passed 1 millisecond, and the time for the second first working thread to process the transaction request has passed 0.5 milliseconds, so the first first working thread and the second first working thread are still in the state of processing the transaction request, so after the transaction request combination is obtained for the third time, it is necessary to select the third first working thread from the remaining two working threads. When 0.5 milliseconds have passed again, the first first worker thread has processed the transaction request for 1.5 milliseconds, the second first worker thread has processed the transaction request for 1 millisecond, and the third first worker thread has processed the transaction request for 0.5 milliseconds. At this time, the first first worker thread, the second first worker thread, and the third first worker thread are still in the state of processing the transaction request. At this time, after obtaining the transaction request combination for the third time, it is necessary to select the fourth first worker thread from the remaining worker thread. When 0.5 milliseconds have passed again, the first first worker thread has processed the transaction request for 2 milliseconds, just finishing processing the current transaction request and being in an idle state. At this time, after obtaining the transaction request combination for the fourth time, this worker thread can be directly used as the next first worker thread.

[0038] Step S204: Send a transaction processing request to the transaction processing node through the first working thread, where the transaction processing request is used to process the transaction request in the transaction request combination.

[0039] The above-mentioned transaction processing node can be a metadata node, in which a unique identifier of the global transaction is set; each transaction request can be assigned a corresponding global transaction ID (also known as a timestamp), and the global transaction ID corresponding to the transaction request can be returned to the client through the first working thread.

[0040] For example, in the example of step S202, if the number of pre-set multiple working threads is 4, the client's waiting response time is usually only 2 milliseconds or 2.5 milliseconds of network delay; it is understandable that if the number of the multiple working threads is 3, the client's waiting time is usually 2-3 milliseconds; if the number of the multiple working threads is 2, the client's waiting time is usually 2-3.5 milliseconds; if the number of the multiple working threads is 1, the client's waiting time is usually 2-4 milliseconds. Since the multiple working threads are executed concurrently, the more the multiple working threads are, the less time the client waits.

[0041] An embodiment of the present invention provides a method for processing transaction requests, first obtaining a transaction request combination, and assigning a first working thread to the transaction request combination from multiple working threads; wherein the transaction request combination includes at least one transaction request received within a first specified time period; then, through the first working thread, sending a transaction processing request to a transaction processing node, the transaction processing request is used to request the processing of the transaction requests in the transaction combination. In this method, the transaction request combination may include all transaction requests received within a certain time period, and a working thread is assigned to the transaction request combination from multiple concurrently executable working threads, and then the transaction processing node is requested to process the transaction requests in the transaction request combination. This method of batch processing transaction requests can reduce the amount of data interaction of the transaction processing node, thereby reducing the traffic and computing pressure of the network and nodes; in addition, the concurrent execution of multiple working threads can reduce the delay in transaction request processing, thereby improving the efficiency of request transaction processing.

[0042] The embodiment of the present invention further provides another transaction request processing method, which is implemented on the basis of the above embodiment. This embodiment focuses on the specific implementation process of the steps of obtaining a transaction request combination and allocating a first working thread to the transaction request combination from multiple working threads, as well as the specific implementation process of the steps before this step. The method includes the following steps:

[0043] Step 301, determining the initial number of threads of a plurality of working threads according to a first specified time period and an initial network delay time;

[0044] The first specified time period can be set according to actual needs, for example, 0.5 milliseconds, 1 millisecond, etc.; the initial network delay time usually refers to the round-trip time of a transaction request from the user's terminal device to the website server, and then immediately returned from the website server to the user's terminal device. Of course, during the operation of the system, the initial network delay time may also change due to the quality of the network, the size of the request volume, etc. For example, the initial network delay time is 2 milliseconds, 3 milliseconds, etc.

[0045] A possible implementation of step 301 is as follows:

[0046] The ratio of the initial network delay time to the first specified time period is calculated, and the initial number of threads is determined according to the ratio; wherein the first specified time period is less than the initial network delay time; and the initial number of threads is determined as the initial number of threads of the plurality of working threads.

[0047] Specifically, if the ratio is an integer, the ratio is determined as the initial number of threads; if the ratio includes a non-zero decimal, the integer of the ratio is added by one to obtain the initial number of threads; for example, the initial network delay time is 2 milliseconds, and the first specified time period is 0.5 milliseconds. Based on the first specified time period, the transaction request combination is obtained regularly, and 2ms / 0.5ms=4 can be calculated, that is, the initial number of threads is 4; for another example, the initial network delay time is 2.7 milliseconds, and the first specified time period is 0.5 milliseconds. Based on the first specified time period, the transaction request combination is obtained regularly, and 2.7ms / 0.5ms=5.4 can be calculated. 5.4 is rounded up to obtain the initial number of threads of 6.

[0048] The server is also preset with a listening thread; through the listening thread, each time the first specified time period passes, the following steps 302 and 303 are executed cyclically:

[0049] Step 302, acquiring transaction requests received within a first specified time period, and determining the acquired transaction requests as a transaction request combination;

[0050] The above-mentioned listening thread can also be expressed as a listener thread; the listening thread has a batch processing function, that is, a function of periodically obtaining transaction requests in batches. Specifically, the transaction requests received within the first specified time period are obtained through the listening thread, and the obtained transaction requests are determined as a transaction request combination; wherein the received transaction requests usually include multiple requests, which may be sent by multiple clients. Compared with the method of obtaining each transaction request separately in sequence, the above-mentioned batch processing method can reduce the number of network interactions, reduce network delays, and improve the performance of distributed transactions.

[0051] Step 303: determine a working thread in an idle state among the multiple working threads as a first working thread, and send the transaction request combination to the first working thread;

[0052] Since the above-mentioned multiple worker threads are executed concurrently, after the listening thread receives the transaction request combination, it is first necessary to determine the worker threads in the idle state among the multiple worker threads. If there is a worker thread in the idle state, one can be selected as the first worker thread, and the transaction request combination can be sent to the first worker thread. It should be noted that in the related art, if there is no worker thread in the idle state among the multiple worker threads, it is necessary to wait until an idle worker thread appears before the transaction request combination can be sent to the first worker thread. Therefore, the above-mentioned step of setting the number of threads of the multiple worker threads can avoid the waiting process in the prior art. Usually, after receiving the transaction request combination, there will be at least one worker thread in the idle state.

[0053] Step 304: Request the transaction processing node to process the transaction request in the transaction request combination through the first working thread.

[0054] In the above method, the initial number of threads of multiple working threads is determined according to the first specified time period and the initial network delay time, wherein the determined initial number of threads of multiple working threads can satisfy that after the listening thread obtains the transaction request combination, there is always a working thread in an idle state among the multiple working threads, thereby avoiding the problem of waiting for processing transaction requests, and being able to process received transaction requests in a timely manner. Under the premise of ensuring the consistent reading function, the network delay is reduced, and the speed at which the server responds to the client transaction request is improved, thereby reducing the damage to the performance of the distributed system.

[0055] The embodiment of the present invention further provides another transaction request processing method, which is implemented on the basis of the above embodiment. This embodiment mainly describes the specific implementation process of the step of sending a transaction processing request to a transaction processing node through a first working thread, and the specific implementation process of the step after the step. The method includes the following steps:

[0056] Step 401, obtaining a transaction request combination, and assigning a first working thread to the transaction request combination from a plurality of working threads; wherein the transaction request combination includes at least one transaction request received within a first specified time period;

[0057] Step 402: send at least one transaction request in the transaction request combination to the transaction processing node in an asynchronous processing manner through the first working thread, generate a response message corresponding to each transaction request, and return each response message to the client corresponding to the response message.

[0058] Specifically, after receiving the transaction request combination, the first working thread adopts an asynchronous processing method to first send one transaction request in the transaction request combination to the transaction processing node, and before the transaction processing node returns a response message, concurrently sends the next transaction request in the transaction request combination to the transaction processing node, so that the transaction processing node allocates a corresponding response message to each transaction request. Finally, each response message is first returned to the corresponding working thread, and then the working thread returns the response message to the corresponding client.

[0059] When the server or system is running, it may be affected by the network, transaction request volume and other factors, and the initial network delay time may change. For example, the initial network delay time decreases or increases. At this time, the initial number of threads of multiple worker threads set in advance may not be suitable for the current working environment. The initial number of threads of each worker thread needs to be updated, including:

[0060] Step 403: based on the current network delay time and the number of transaction requests being processed, update the initial number of the plurality of working threads.

[0061] Specifically, when the current network delay time and the number of transaction requests being processed increase, the initial number of pre-set multiple worker threads is small. When the listening thread obtains the transaction request combination, there are no idle worker threads. At this time, waiting is required, which will reduce the speed at which the server responds to the client's transaction request. At this time, the number of multiple worker threads can be increased according to the current network delay time. In addition, when the current network delay time decreases and the number of transaction requests being processed decreases, there may be more idle worker threads. At this time, the number of multiple worker threads can be reduced according to the network delay time; this method can release system resources in a timely manner and meet business needs.

[0062] The above step 403, a possible real-time method:

[0063] During the preset timing duration, every time the second specified time period passes, the following operations are executed cyclically:

[0064] (1) Obtain the current network delay time and the number of transaction requests currently being processed;

[0065] (2) calculating the ratio of the current network delay time to the first specified time period, and determining the target number of threads according to the ratio;

[0066] (3) Compare the target number of threads with the initial number of threads of the plurality of working threads to obtain a comparison result;

[0067] The above-mentioned preset timing time can be 30 seconds, 1 minute, or 2 minutes, etc., which can be set according to business needs, and this embodiment does not limit it. The above-mentioned second specified time period is usually greater than the first specified time period, for example, 1 second, 2 seconds, etc., and similarly, it can be set according to business needs, and this embodiment does not limit it.

[0068] In actual implementation, when the server is running, before the second specified time period has passed, the current network delay time and the number of transaction requests currently being processed are obtained; the number of transaction requests currently being processed is the number of transaction requests currently being processed by each thread; then the ratio of the current network delay time to the first specified time period is calculated, and the comparison value is rounded up to obtain the target number of threads; the implementation method is the same as the above step 301, and will not be repeated again. Finally, the target number of threads is compared with the initial number of threads of multiple working threads to obtain a comparison result; the comparison result generally includes that the target number of threads is greater than the initial number of threads of multiple working threads, the target number of threads is less than the initial number of threads of multiple working threads, and the target number of threads is equal to the initial number of threads of multiple working threads.

[0069] (4) When the timing duration is reached, the initial number of threads of the multiple working threads is updated according to the comparison result.

[0070] During the above preset timing duration, a plurality of comparison results are usually obtained. When the timing duration is reached, the initial number of threads of the plurality of working threads may be increased or decreased according to each comparison result.

[0071] In the above step (4), when the timing duration is reached, the initial thread number of multiple working threads is updated according to the comparison result. A possible real-time method is:

[0072] If the comparison results all indicate that the target number of threads is greater than the initial number of threads of the multiple working threads, and the number of transaction requests currently being processed meets the preset number, the initial number of threads of the multiple working threads is increased to the target number of threads;

[0073] If the comparison results all indicate that the target number of threads is less than the initial number of threads of the plurality of worker threads, the initial number of threads of the plurality of worker threads is reduced to the target number of threads.

[0074] The above preset number can be set according to business needs, such as 0, 1, or other specific numbers. Specifically, when the timing duration is reached, if each comparison result continuously indicates that the target number of threads is greater than the initial number of threads of the multiple worker threads, and the number of transaction requests currently being processed is not zero, the number of worker threads can be increased to make the number of threads of the multiple worker threads the same as the target number of threads. In addition, if each comparison result continuously indicates that the target number of threads is greater than the initial number of threads of the multiple worker threads, and the number of transaction requests currently being processed is zero, it means that there is only network congestion at present, and there is no transaction request, so there is no need to update the initial number of threads of the multiple worker threads.

[0075] When the timing duration is reached, if each comparison result continuously indicates that the target number of threads is less than the initial number of threads of the plurality of worker threads, the number of worker threads can be reduced so that the number of threads of the plurality of worker threads is the same as the target number of threads, so as to release system resources in time and meet the needs of the business. In addition, if each comparison result continuously indicates that the target number of threads is equal to the initial number of threads of the plurality of worker threads, the number of threads of the plurality of worker threads is not updated.

[0076] The step of reducing the initial number of the plurality of worker threads to the target number of threads includes: deleting the worker threads whose current working state is idle among the plurality of worker threads, so that the initial number of the plurality of worker threads after update is consistent with the target number of threads.

[0077] When reducing the number of threads in multiple worker threads, since some worker threads are in working state, the worker threads whose current working state is idle can be selected for deletion, so that the initial number of threads of the updated multiple worker threads is consistent with the target number of threads.

[0078] In the above method, no matter how long the network delay is, the number of worker threads can be adaptively adjusted to meet the application. By updating the number of worker threads that send messages concurrently, the latency of concurrent transaction requests can be effectively reduced, and performance can be effectively improved in high-latency and high-throughput networks. This dynamic adjustment strategy is mainly to release system resources in a timely manner and meet business needs. In addition, this method reduces network interaction delays and improves the performance of distributed systems in processing transactions, especially for clusters with large network delays between clients and transaction processing nodes. The advantages of this solution are more obvious.

[0079] In addition, the above method also includes: based on a third specified time period, periodically obtaining the number of threads of the current working thread; if the number of threads of the current working thread is greater than the specified number of threads, reducing the number of threads of the current working thread to the specified number of threads; wherein the specified number of threads is pre-set according to the performance of the server.

[0080] The third specified time period may be the same as the second specified time period, or greater than the second specified time period. Specifically, if the comparison result indicates that the target number of threads is equal to the number of threads of the plurality of working threads, and the number of transaction requests currently being processed is zero, the number of threads of the current working thread is further obtained to determine whether the number of threads of the current working thread is greater than the specified number of threads. If it is greater than the specified number of threads, the number of threads of the current working thread is reduced to the specified number of threads to meet the application. This method takes into account the actual operating capacity of the server, sets the specified number of threads, and avoids problems such as slow network delays and slow response speeds caused when the number of threads of the current working thread exceeds the specified number of threads.

[0081] The embodiment of the present invention provides a specific transaction request processing method, such as Figure 3 As shown, the request message corresponds to the aforementioned transaction request, group 1 and group 2 correspond to the aforementioned transaction request combination; the timestamp request also corresponds to the aforementioned transaction request; the timestamp response corresponds to the aforementioned response message. The client can be understood as the coordinator in the two stages; the listener thread corresponds to the aforementioned listening thread, which mainly implements the batch function, that is, to obtain requests in batches at a fixed time; worker thread 1 and worker thread 2 correspond to the aforementioned multiple worker threads, which mainly implement the function of concurrent execution. The GTS node is the metadata center. Corresponding to the aforementioned transaction processing node, that is, allocating global time. Specifically, the listener thread obtains request messages at a fixed time, and groups the request messages obtained at the same time into a group, such as group 1 and group 2 in the figure. After obtaining a batch of requests, it is sent to the worker thread. Specifically, group 1 can be sent to worker thread 1, and group 2 can be sent to worker thread 2; each worker thread can interact asynchronously with the GTS node to obtain a timestamp response, and finally send the response message corresponding to each request message to the corresponding client.

[0082] Corresponding to the above method embodiment, the embodiment of the present invention further provides a transaction request processing device, which is arranged in a server; the server is preset with multiple concurrently executable working threads; Figure 4 As shown, the device comprises:

[0083] The acquisition module 41 is used to acquire a transaction request combination and allocate a first working thread to the transaction request combination from a plurality of working threads; wherein the transaction request combination includes at least one transaction request received within a specified time period;

[0084] The processing module 42 is used to send a transaction processing request to the transaction processing node through a first working thread, where the transaction processing request is used to process a transaction request in the transaction request combination.

[0085] The embodiment of the present invention provides a transaction request processing device, which first obtains a transaction request combination, and allocates a first working thread to the transaction request combination from multiple working threads; wherein the transaction request combination includes at least one transaction request received within a first specified time period; and then sends a transaction processing request to a transaction processing node through the first working thread, and the transaction processing request is used to process the transaction requests in the transaction request combination. In this method, at least one transaction request is obtained in batches when the first specified time period is reached, and each transaction request in the transaction request combination is processed through multiple working threads that can be executed concurrently, which reduces the network delay of the transaction request and improves the speed at which the server responds to the client transaction request while ensuring the consistent read function, thereby improving the performance of distributed transactions.

[0086] Furthermore, a listening thread is preset in the above-mentioned server; the above-mentioned acquisition module is also used to: through the listening thread, every time the length of the first specified time period passes, cyclically execute the following operations: obtain the transaction requests received within the first specified time period, and determine the obtained transaction requests as a transaction request combination; determine a working thread in an idle state among multiple working threads as the first working thread, and send the transaction request combination to the first working thread.

[0087] Furthermore, the above-mentioned device also includes a thread quantity determination module, which is used to determine the initial thread quantity of multiple working threads according to the first specified time period and the initial network delay time.

[0088] Furthermore, the above-mentioned thread number determination module is also used to: calculate the ratio of the initial network delay time to the first specified time period, and determine the initial number of threads based on the ratio; wherein the first specified time period is less than the initial network delay time; and determine the initial number of threads as the initial number of threads of multiple working threads.

[0089] Furthermore, the thread number determination module is further configured to: if the ratio is an integer, determine the ratio as the initial thread number; if the ratio includes a non-zero decimal, add one to the integer of the ratio to obtain the initial thread number.

[0090] Furthermore, the above-mentioned device also includes a thread quantity updating module, which is used to update the initial thread quantity of multiple working threads based on the current network delay time and the number of transaction requests being processed.

[0091] Furthermore, the above-mentioned thread quantity update module is also used to: within a preset timing duration, every time the second specified time period passes, loop the following operations: obtain the current network delay time and the number of transaction requests currently being processed; calculate the ratio of the current network delay time to the first specified time period, and determine the target number of threads based on the ratio; compare the target number of threads with the initial number of threads of multiple working threads to obtain a comparison result; when the timing duration is reached, update the initial number of threads of multiple working threads based on the comparison result.

[0092] Furthermore, the above-mentioned thread number update module is also used to: if the comparison results all indicate that the target thread number is greater than the initial thread number of multiple working threads, and the number of transaction requests currently being processed meets the preset number, increase the initial thread number of multiple working threads to the target thread number; if the comparison results all indicate that the target thread number is less than the initial thread number of multiple working threads, reduce the initial thread number of multiple working threads to the target thread number.

[0093] Furthermore, the thread quantity updating module is further used to delete the working threads whose current working status is idle among the multiple working threads, so that the initial thread quantity of the multiple working threads after update is consistent with the target thread quantity.

[0094] Furthermore, the above-mentioned processing module is also used to: send at least one transaction request in the transaction request combination to the transaction processing node through the first working thread in an asynchronous processing manner, generate a response message corresponding to each transaction request; and return each response message to the client corresponding to the response message.

[0095] Furthermore, the above-mentioned device is also used to: based on a third specified time period, periodically obtain the number of threads of the current working thread; if the number of threads of the current working thread is greater than the specified number of threads, reduce the number of threads of the current working thread to the specified number of threads; wherein the specified number of threads is pre-set according to the performance of the server.

[0096] The transaction request processing device provided in the embodiment of the present invention has the same technical features as the transaction request processing method provided in the above embodiment, so it can also solve the same technical problems and achieve the same technical effects.

[0097] An embodiment of the present invention further provides an electronic device, including a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the above-mentioned transaction request processing method.

[0098] See also Figure 5As shown, the electronic device includes a processor 100 and a memory 101. The memory 101 stores machine executable instructions that can be executed by the processor 100. The processor 100 executes the machine executable instructions to implement the above-mentioned transaction request processing method.

[0099] Further, Figure 5 The electronic device shown further includes a bus 102 and a communication interface 103 , and the processor 100 , the communication interface 103 and the memory 101 are connected via the bus 102 .

[0100] The memory 101 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 103 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus 102 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0101] The processor 100 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 100. The above processor 100 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present invention can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 101, and the processor 100 reads the information in the memory 101 and completes the steps of the method of the above embodiment in combination with its hardware.

[0102] An embodiment of the present invention further provides a machine-readable storage medium storing machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the above-mentioned transaction request processing method.

[0103] The computer program product of the transaction request processing method, device and system provided in the embodiments of the present invention includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the previous method embodiments. The specific implementation can be found in the method embodiments and will not be repeated here.

[0104] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0105] In addition, in the description of the embodiments of the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, and it can be the internal communication of two components. For those skilled in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0106] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program codes.

[0107] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.

[0108] Finally, it should be noted that the above embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above embodiments, those skilled in the art should understand that any person skilled in the art can still modify the technical solutions recorded in the above embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A method for processing a transaction request, characterized in that: The method is applied to a server; The server is preset with multiple working threads that can be executed concurrently; the method comprises: Acquire a transaction request combination, and allocate a first working thread to the transaction request combination from the multiple working threads; wherein the transaction request combination includes at least one transaction request received within a first specified time period; Sending a transaction processing request to a transaction processing node through the first working thread, where the transaction processing request is used to process a transaction request in the transaction request combination; The server is also preset with a listening thread; the step of obtaining the transaction request combination and allocating a first working thread to the transaction request combination from the multiple working threads includes: Through the monitoring thread, every time the first specified time period passes, the following operations are cyclically performed: Acquire transaction requests received within the first specified time period, and determine the acquired transaction requests as the transaction request combination; A working thread in an idle state among the multiple working threads is determined as a first working thread, and the transaction request combination is sent to the first working thread.

2. The method according to claim 1, characterized in that Before the step of obtaining a transaction request combination and allocating a first working thread to the transaction request combination from the multiple working threads, the method further includes: An initial number of threads of the plurality of working threads is determined according to the first specified time period and the initial network delay time.

3. The method according to claim 2, characterized in that The step of determining the initial number of threads of the plurality of working threads according to the first specified time period and the initial network delay time comprises: Calculating a ratio of the initial network delay time to the first specified time period, and determining the initial number of threads according to the ratio; wherein the first specified time period is less than the initial network delay time; The initial number of threads is determined as the initial number of threads of the plurality of working threads.

4. The method according to claim 3, characterized in that The step of determining the initial number of threads according to the ratio comprises: If the ratio is an integer, determining the ratio as the initial number of threads; If the ratio includes a non-zero decimal, the integer of the ratio is increased by one to obtain the initial number of threads.

5. The method according to claim 2 or 3, characterized in that: After the step of sending a transaction processing request to a transaction processing node through the first working thread, wherein the transaction processing request is used to process a transaction request in the transaction request combination, the method further includes: Based on the current network delay time and the number of transaction requests being processed, the initial number of threads of the plurality of working threads is updated.

6. The method according to claim 5, characterized in that The step of updating the initial number of the plurality of working threads based on the current network delay time and the number of transaction requests being processed comprises: During the preset timing duration, every time the second specified time period passes, the following operations are executed cyclically: Get the current network delay time and the number of transaction requests currently being processed; Calculating a ratio of the current network delay time to the first specified time period, and determining a target number of threads according to the ratio; Comparing the target number of threads with the initial number of threads of the plurality of working threads to obtain a comparison result; When the timing duration is reached, the initial number of threads of the plurality of working threads is updated according to the comparison result.

7. The method according to claim 6, characterized in that The step of updating the initial number of threads of the plurality of working threads according to the comparison result comprises: If the comparison results all indicate that the target number of threads is greater than the initial number of threads of the plurality of working threads, and the number of transaction requests currently being processed meets a preset number, increasing the initial number of threads of the plurality of working threads to the target number of threads; If the comparison results all indicate that the target number of threads is less than the initial number of threads of the plurality of working threads, the initial number of threads of the plurality of working threads is reduced to the target number of threads.

8. The method according to claim 7, characterized in that The step of reducing the initial number of threads of the plurality of working threads to the target number of threads comprises: The working threads in the current working state of the multiple working threads are deleted, so that the initial thread number of the multiple working threads after update is consistent with the target thread number.

9. The method according to claim 1, characterized in that: The step of sending a transaction processing request to a transaction processing node through the first working thread, wherein the transaction processing request is used to process a transaction request in the transaction request combination includes: Sending, by means of the first working thread, at least one transaction request in the transaction request combination to a transaction processing node in an asynchronous processing manner, and generating a response message corresponding to each transaction request; Each of the response messages is returned to the client corresponding to the response message.

10. The method according to any one of claims 1-4, 6 to 9, characterized in that: The method further comprises: Based on a third specified time period, periodically obtain the number of threads of the current working thread; If the number of threads of the current working thread is greater than the specified number of threads, the number of threads of the current working thread is reduced to the specified number of threads; wherein the specified number of threads is pre-set according to the performance of the server.

11. The method according to claim 5, characterized in that The method further comprises: Based on a third specified time period, periodically obtain the number of threads of the current working thread; If the number of threads of the current working thread is greater than the specified number of threads, the number of threads of the current working thread is reduced to the specified number of threads; wherein the specified number of threads is pre-set according to the performance of the server.

12. A transaction request processing device, characterized in that: The device is arranged on a server; The server is preset with multiple working threads that can be executed concurrently; the device comprises: An acquisition module, configured to acquire a transaction request combination, and allocate a first working thread to the transaction request combination from the plurality of working threads; wherein the transaction request combination includes at least one transaction request received within a first specified time period; A processing module, configured to send a transaction processing request to a transaction processing node through the first working thread, wherein the transaction processing request is used to process a transaction request in the transaction request combination; Wherein, the server is also preset with a monitoring thread; The acquisition module is further used for: Through the monitoring thread, every time the first specified time period passes, the following operations are cyclically performed: Acquire transaction requests received within the first specified time period, and determine the acquired transaction requests as the transaction request combination; A working thread in an idle state among the multiple working threads is determined as a first working thread, and the transaction request combination is sent to the first working thread.

13. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the transaction request processing method according to any one of claims 1 to 11.

14. A machine-readable storage medium, characterized in that: The machine-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the transaction request processing method according to any one of claims 1 to 11.