CN113268327A - Transaction request processing method and device and electronic equipment - Google Patents

Transaction request processing method and device and electronic equipment Download PDF

Info

Publication number
CN113268327A
CN113268327A CN202110574800.4A CN202110574800A CN113268327A CN 113268327 A CN113268327 A CN 113268327A CN 202110574800 A CN202110574800 A CN 202110574800A CN 113268327 A CN113268327 A CN 113268327A
Authority
CN
China
Prior art keywords
transaction request
thread
transaction
working
threads
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110574800.4A
Other languages
Chinese (zh)
Inventor
干荣亮
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Kingsoft Cloud Network Technology Co Ltd
Original Assignee
Beijing Kingsoft Cloud Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Kingsoft Cloud Network Technology Co Ltd filed Critical Beijing Kingsoft Cloud Network Technology Co Ltd
Priority to CN202110574800.4A priority Critical patent/CN113268327A/en
Publication of CN113268327A publication Critical patent/CN113268327A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4812Task transfer initiation or dispatching by interrupt, e.g. masked
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5018Thread allocation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention provides a processing method and a processing device of a transaction request and electronic equipment, wherein a first working thread is allocated to a transaction request combination from a plurality of working threads which can be executed concurrently; the transaction request combination comprises at least one transaction request received within a first specified time period; and sending the transaction processing request to the transaction processing node through the first working thread so that the transaction processing node processes the transaction request in the transaction request combination. In the method, the transaction request combination comprises all transaction requests received within a certain time period, and the data interaction amount of the transaction processing node can be reduced, and the flow and the calculation pressure of a network and the node can be reduced by a batch processing transaction request mode; in addition, the plurality of working threads are executed concurrently, so that the delay of transaction request processing can be reduced, and the efficiency of request transaction processing is improved.

Description

Transaction request processing method and device and electronic equipment
Technical Field
The present invention relates to the field of distributed system technologies, and in particular, to a method and an apparatus for processing a transaction request, and an electronic device.
Background
In a distributed database system, a global transaction ID is usually assigned to a transaction to be processed to implement global consistent read; for a two-phase distributed database system, the manner in which the global transaction ID is obtained is typically on-demand and on-demand. In each stage, aiming at each transaction request sent by a client, the client is required to perform network interaction with a metadata node so as to obtain a global transaction ID of the transaction request; aiming at the transaction requests of a plurality of clients, the global transaction ID of each transaction request can be obtained only through a plurality of network interactions; when a plurality of clients send a large number of transaction requests to a server, a large flow and a large calculation pressure are caused to metadata nodes of a network and the server, so that the server has a low speed of responding to the client requests, and the performance of distributed transactions is low.
Disclosure of Invention
In view of this, the present invention provides a method, an apparatus, and an electronic device for processing a transaction request, so as to improve the speed of a server responding to a client request, thereby improving the performance of a distributed transaction.
The embodiment of the invention provides a method for processing a transaction request, which is applied to a server; a plurality of working threads which can be executed concurrently are preset in the server; the method comprises the following steps: acquiring a transaction request combination, and distributing a first working thread for the transaction request combination from a 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 the transaction processing node through the first working thread, wherein the transaction processing request is used for processing a transaction request in the transaction request combination.
Furthermore, a monitoring thread is also preset in the server; the method for acquiring the transaction request combination and distributing the first working thread for the transaction request combination from a plurality of working threads comprises the following steps: by monitoring the thread, circularly executing the following operations every time the duration of the first specified time period passes: acquiring a transaction request received in a first designated time period, and determining the acquired transaction request as a transaction request combination; and determining one working thread in an idle state from the plurality of working threads as a first working thread, and sending the transaction request combination to the first working thread.
Further, before the step of obtaining a transaction request combination and allocating a first work thread for the transaction request combination from a plurality of work threads, the method further includes: and determining the initial thread number of the plurality of working threads according to the first designated time period and the initial network delay time.
Further, the step of determining an initial thread count of the plurality of worker 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 appointed time period, and determining the initial thread number according to the ratio; wherein the first specified time period is less than the initial network delay time; the initial thread count is determined as an initial thread count for the plurality of worker threads.
Further, the step of determining the initial number of threads according to the ratio includes: if the ratio is an integer, determining the ratio as an initial thread number; if the ratio includes a fraction that is not zero, the integer of the ratio is incremented by one to obtain the initial thread number.
Further, after the step of sending a transaction request to the transaction processing node through the first work thread, the transaction request being used for processing the transaction request in the transaction request combination, the method further includes: the initial thread number for the plurality of worker threads is updated based on the current network latency time and the number of transaction requests being processed.
Further, the step of updating the initial thread count for the plurality of worker threads based on the current network latency time and the number of transaction requests being processed includes: within the preset timing duration, circularly executing the following operations every time when a second designated time period passes: acquiring the current network delay time and the number of transaction requests currently in a processing state; calculating the ratio of the current network delay time to the first appointed time period, and determining the target thread number according to the ratio; comparing the target thread number with the initial thread number of the plurality of working threads to obtain a comparison result; and when the time length is up, updating the initial thread number of the plurality of working threads according to the comparison result.
Further, the step of updating the initial thread number of the plurality of working threads according to the comparison result includes: if the comparison result indicates that the target thread number is larger than the initial thread number of the plurality of working threads and the number of the currently processed transaction requests meets the preset number, increasing the initial thread number of the plurality of working threads to the target thread number; and if the comparison result indicates that the target thread number is less than the initial thread number of the plurality of working threads, reducing the initial thread number of the plurality of working threads to the target thread number.
Further, the step of reducing the initial thread number of the plurality of working threads to the target thread number includes: and deleting the working threads with idle working states in the plurality of working threads so as to enable the updated initial thread number of the plurality of working threads to be consistent with the target thread number.
Further, the step of sending a transaction request to the transaction processing node through the first work thread, wherein the transaction request is used for processing a transaction request in a transaction request combination, and the step includes: sending at least one transaction request in the transaction request combination to a transaction processing node by a first working thread in an asynchronous processing mode, and generating a response message corresponding to each transaction request; and returning each response message to the client corresponding to the response message.
Further, the method further comprises: based on a third appointed time period, acquiring the thread number of the current working thread at fixed time; if the number of the threads of the current working thread is larger than the number of the designated threads, reducing the number of the threads of the current working thread to the number of the designated threads; wherein the number of the designated threads is preset according to the performance of the server.
The embodiment of the invention also provides a device for processing the transaction request, which is arranged on the server; a plurality of working threads which can be executed concurrently are preset in the server; the device comprises: the system comprises an acquisition module, a processing module and a processing module, wherein the acquisition module is used for acquiring a transaction request combination and distributing a first working thread for the transaction request combination from a plurality of working threads; the transaction request combination comprises at least one transaction request received in a specified time period; and the processing module is used for sending a transaction processing request to the transaction processing node through the first working thread, wherein the transaction processing request is used for processing a transaction request in the transaction request combination.
An embodiment of the present invention further provides an electronic device, which includes a processor and a memory, where the memory stores machine executable instructions capable of being executed by the processor, and the processor executes the machine executable instructions to implement the method for processing the transaction request according to any one of the first aspect.
Embodiments of the present invention also provide a machine-readable storage medium storing machine-executable instructions, which when invoked and executed by a processor, cause the processor to implement a method for processing a transaction request according to any one of the first aspect.
The embodiment of the invention has the following beneficial effects:
the invention provides a method and a device for processing a transaction request and electronic equipment, wherein a transaction request combination is obtained firstly, and a first working thread is distributed for the transaction request combination from a plurality of working threads; wherein the transaction request combination comprises at least one transaction request received within a first specified time period; and then sending a transaction processing request to the transaction processing node through the first working thread, wherein the transaction processing request is used for processing the transaction request in the transaction request combination. In this manner, the transaction request combination may include all transaction requests received within a certain time period, and a work thread is allocated to the transaction request combination from a plurality of concurrently executable work threads, so as to request the transaction processing node to process the transaction request in the transaction request combination. The mode of processing transaction requests in batches can reduce the data interaction amount of transaction processing nodes, thereby reducing the flow and the calculation pressure of a network and the nodes; in addition, the plurality of working threads are executed concurrently, so that the delay of transaction request processing can be reduced, and the efficiency of request transaction processing is improved.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. The objectives and other advantages of the invention will be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings can be obtained by those skilled in the art without creative efforts.
Fig. 1 is a schematic application scenario diagram of a transaction request processing method according to an embodiment of the present invention;
fig. 2 is a flowchart of a method for processing a transaction request according to an embodiment of the present invention;
fig. 3 is an architecture diagram of a specific transaction request processing method according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a transaction request processing apparatus according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
To make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some, but not all embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
At present, when a system is designed and deployed in a distributed environment, there are usually three core requirements, which may also be referred to as CAP theorem, namely Consistency, Availability and Partition Tolerance; consistency represents Consistency, and data on all data nodes have Consistency and correctness; availability represents Availability, ensuring that each request is responsive regardless of success or failure; the Partition Tolerance represents the Partition Tolerance, and the continuous operation of the system cannot be influenced by the loss or failure of any information in the system. Secondly, four isolation levels of database transactions are provided, namely uncommitted reading, committed reading, repeatable reading and serialization respectively; wherein, uncommitted reads indicate that a transaction can read uncommitted data of other transactions; a commit read indicates that multiple query statements for the same transaction may return different results if other transactions modify the corresponding tables during transaction processing; the repeated reading means that the value of the same data is consistent with the starting time of the transaction when the same data is read for multiple times in the transaction processing process, but the ghost data can also appear, namely the same transaction operation is performed, and the results of reading the same data in the front time period and the back time period are different; serialization indicates that all transactions are required to execute serially and not concurrently.
In addition, a distributed transaction includes a two-phase commit, the first phase being the request phase (or prepare phase), i.e., in the request phase, the coordinator will inform the transaction participants about the readiness to commit or cancel the transaction and then enter the voting process. In the voting process, the participants will inform the coordinator of their own decisions: agree (transaction participant local job execution success) or cancel (local job execution failure). The second phase (or commit phase) where the coordinator will make a decision (commit or cancel) based on the voting results of the first phase. All participants are notified by the coordinator to commit the transaction if and only if they agree to commit the transaction, otherwise all participants are notified by the coordinator to cancel the transaction. The participator will execute the responding operation after receiving the message sent by the coordinator.
In distributed database systems, consistency and partition tolerance are typically required to be met, the isolation level of a transaction is typically a commit read or a reread, and the transaction is a two-phase commit; in a distributed database system, a global transaction ID is usually assigned to a transaction to be processed to realize global consistency reading; for a two-phase distributed database system, the manner in which the global transaction ID is obtained is typically on-demand and on-demand. Firstly, opening a transaction; second, get global transaction ID (defined as start _ ts) and execute SQL (Structured Quer)yLanguange); thirdly, acquiring a global transaction ID (defined as prefix _ ts) and entering a request phase; fourth, the global transaction ID (defined as commit _ ts) is obtained and the commit phase is entered. At each stepA segment, for each transaction request sent by a client, requiring the client to perform network interaction with a metadata node to obtain a global transaction ID of the transaction request; aiming at the transaction requests of a plurality of clients, the global transaction ID of each transaction request can be obtained only through a plurality of network interactions; when a plurality of clients send a large number of transaction requests to a server, a large flow and a large calculation pressure are caused to metadata nodes of a network and the server, so that the server has a low speed of responding to the client requests, and the performance of distributed transactions is low.
Based on this, the transaction request processing method, the transaction request processing device and the electronic device provided by the embodiment of the invention can be applied to electronic devices such as servers with distributed database systems.
To facilitate understanding of the present embodiment, a detailed description is given to a method for processing a transaction request disclosed in the present embodiment of the invention, referring first to an application scenario diagram of the method for processing a transaction request shown in fig. 1, where a first electronic device in the diagram may be a client device, and may generally include one or more devices for sending a transaction request; the second electronic device may be a server provided with a thread, and configured to receive or obtain a transaction request sent by the client device; the third electronic device may be a metadata node disposed in the database, and is configured to process the transaction requests sent by the server, send a response message corresponding to each transaction request to the second electronic device, and send the response message to the corresponding client device by the second electronic device.
Fig. 2 is a flow chart of a transaction request processing method, which is applied to a server; a plurality of working threads which can be executed concurrently are preset in the server; the method comprises the following steps:
step S202, acquiring a transaction request combination, and distributing a first working thread for the transaction request combination from a plurality of working threads; wherein the transaction request combination comprises at least one transaction request received within a first specified time period;
the transaction request combination generally comprises a plurality of transaction requests sent by a plurality of clients; the plurality of working threads can be executed concurrently, namely, the received transaction requests can be processed simultaneously; the first worker thread is typically one worker thread that is in an idle state. In actual implementation, one or more transaction requests received in a time period can be obtained in batch every time the first specified time period is passed; after the transaction request combination is obtained, an idle working thread can be selected from the plurality of working threads to serve as a first working thread.
For example, when the number of the plurality of working threads is 4, the first specified time period is 0.5 milliseconds, and the transaction requests are obtained in batch every 0.5 milliseconds, after the transaction request combination is obtained for the first time, because the plurality of working threads are all in an idle state, one working thread can be directly selected from the plurality of working threads as a first working thread; after 0.5 milliseconds passes again, because the network of the server has time delay, if the time delay is 2 milliseconds, the time for processing the transaction request by the first working thread passes by 0.5 milliseconds, so that the 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 working thread can be selected from the remaining three working threads; after 0.5 milliseconds passes again, at this time, the time for the first working thread to process the transaction request passes by 1 millisecond, and the time for the second first working thread to process the transaction request passes by 0.5 millisecond, so that both the first working thread and the second first working thread are still in a state of processing the transaction request, and therefore, after the transaction request combination is obtained for the third time, a third first working thread needs to be selected from the remaining two working threads. When 0.5 millisecond passes again, at this time, the time for the first working thread to process the transaction request passes by 1.5 milliseconds, the time for the second first working thread to process the transaction request passes by 1 millisecond, and the time for the third first working thread to process the transaction request passes by 0.5 millisecond, at this time, the first working thread, the second first working thread, and the third first working thread are all still in a state of processing the transaction request, and at this time, after the transaction request combination is obtained for the third time, a fourth first working thread needs to be selected from the remaining one working thread. When 0.5 millisecond passes again, the time for processing the transaction request by the first working thread at this time passes by 2 milliseconds, the current transaction request is just processed, and the working thread is in an idle state, and the working thread can be directly used as the next first working thread after the transaction request combination is obtained for the fourth time.
Step S204, a transaction processing request is sent to the transaction processing node through the first working thread, and the transaction processing request is used for processing the transaction request in the transaction request combination.
The transaction processing node can be a metadata node, wherein a unique identifier of a global transaction is set; each transaction request may be assigned a corresponding global transaction ID (which may also be referred to as a timestamp) and returned to the client by the first worker thread.
For example, in the example of the step S202, if the number of the preset multiple work threads is 4, the waiting response time of the client is usually only 2 milliseconds or 2.5 milliseconds of the network delay; it can be understood that if the number of the plurality of working threads is 3, the waiting time of the client is usually 2-3 milliseconds; if the number of the working threads is 2, the waiting time of the client is usually 2-3.5 milliseconds; if the number of the plurality of work threads is 1, the waiting time of the client is usually 2-4 milliseconds. Since the plurality of work threads are concurrently executed, the waiting time of the client decreases as the number of the plurality of work threads increases.
The embodiment of the invention provides a processing method of a transaction request, which comprises the steps of firstly obtaining a transaction request combination, and distributing a first working thread for the transaction request combination from a plurality of working threads; wherein the transaction request combination comprises at least one transaction request received within a first specified time period; and then sending a transaction processing request to the transaction processing node through the first working thread, wherein the transaction processing request is used for requesting to process the transaction request in the transaction combination. In this manner, the transaction request combination may include all transaction requests received within a certain time period, and a work thread is allocated to the transaction request combination from a plurality of concurrently executable work threads, so as to request the transaction processing node to process the transaction request in the transaction request combination. The mode of processing transaction requests in batches can reduce the data interaction amount of transaction processing nodes, thereby reducing the flow and the calculation pressure of a network and the nodes; in addition, the plurality of working threads are executed concurrently, so that the delay of transaction request processing can be reduced, and the efficiency of request transaction processing is improved.
The embodiment of the present invention further provides another method for processing a transaction request, which is implemented on the basis of the above embodiment, where this embodiment mainly describes a specific implementation process of a step of acquiring a transaction request combination and allocating a first working thread to the transaction request combination from a plurality of working threads, and a specific implementation process of a step before this step, the method includes the following steps:
step 301, determining the initial thread number of a plurality of working threads according to a first specified time period and initial network delay time;
the first specified time period may be set according to actual needs, for example, 0.5ms, 1 ms, and the like; the initial network latency time generally refers to the round-trip time for a transaction request to be sent from the user's terminal device to the web server and then immediately returned from the web server to the user's terminal device. Of course, during the operation of the system, the initial network delay time may also be changed due to the quality of the network, the size of the request amount, and the like. For example, the initial network delay time is 2 milliseconds, 3 milliseconds, etc.
Step 301, a possible implementation:
calculating the ratio of the initial network delay time to the first appointed time period, and determining the initial thread number according to the ratio; wherein the first specified time period is less than the initial network delay time; the initial thread count is determined as an initial thread count for the plurality of worker threads.
Specifically, if the ratio is an integer, determining the ratio as an initial thread number; if the ratio comprises a decimal number which is not zero, adding one to the integer of the ratio to obtain an initial thread number; for example, the initial network delay time is 2 milliseconds, the first specified time period is 0.5 milliseconds, based on the first specified time period, the transaction request combination is obtained at regular time, and 2ms/0.5ms can be calculated to be 4, that is, the initial thread number is 4; if the initial network delay time is 2.7ms and the first specified time period is 0.5ms, based on the first specified time period, the transaction request combination is obtained at regular time, and 2.7ms/0.5ms may be calculated to be 5.4, and rounding up is performed on 5.4 to obtain an initial thread number of 6.
Wherein, the server is also preset with a monitoring thread; by the listening thread, each time the duration of the first specified time period passes, the following operations of step 302 and step 303 are executed in a loop:
step 302, acquiring a transaction request received in a first specified time period, and determining the acquired transaction request as a transaction request combination;
the above listening thread may also be denoted as a listener thread; the thread has the function of batch processing, namely the function of acquiring transaction requests in batches at regular time. Specifically, a transaction request received in a first specified time period is obtained through a monitoring thread, and the obtained transaction request is determined as a transaction request combination; the received transaction request usually includes a plurality of transaction requests, which may be sent by a plurality of clients. Compared with the mode of independently acquiring each transaction request in sequence, the batch processing mode can reduce the times of network interaction, reduce network delay and improve the performance of distributed transactions.
Step 303, determining one of the plurality of working threads in an idle state as a first working thread, and sending a transaction request combination to the first working thread;
because the plurality of working threads are executed concurrently, after the listening thread receives the transaction request combination, the working thread in an idle state in the plurality of working threads needs to be judged first, if the working thread in the idle state exists, one working thread can be selected to be determined as a first working thread, and the transaction request combination is sent to the first working thread. It should be noted that, in the related art, if there is no working thread in an idle state in the plurality of working threads, it is necessary to wait until the working thread in the idle state occurs, and the transaction request combination may not be sent to the first working thread. Therefore, the step of setting the number of threads of the plurality of working threads can avoid the waiting process in the prior art, and usually at least one working thread in an idle state is available after the transaction request combination is received.
Step 304, a transaction request in the transaction request combination is requested to be processed from the transaction processing node through the first work thread.
In the above manner, according to the first specified time period and the initial network delay time, the initial thread number of the multiple working threads is determined, wherein the determined initial thread number of the multiple working threads can meet the requirement that one working thread in an idle state always exists in the multiple working threads after the monitoring thread obtains the transaction request combination, so that the problem that the transaction request needs to be waited for processing is avoided, the received transaction request can be processed in time, on the premise that the consistency reading function is ensured, the network delay is reduced, the speed of the server side responding to the client side transaction request is improved, and the infringement on the performance of the distributed system is reduced.
An embodiment of the present invention further provides another method for processing a transaction request, where the method is implemented on the basis of the foregoing embodiment, and this embodiment mainly describes a specific implementation process of a step of sending a transaction request to a transaction processing node through a first working thread, where the transaction request is used to process a transaction request in a transaction request combination, and a specific implementation process of the step after the step, and the method includes the following steps:
step 401, acquiring a transaction request combination, and allocating a first working thread for the transaction request combination from a plurality of working threads; wherein the transaction request combination comprises at least one transaction request received within a first specified time period;
step 402, sending at least one transaction request in the transaction request combination to a transaction processing node by a first working thread in an asynchronous processing mode, and generating a response message corresponding to each transaction request; and returning each response message to the client corresponding to the response message.
Specifically, after receiving the transaction request combination, the first working thread sends one transaction request in the transaction request combination to the transaction processing node in an asynchronous processing mode, and sends the next transaction request in the transaction request combination to the transaction processing node concurrently before the transaction processing node returns a response message, so that the transaction processing node allocates a corresponding response message to each transaction request. And finally, returning each response message to the corresponding working thread, and then returning the response message to the corresponding client by the working thread.
Because a server or a system is influenced by a network, a transaction request amount, and the like during operation, an initial network delay time may change, for example, the initial network delay time decreases or increases, at this time, an initial thread number of a plurality of preset working threads may not be suitable for a current working environment, and the initial thread number of the working threads needs to be updated, which includes:
in step 403, the initial thread number of the plurality of working threads is updated based on the current network delay time and the number of transaction requests in the processing state.
Specifically, when the current network delay time and the number of transaction requests in a processing state are both increased, the number of preset initial threads of a plurality of working threads is small, when the monitoring thread obtains a transaction request combination, no working thread in an idle state exists, at this time, waiting is needed, the speed of the server side for responding to the client-side transaction request is reduced, and at this time, the number of threads of the plurality of working threads can be increased according to the current network delay time. In addition, when the current network delay time is reduced and the number of transaction requests in a processing state is reduced, more working threads in an idle state may exist, and the number of the working threads can be reduced according to the network delay time; the method can release system resources in time and meet the requirements of services.
Step 403, a possible real-time method:
within the preset timing duration, circularly executing the following operations every time when a second designated time period passes:
(1) acquiring the current network delay time and the number of transaction requests currently in a processing state;
(2) calculating the ratio of the current network delay time to the first appointed time period, and determining the target thread number according to the ratio;
(3) comparing the target thread number with the initial thread number of the plurality of working threads to obtain a comparison result;
the preset timing time can be 30 seconds, 1 minute, 2 minutes and the like; specifically, the setting may be performed according to a service requirement, and this embodiment is not limited. The second designated time period is usually greater than the first designated time period, for example, 1 second, 2 seconds, and the like, and may be specifically set according to a service requirement, which is not limited in this embodiment.
In actual implementation, in the process that the server is running, the duration of a second specified time period does not pass, and the current network delay time and the number of transaction requests currently in a processing state are obtained; the number of the transaction requests currently in the processing state, that is, the number of the transaction requests currently being processed by each thread; then calculating the ratio of the current network delay time to the first appointed time period, and rounding up the ratio to obtain a target thread number; similar to the above embodiment of step 301, further description is omitted. Finally, comparing the target thread number with the initial thread number of the plurality of working threads to obtain a comparison result; the comparison result generally includes a target thread number greater than the initial thread number of the plurality of worker threads, a target thread number less than the initial thread number of the plurality of worker threads, and a target thread number equal to the initial thread number of the plurality of worker threads.
(4) And when the time length is up, updating the initial thread number of the plurality of working threads according to the comparison result.
Within the preset timing duration, a plurality of comparison results are usually obtained, and when the timing duration is reached, the initial thread number of a plurality of working threads can be increased or decreased according to each comparison result.
When the time length reaches the time length in the step (4), updating the initial thread number of the plurality of working threads according to the comparison result, which is a possible real-time mode:
if the comparison result indicates that the target thread number is larger than the initial thread number of the plurality of working threads and the number of the currently processed transaction requests meets the preset number, increasing the initial thread number of the plurality of working threads to the target thread number;
and if the comparison result indicates that the target thread number is less than the initial thread number of the plurality of working threads, reducing the initial thread number of the plurality of working threads to the target thread number.
The preset number may be set according to service requirements, for example, 0, 1, or other specific numbers. Specifically, when the time length is reached, if each comparison result continuously indicates that the target thread number is greater than the initial thread number of the plurality of working threads and the number of the currently processed transaction requests is not zero, the number of the working threads may be increased so that the thread number of the plurality of working threads is the same as the target thread number. In addition, if each comparison result continuously indicates that the target thread number is greater than the initial thread number of the plurality of working threads and the number of the transaction requests currently being processed is zero, it indicates that the network is currently blocked only and there is no transaction request, and the initial thread number of the plurality of working threads does not need to be updated.
When the time length is reached, if each comparison result continuously indicates that the target thread number is smaller than the initial thread number of the plurality of working threads, the number of the working threads can be reduced, so that the thread number of the plurality of working threads is the same as the target thread number, and system resources are released in time and the requirements of services are met. In addition, if each of the comparison results continuously indicates that the target thread number is equal to the initial thread number of the plurality of worker threads, the thread numbers of the plurality of worker threads are not updated.
The step of reducing the initial thread number of the plurality of working threads to the target thread number includes: and deleting the working threads with idle working states in the plurality of working threads so as to enable the updated initial thread number of the plurality of working threads to be consistent with the target thread number.
When the number of threads in the plurality of working threads is reduced, because part of the working threads are in a working state, the working threads with the current working state being idle can be selected for deletion, so that the updated initial thread number of the plurality of working threads is consistent with the target thread number.
In the above manner, the number of threads of the working threads can be adaptively adjusted to meet the application requirements no matter what the network delay time is. By updating the number of the working threads which send messages concurrently, the concurrent transaction request delay can be effectively reduced, and meanwhile, the performance can be effectively improved in a high-delay high-throughput network. The dynamic adjustment strategy mainly releases system resources in time and meets the requirements of services. In addition, the method reduces the network interaction delay, improves the performance of processing transactions of the distributed system, and has more obvious advantages particularly for the cluster with large network delay of the client and the transaction processing node.
In addition, the method further comprises: based on a third appointed time period, acquiring the thread number of the current working thread at fixed time; if the number of the threads of the current working thread is larger than the number of the designated threads, reducing the number of the threads of the current working thread to the number of the designated threads; wherein the number of the designated threads is preset according to the performance of the server.
The third designated time period may be the same as the second designated time period or greater than the second designated time period. Specifically, if the comparison result indicates that the target thread number is equal to the thread number of the plurality of working threads and the number of the currently processed transaction requests is zero, the thread number of the current working thread is further obtained, whether the thread number of the current working thread is larger than the designated thread number or not is judged, and if the thread number of the current working thread is larger than the designated thread number, the thread number of the current working thread is reduced to the designated thread number to meet the application.
An embodiment of the present invention provides a specific transaction request processing method, as shown in fig. 3, a request message corresponds to the transaction request, and group 1 and group 2 correspond to the transaction request combination; the timestamp request also corresponds to the aforementioned transaction request; the time-stamped response corresponds to the aforementioned response message. The client may be understood as a coordinator in two phases; the listener thread corresponds to the monitoring thread and mainly realizes the batch function, namely the timed batch acquisition request; worker thread 1 and worker thread 2 correspond to the plurality of working threads, and mainly realize a function of concurrent execution. The GTS node is a metadata center. And allocating the global time corresponding to the transaction processing node. Specifically, a listener thread acquires request messages at regular time, the request messages acquired at the same time are combined into a group, such as a group 1 and a group 2 in the figure, and after a batch of requests are acquired, the request messages are sent to a worker thread, specifically, the group 1 can be sent to the worker thread 1, and the group 2 can be sent to the worker thread 2; and carrying out asynchronous interaction with the GTS node through each worker thread to obtain timestamp response, and finally sending a response message corresponding to each request message to a corresponding client.
Corresponding to the above method embodiment, the embodiment of the present invention further provides a device for processing a transaction request, where the device is disposed in a server; a plurality of working threads which can be executed concurrently are preset in the server; as shown in fig. 4, the apparatus includes:
an obtaining module 41, configured to obtain a transaction request combination, and allocate a first working thread to the transaction request combination from among multiple working threads; the transaction request combination comprises at least one transaction request received in a specified time period;
and the processing module 42 is configured to send a transaction processing request to the transaction processing node through the first work thread, where the transaction processing request is used for processing a transaction request in the transaction request combination.
The embodiment of the invention provides a processing device of a transaction request, which comprises the following steps of firstly obtaining a transaction request combination, and distributing a first working thread for the transaction request combination from a plurality of working threads; wherein the transaction request combination comprises at least one transaction request received within a first specified time period; and then sending a transaction processing request to the transaction processing node through the first working thread, wherein the transaction processing request is used for processing the transaction request in the transaction request combination. In the method, at least one transaction request is obtained in batch at the moment when the first specified time period is reached, each transaction request in the transaction request combination is processed through a plurality of concurrently executable working threads, on the premise that a consistent reading function is ensured, the network delay of the transaction requests is reduced, the speed of the server side responding to the client side transaction requests is improved, and the performance of distributed transactions is further improved.
Further, a monitoring thread is also preset in the server; the obtaining module is further configured to: by monitoring the thread, circularly executing the following operations every time the duration of the first specified time period passes: acquiring a transaction request received in a first designated time period, and determining the acquired transaction request as a transaction request combination; and determining one working thread in an idle state from the plurality of working threads as a first working thread, and sending the transaction request combination to the first working thread.
Further, the device further comprises a thread number determining module, configured to determine an initial thread number of the plurality of working threads according to the first specified time period and the initial network delay time.
Further, the thread number determining module is further configured to: calculating the ratio of the initial network delay time to the first appointed time period, and determining the initial thread number according to the ratio; wherein the first specified time period is less than the initial network delay time; the initial thread count is determined as an initial thread count for the plurality of worker threads.
Further, the thread number determining module is further configured to: if the ratio is an integer, determining the ratio as an initial thread number; and if the ratio comprises a decimal number which is not zero, adding one to the integer of the ratio to obtain an initial thread number.
Further, the apparatus further includes a thread number updating module, configured to update an initial thread number of the plurality of working threads based on the current network latency and the number of transaction requests in the processing state.
Further, the thread number updating module is further configured to: within the preset timing duration, circularly executing the following operations every time when a second designated time period passes: acquiring the current network delay time and the number of transaction requests currently in a processing state; calculating the ratio of the current network delay time to the first appointed time period, and determining the target thread number according to the ratio; comparing the target thread number with the initial thread number of the plurality of working threads to obtain a comparison result; and when the time length is up, updating the initial thread number of the plurality of working threads according to the comparison result.
Further, the thread number updating module is further configured to: if the comparison result indicates that the target thread number is larger than the initial thread number of the plurality of working threads and the number of the currently processed transaction requests meets the preset number, increasing the initial thread number of the plurality of working threads to the target thread number; and if the comparison result indicates that the target thread number is less than the initial thread number of the plurality of working threads, reducing the initial thread number of the plurality of working threads to the target thread number.
Further, the thread number updating module is further configured to: and deleting the working threads with idle working states in the plurality of working threads so as to enable the updated initial thread number of the plurality of working threads to be consistent with the target thread number.
Further, the processing module is further configured to: sending at least one transaction request in the transaction request combination to a transaction processing node by a first working thread in an asynchronous processing mode, and generating a response message corresponding to each transaction request; and returning each response message to the client corresponding to the response message.
Further, the above apparatus is further configured to: based on a third appointed time period, acquiring the thread number of the current working thread at fixed time; if the number of the threads of the current working thread is larger than the number of the designated threads, reducing the number of the threads of the current working thread to the number of the designated threads; wherein the number of the designated threads is preset according to the performance of the server.
The processing device for the transaction request provided by the embodiment of the invention has the same technical characteristics as the processing method for the transaction request provided by the embodiment, so that the same technical problems can be solved, and the same technical effects can be achieved.
The embodiment of the invention also provides an electronic device, which comprises a processor and a memory, wherein the memory stores machine executable instructions capable of being executed by the processor, and the processor executes the machine executable instructions to realize the processing method of the transaction request.
Referring to fig. 5, the electronic device includes a processor 100 and a memory 101, where the memory 101 stores machine executable instructions capable of being executed by the processor 100, and the processor 100 executes the machine executable instructions to implement the method for processing the transaction request.
Further, the electronic device shown in fig. 5 further includes a bus 102 and a communication interface 103, and the processor 100, the communication interface 103, and the memory 101 are connected through the bus 102.
The Memory 101 may include a high-speed Random Access Memory (RAM) and may also include a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. The communication connection between the network element of the system 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, a wide area network, a local network, a metropolitan area network, and the like can be used. The bus 102 may be an ISA bus, PCI bus, EISA bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one double-headed arrow is shown in FIG. 5, but this does not indicate only one bus or one type of bus.
Processor 100 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 100. The Processor 100 may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the device can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, a discrete Gate or transistor logic device, or a discrete hardware component. The various methods, steps and logic blocks disclosed in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present invention may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. 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 foregoing embodiment in combination with the hardware thereof.
Embodiments of the present invention also provide a machine-readable storage medium, where the machine-readable storage medium stores machine-executable instructions, and when the machine-executable instructions are called and executed by a processor, the machine-executable instructions cause the processor to implement the method for processing the transaction request.
The method, the apparatus, and the computer program product of the system for processing the transaction request provided in the embodiments of the present invention include a computer-readable storage medium storing a program code, where instructions included in the program code may be used to execute the method described in the foregoing method embodiments, and specific implementation may refer to the method embodiments, and will not be described herein again.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the system and the apparatus described above may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In addition, in the description of the embodiments of the present invention, unless otherwise explicitly specified or limited, the terms "mounted," "connected," and "connected" are to be construed broadly, e.g., as meaning either a fixed connection, a removable connection, or an integral connection; can be mechanically or electrically connected; they may be connected directly or indirectly through intervening media, or they may be interconnected between two elements. The specific meaning of the above terms in the present invention can be understood in specific cases for those skilled in the art.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicate orientations or positional relationships based on the orientations or positional relationships shown in the drawings, and are only for convenience of description and simplicity of description, but do not indicate or imply that the device or element being referred to must have a particular orientation, be constructed and operated in a particular orientation, and thus, should not be construed as limiting the present invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance.
Finally, it should be noted that: although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art will understand that the following embodiments are merely illustrative of the present invention, and not restrictive, and the scope of the present invention is not limited thereto: any person skilled in the art can modify or easily conceive the technical solutions described in the foregoing embodiments or equivalent substitutes for some technical features within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present invention, and they should be construed as being included therein. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (14)

1. A transaction request processing method is applied to a server; a plurality of working threads which can be executed concurrently are preset in the server; the method comprises the following steps:
acquiring a transaction request combination, and distributing a first working thread for 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 for processing a transaction request in the transaction request combination.
2. The method according to claim 1, wherein a listening thread is preset in the server; the step of obtaining the transaction request combination and allocating a first working thread for the transaction request combination from the plurality of working threads comprises:
and circularly executing the following operations by the monitoring thread every time when the duration of the first specified time period passes:
acquiring the transaction request received in the first appointed time period, and determining the acquired transaction request as the transaction request combination;
and determining one working thread in an idle state in the plurality of working threads as a first working thread, and sending the transaction request combination to the first working thread.
3. The method of claim 1, wherein prior to the step of obtaining a transaction request combination and assigning a first worker thread from the plurality of worker threads to the transaction request combination, the method further comprises:
and determining the initial thread number of the plurality of working threads according to the first designated time period and the initial network delay time.
4. The method of claim 3, wherein determining an initial thread count for the plurality of worker threads based on the first specified time period and an initial network latency time comprises:
calculating the ratio of the initial network delay time to the first appointed time period, and determining the initial thread number according to the ratio; wherein the first specified time period is less than the initial network delay time;
determining the initial thread number as an initial thread number of the plurality of worker threads.
5. The method of claim 4, wherein determining the initial number of threads based on the ratio comprises:
if the ratio is an integer, determining the ratio as the initial thread number;
and if the ratio comprises a decimal number which is not zero, adding one to the integer of the ratio to obtain the initial thread number.
6. The method according to claim 3 or 4, wherein a transaction request is sent to a transaction processing node by the first worker thread, and after the step of processing the transaction request in the transaction request combination, the method further comprises:
updating an initial thread number of the plurality of worker threads based on a current network latency time and a number of transaction requests being processed.
7. The method of claim 6, wherein the step of updating the initial thread count for the plurality of worker threads based on the current network latency time and the number of transaction requests being processed comprises:
within the preset timing duration, circularly executing the following operations every time when a second designated time period passes:
acquiring the current network delay time and the number of transaction requests currently in a processing state;
calculating the ratio of the current network delay time to the first appointed time period, and determining the target thread number according to the ratio;
comparing the target thread number with the initial thread number of the plurality of working threads to obtain a comparison result;
and when the time length is reached, updating the initial thread number of the plurality of working threads according to the comparison result.
8. The method of claim 7, wherein updating the initial thread count for the plurality of worker threads based on the comparison comprises:
if the comparison result indicates that the target thread number is larger than the initial thread number of the plurality of working threads and the number of the currently processed transaction requests meets a preset number, increasing the initial thread number of the plurality of working threads to the target thread number;
and if the comparison result indicates that the target thread number is less than the initial thread number of the plurality of working threads, reducing the initial thread number of the plurality of working threads to the target thread number.
9. The method of claim 8, wherein the step of reducing the initial number of threads of the plurality of worker threads to the target number of threads comprises:
and deleting the working threads with idle working states in the plurality of working threads so as to enable the updated initial thread number of the plurality of working threads to be consistent with the target thread number.
10. The method according to claim 1, wherein the step of sending a transaction request to a transaction processing node through the first work thread, the transaction request being used for processing a transaction request in the transaction request combination, comprises:
sending at least one transaction request in the transaction request combination to a transaction processing node by the first working thread in an asynchronous processing mode, and generating a response message corresponding to each transaction request;
and returning each response message to the client corresponding to the response message.
11. The method according to any one of claims 1-10, further comprising:
based on a third appointed time period, acquiring the thread number of the current working thread at fixed time;
if the number of the threads of the current working thread is larger than the number of the designated threads, reducing the number of the threads of the current working thread to the number of the designated threads; wherein the specified thread number is preset according to the performance of the server.
12. The transaction request processing device is characterized in that the device is arranged on a server; a plurality of working threads which can be executed concurrently are preset in the server; the device comprises:
the acquisition module is used for acquiring a transaction request combination and distributing a first working thread for the transaction request combination from the plurality of working threads; wherein the transaction request combination comprises at least one transaction request received within a specified time period;
and the processing module is used for sending a transaction processing request to a transaction processing node through the first working thread, wherein the transaction processing request is used for processing a transaction request in the transaction request combination.
13. An electronic device comprising a processor and a memory, the memory storing machine executable instructions executable by the processor, the processor executing the machine executable instructions to implement the method of processing transaction requests of any of claims 1 to 11.
14. A machine-readable storage medium having stored thereon machine-executable instructions which, when invoked and executed by a processor, cause the processor to implement a method of processing a transaction request as claimed in any of claims 1 to 11.
CN202110574800.4A 2021-05-25 2021-05-25 Transaction request processing method and device and electronic equipment Pending CN113268327A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110574800.4A CN113268327A (en) 2021-05-25 2021-05-25 Transaction request processing method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110574800.4A CN113268327A (en) 2021-05-25 2021-05-25 Transaction request processing method and device and electronic equipment

Publications (1)

Publication Number Publication Date
CN113268327A true CN113268327A (en) 2021-08-17

Family

ID=77233021

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110574800.4A Pending CN113268327A (en) 2021-05-25 2021-05-25 Transaction request processing method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN113268327A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114866556A (en) * 2022-05-25 2022-08-05 上海众源网络有限公司 Server resource request method and device, electronic equipment and storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114866556A (en) * 2022-05-25 2022-08-05 上海众源网络有限公司 Server resource request method and device, electronic equipment and storage medium
CN114866556B (en) * 2022-05-25 2024-04-19 上海众源网络有限公司 Server resource request method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN110489447B (en) Data query method and device, computer equipment and storage medium
CN110519183B (en) Node speed limiting method and device, electronic equipment and storage medium
CN112118315A (en) Data processing system, method, device, electronic equipment and storage medium
CN110224943B (en) Flow service current limiting method based on URL, electronic equipment and computer storage medium
WO2021238796A1 (en) Asynchronous processing method, apparatus, and system for download tasks, and storage medium
WO2020019743A1 (en) Traffic control method and device
CN108574645B (en) Queue scheduling method and device
JPWO2018220708A1 (en) Resource allocation system, management device, method and program
CN109173270B (en) Game service system and implementation method
CN111427670A (en) Task scheduling method and system
CN111371585A (en) Configuration method and device for CDN node
CN113268327A (en) Transaction request processing method and device and electronic equipment
CN110324262A (en) A kind of method and device that resource is seized
CN111857992B (en) Method and device for allocating linear resources in Radosgw module
CN110955460B (en) Service process starting method and device, electronic equipment and storage medium
CN111831408A (en) Asynchronous task processing method and device, electronic equipment and medium
WO2011035608A1 (en) Data query system and constructing method thereof and corresponding data query method
CN109032779B (en) Task processing method and device, computer equipment and readable storage medium
CN111008071A (en) Task scheduling system, method and server
CN116074332A (en) Mirror image management method, distributed system, electronic equipment and medium
CN113835905B (en) Message queue load balancing method and device, electronic equipment and medium
CN110912958A (en) HTTP connection processing method, device, equipment and medium
CN114866395A (en) Multi-component distributed consistency protocol cluster heartbeat communication method and device
CN114443274A (en) Method, device and readable storage medium for adjusting thread number in micro-service thread pool
CN110046040B (en) Distributed task processing method and system and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination