Method, apparatus, electronic device, and storage medium for processing concurrent services
By establishing a cache queue for service objects in online financial transactions and using zookeeper and CountDownLatch to manage thread state, the bottlenecks and deadlock problems caused by concurrent transactions of multiple objects are solved, the throughput and response rate of the service system are improved, and the user experience is improved.
Patent Information
- Application Number
- CN202210186146.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-28
- Publication Date
- 2025-07-22
- Estimated Expiration
- 2042-02-28
AI Technical Summary
In online financial transactions, when multiple objects transfer money at the same time or are transferred, it is easy to lead to bottlenecks and deadlocks of concurrent transactions, affecting the throughput and response rate of the service system.
By establishing a service cache queue, creating a corresponding cache queue for each service object, and queuing the service identification information as a queue element. Only when all queue headers are corresponding identification information are the corresponding identification information are used to manage thread status using zookeeper and CountDownLatch mechanisms to avoid deadlocks.
It improves the throughput and concurrency of the service system, enhances the system robustness, and improves the response rate and user experience of service requests.
Smart Images

Figure CN114565381B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of financial technology, and in particular, to a method, apparatus, electronic device, and storage medium for processing concurrent services. Background Art
[0002] With the rise and reform of fintech, more and more online financial transactions replace traditional offline paper currency transactions, and various scenarios of offline transactions urgently need to be realized online. In the online financial transaction scenario, financial transactions such as transfer and consumption among a large number of objects are becoming more and more common. For example, transfers in real life, payments to merchants, consumption scenarios, etc. all involve mutual transfers among multiple objects.
[0003] However, in the face of the current demand for high-concurrency online transactions, situations such as multiple objects transferring money to one object simultaneously, or the transferred object initiating a transfer to another party simultaneously may often occur. Therefore, it may lead to bottleneck problems caused by a large number of multi-object concurrent transactions and deadlock problems caused by multi-object mutual queuing. Summary of the Invention
[0004] Embodiments of the present invention provide a method, apparatus, electronic device, and storage medium for processing concurrent services to achieve orderly processing of high-concurrency services.
[0005] In a first aspect, an embodiment of the present invention provides a method for processing concurrent services, the method comprising:
[0006] When receiving a service request associated with at least two service objects, determining whether a service cache queue has been created for the service objects associated with the service request;
[0007] If not, respectively establishing corresponding service cache queues based on the service objects, and putting the service identification information corresponding to the service request into the service cache queues as queue elements for queuing;
[0008] When the first elements of the service cache queues of the service objects associated with the service request are both the service identification information corresponding to the service request, responding to the service request and executing the target service corresponding to the service request.
[0009] In a second aspect, an embodiment of the present invention further provides a device for processing concurrent services, the device comprising:
[0010] A request receiving module, configured to determine whether a service cache queue has been created for the service objects associated with the service request when receiving a service request associated with at least two service objects;
[0011] A queue establishment module, which is used to, if the answer is no, establish corresponding service cache queues based on service objects respectively, and put the service identification information corresponding to the service request into the service cache queues as queue elements respectively for queuing;
[0012] A service execution module, which is used to, when the first elements of the service cache queues of the service objects associated with the service request are all the service identification information corresponding to the service request, respond to the service request and execute the target service corresponding to the service request.
[0013] In a third aspect, an embodiment of the present invention further provides an electronic device, which includes:
[0014] One or more processors;
[0015] A storage device, which is used to store one or more programs,
[0016] When the one or more programs are executed by the one or more processors, the one or more processors implement the processing method for concurrent services provided by any embodiment of the present invention.
[0017] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the processing method for concurrent services provided by any embodiment of the present invention is implemented.
[0018] The technical solution of the embodiment of the present invention, when receiving a service request associated with at least two service objects, determines whether a service cache queue has been created for the service objects associated with the service request. If the answer is no, corresponding service cache queues are established based on the service objects respectively, and the service identification information corresponding to the service request is put into the service cache queues as queue elements respectively for queuing. When the first elements of the service cache queues of the service objects associated with the service request are all the service identification information corresponding to the service request, the service request is responded to and the target service corresponding to the service request is executed, solves the bottleneck problem caused by a large number of concurrent transactions of multiple objects and the deadlock problem of multiple objects queuing up for each other in the prior art, such as when multiple objects transfer money to one object at the same time, or the transferred object transfers money to another party at the same time, etc., realizes the beneficial effect of effectively improving the service throughput and concurrency of the service system, further enhances the robustness and concurrency of the service system, improves the response rate of service requests, and improves the user experience. Description of the Drawings
[0019] To more clearly illustrate the technical solutions of the exemplary embodiments of the present invention, the accompanying drawings required for describing the embodiments will be briefly introduced below. Obviously, the accompanying drawings introduced are only the drawings of a part of the embodiments to be described by the present invention, rather than all the drawings. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings without creative efforts.
[0020] Figure 1 Schematic flowchart of a method for processing concurrent services provided in the first embodiment of the present invention;
[0021] Figure 2 Schematic diagram of concurrent service requests in an application scenario provided in the first embodiment of the present invention;
[0022] Figure 3 Schematic diagram of the establishment effect of a service cache queue in an application scenario provided in the first embodiment of the present invention;
[0023] Figure 4 Schematic diagram of the deadlock situation of service objects in an application scenario provided in the first embodiment of the present invention;
[0024] Figure 5 Schematic diagram of a solution to the deadlock situation in an application scenario provided in the first embodiment of the present invention;
[0025] Figure 6 Schematic flowchart of a method for processing concurrent services provided in the second embodiment of the present invention;
[0026] Figure 7 Schematic diagram of a method for processing concurrent services in an application scenario provided in the second embodiment of the present invention;
[0027] Figure 8 Schematic diagram of a method for processing concurrent services in an application scenario provided in the second embodiment of the present invention;
[0028] Figure 9 Schematic flowchart of a method for processing concurrent services provided in the third embodiment of the present invention;
[0029] Figure 10 Schematic flowchart of a method for processing concurrent services provided in the third embodiment of the present invention;
[0030] Figure 11 Schematic diagram of the structure of a device for processing concurrent services provided in the fourth embodiment of the present invention;
[0031] Figure 12 Schematic diagram of the structure of an electronic device provided in the fifth embodiment of the present invention. Detailed implementation manners
[0032] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It can be understood that the specific embodiments described herein are only used to explain the present invention, rather than limiting the present invention. Additionally, it should be noted that for ease of description, only parts related to the present invention rather than all structures are shown in the drawings.
[0033] It should also be noted that for ease of description, only parts related to the present invention rather than all content are shown in the drawings. Before discussing the exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe the operations (or steps) as sequential processes, many of the operations can be performed in parallel, concurrently, or simultaneously. In addition, the order of the operations can be rearranged. The process can be terminated when its operations are completed, but it can also have additional steps not included in the drawings. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0034] Embodiment 1
[0035] Figure 1 As shown in the flowchart of a processing method for concurrent services provided by Embodiment 1 of the present invention, this embodiment is applicable to the situation where a large number of concurrent services are carried out simultaneously. This method can be executed by a processing device for concurrent services, and this device can be implemented through software and / or hardware, and can be configured in a terminal and / or a server to implement the processing method for concurrent services in the embodiments of the present invention.
[0036] As Figure 1 shown, the method of this embodiment can specifically include:
[0037] S110. When receiving a service request associated with at least two service objects, determine whether a service cache queue has been created for the service objects associated with the service request.
[0038] Among them, a service object can be understood as an object that needs to be served. Exemplarily, a service object can be a customer, a user, or other objects that need to be helped, etc. For example, a service object can be a trading account. Correspondingly, a service request can be an instruction or code information generated by the service object when requesting a corresponding service. A service cache queue can be a database used to store request information during the transmission of a service request. For example, a service cache queue can be Redis.
[0039] In a specific implementation, a user can trigger an operation on a target service through an application program displayed on a service terminal. After the service terminal detects the target service trigger operation, it triggers a service request. When receiving and detecting that the service request is associated with at least two service objects, it determines whether to create a service cache queue for the service objects associated with the service request, so as to determine the response process of the service request according to the judgment result.
[0040] It should be noted that when the service object associated with the received service request is one, there is no need to determine whether the service object associated with the service request has created a service cache queue, and the service request can be directly responded to, and the target service corresponding to the service request can be executed.
[0041] S120. If not, corresponding service cache queues are established based on the service objects respectively, and the service identification information corresponding to the service request is used as queue elements and put into the service cache queues respectively for queuing.
[0042] Among them, the service identification information can be the identification information used to identify the current state of the service request. For example, when the service request is a transfer transaction, the service identification information can be key information such as the transaction serial number, the transferor and transferee accounts, and the amount.
[0043] Optionally, for the same service object, there may be one service request associated with it, or there may be multiple service requests associated with it within a certain period of time. Correspondingly, there may be one service identification information in the service cache queue of the service object, or there may be multiple service identification information. When multiple service identification information needs to be used as queue elements and put into the service cache queue for queuing, the corresponding service identification information can be put into the service cache queue according to the time sequence of receiving the service request. To more clearly introduce the above technical solution, a specific application scenario can be used as an example to illustrate, such as Figure 2 As shown, for example, A - E are 5 trading accounts. Transaction 1 represents that account A transfers money to account B, and at the same time account B transfers money to account C to generate transaction 2, account C transfers money to account D to generate transaction 3, account D transfers money to account A to generate transaction 4, and account E transfers money to account D to generate transaction 5. The above transactions 1 - 5 occur simultaneously. Further, Redis queues are established for the 5 trading accounts A - E respectively, and the specific establishment result can be as Figure 3 As shown, 5 queues are established in Redis, and the elements in the queue are the transaction identification information of each transaction. For example, when account A transfers money to account B and generates transaction 1, the transaction identification information of transaction 1 will be added to the queues of both accounts A and B for queuing. Similarly, when account D transfers money to account A and generates transaction 4, the transaction identification information of transaction 4 will be added to the queues of both accounts A and D for queuing, etc.
[0044] In a specific implementation, if the service cache queue for the service object associated with the service request has not been created, corresponding service cache queues are established based on the service objects respectively, and the service identification information used to identify the service request is used as queue elements and placed in the service cache queues respectively for queuing. The advantage of this setting is that: the service requests establish their respective service cache queues according to the service objects, and the service identification information corresponding to the service requests is placed in the queues, so that the service cache queues are service objects that are mutually associated and have a close coupling of services.
[0045] S130. When the first elements of the service cache queues of the service objects associated with the service request are all the service identification information corresponding to the service request, the service request is responded to and the target service corresponding to the service request is executed.
[0046] Among them, the target service can be the service that the service terminal needs to execute at the current moment. For example, the target service can be a transfer service.
[0047] In a specific implementation, before responding to the service request, it is necessary to determine that the first elements of the service cache queues of all service objects associated with the service request are all the service identification information corresponding to the service request. When the first elements of the service cache queues are all the service identification information corresponding to the service request, the service request can be responded to and the target service corresponding to the service request can be executed.
[0048] Optionally, when there are two service objects associated with the service request, when the first elements of the service cache queues of the two service objects are both the service identification information corresponding to the service request, the service request is responded to. For example, when the service request is a transfer from account A to account B, the associated service objects are account A and account B. When the first elements of the service cache queues of account A and account B are both the identification information corresponding to the transfer request, the transfer request is responded to and the transfer transaction is executed. Or, when there are three service objects associated with the service request object, when the first elements of the service cache queues of the three service objects are all the service identification information corresponding to the service request, the service request is responded to. For example, account A transfers to account B and involves account C subsidizing or giving preferential treatment to account A, that is, at the same moment, both account A and account C need to transfer to account B. The service relationship associated with this transfer request includes account A, account B, and account C. When the first elements of the service cache queues of account A, account B, and account C are all the identification information corresponding to the transfer request, the transfer request is responded to and the transfer transaction is executed.
[0049] Based on the above technical solution, it further includes: when it is detected that the service identification information at the first position of the service cache queues of the associated service objects does not meet the service execution conditions, the service identification information at the first position of the service cache queue is moved backward in position.
[0050] Among them, the service execution condition can be a pre-set condition for determining whether a service can be executed. In this embodiment, the service execution condition can be whether the service identification information corresponding to the service request is all at the head of the service cache queues of all associated service objects.
[0051] Specifically, when it is detected that the service identification information at the head of the service cache queues of each associated service object does not meet the service execution condition, the service identification information at the head needs to be moved backward in position so that the service identification information in the service cache queue can be executed in an orderly manner. To clearly introduce the specific implementation of this technical solution, it can be illustrated through a specific application scenario. The specific situation can be as Figure 4 shown. For example, two accounts A and B conduct a mutual transfer transaction at the same time, that is, account A generates transaction 1 for account B, and account B generates transaction 2 for account A. When entering the Redis queue, the following queuing situation occurs. The identification information corresponding to transaction 1 is at the head of the queue of account A, and the identification information corresponding to transaction 2 is at the head of the queue of account B. Since the identification information corresponding to transaction 1 is not at the head of the queue of account B, transaction 1 cannot be executed. At the same time, since the identification information corresponding to transaction 2 is not at the head of the queue of account A, transaction 2 cannot be executed either. Therefore, a situation of mutual waiting occurs. Similar to transaction 1 occupying the lock of account A while waiting for the lock of account B, and transaction 2 occupying the lock of account B while waiting for the lock of account A, this will cause A and B to wait for each other's locks, resulting in a deadlock situation. When it is detected that the above situation occurs, the identification information corresponding to transaction 1 can be moved one position backward in the queue of account A so that the identification information corresponding to transaction 2 can be at the head of the queue of account A. At the same time, the head of the queue of account B is also the identification information corresponding to transaction 2, meeting the service execution condition, and the target service corresponding to transaction 2 can be executed. The specific implementation of solving the above deadlock situation can be as Figure 5 shown.
[0052] In the technical solution of the embodiment of the present invention, when a service request associated with at least two service objects is received, it is determined whether a service cache queue has been created for the service objects associated with the service request. If not, corresponding service cache queues are established based on the service objects respectively, and the service identification information corresponding to the service request is used as queue elements and placed in the service cache queues respectively for queuing. When the service identification information corresponding to the service request is at the head of the service cache queues of all the service objects associated with the service request, the service request is responded to, and the target service corresponding to the service request is executed. This solves the bottleneck problem caused by a large number of concurrent transactions of multiple objects, such as when multiple objects transfer money to one object at the same time, or when the transferee object transfers money to another party at the same time, and the deadlock problem caused by multiple objects queuing up with each other, achieving the beneficial effect of effectively improving the service throughput and concurrency of the service system, further enhancing the robustness and concurrency of the service system, improving the response rate of service requests, and enhancing the user experience.
[0053] Embodiment 2
[0054] Figure 6 As shown in the flowchart of a method for processing concurrent services provided by Embodiment 2 of the present invention, on the basis of the above technical solution, this embodiment further refines the technical solution. Optionally, on the basis of any optional technical solution in the embodiment of the present invention, after the service identification information corresponding to the service request is used as queue elements and placed in the service cache queues respectively for queuing, it further includes: determining whether the service identification information corresponding to the service request is at the head of the service cache queues of all the service objects associated therewith; if not, setting a monitoring node for the service identification information and setting a thread blocking and waking mechanism for the service identification information; if so, responding to the service request and executing the target service corresponding to the service request.
[0055] Among them, the same or similar technical terms and technical features as those in the foregoing embodiments are not described herein again.
[0056] As Figure 6 shown, the method of this embodiment may specifically include:
[0057] S210. When a service request associated with at least two service objects is received, determine whether a service cache queue has been created for the service objects associated with the service request. If not, execute S220; if so, execute S230.
[0058] S220. Establish corresponding service cache queues based on the service objects respectively, and use the service identification information corresponding to the service request as queue elements and place them in the service cache queues respectively for queuing.
[0059] S230. Determine whether the service identification information corresponding to the service request is at the head of the service cache queues of all associated service objects. If not, execute S240; if so, execute S250.
[0060] In a specific implementation, after the service identification information corresponding to the service request is placed in the service cache queue for queuing, it is also necessary to determine whether the service identification information is at the head of the service cache queues of all associated service objects, so as to determine the response process of the service request according to the judgment result.
[0061] S240. Set a listening node for the service identification information, and set a thread blocking and waking mechanism for the service identification information, then execute S260.
[0062] Among them, the listening node can be understood as a node used to implement the listening function. The thread blocking and waking mechanism can take the service identification information as a thread, and through this mechanism, the thread can be in a waiting state or woken up to continue thread processing.
[0063] Optionally, setting a listening node for the service identification information and setting a thread blocking and waking mechanism for the service identification information includes: creating a zookeeper node based on the service identification information through zookeeper, and setting a thread blocking and waking mechanism for the service identification information through CountDownLatch; when the zookeeper node monitors that the node state of the zookeeper node corresponding to the service identification information changes, reduce the semaphore of CountDownLatch, and when it is detected that the semaphore reaches the preset wake-up threshold, wake up the service request corresponding to the service identification information and execute it.
[0064] Among them, Zookeeper (a distributed application coordination service component) can be software that provides consistency services for distributed applications. Zookeeper can be used for distributed application configuration management, unified naming service, status synchronization service, cluster management, etc. Zookeeper can include a file system and a listening and notification mechanism. Correspondingly, a Zookeeper node is used to mark the response status of a service request corresponding to service identification information. The response status can include an active state and an inactive state. CountDownLatch can be a synchronization utility class in Zookeeper, which allows one or more threads to wait until other threads finish execution before executing. CountDownLatch can implement thread blocking and waking up through a semaphore counter, and the initial value of the semaphore is the number of threads. Correspondingly, the initial value of the semaphore of CountDownLatch is greater than 0. Optionally, the initial value of the semaphore is set based on the number of service objects that are not at the head of the service cache queue when the service identification information based on the service request is placed in the service cache queue. For example, when the service identification information corresponding to the service request is placed in the service cache queue, if the number of service objects in the service cache queue associated with the service request whose head is not the service identification information corresponding to the service request is 2, the initial value of the semaphore is set to 2. The preset wake-up threshold can be a preset maximum value of the semaphore used to implement the wake-up function. For example, the preset wake-up threshold can be 0.
[0065] Exemplarily, to clearly introduce the specific implementation of this step, it can be illustrated through a specific application scenario, such as Figure 7 As shown, when transaction 1 of transferring money from account A to account B is being executed, transaction 2 of transferring money from account B to account C will queue in the transaction queues of account B and account C and be in a blocked waiting state.
[0066] Optionally, when a Zookeeper node monitors a change in the node state of a Zookeeper node corresponding to service identification information, it includes: after the service request corresponding to the service identification information at the head of the service cache queue finishes execution, detecting the next Zookeeper node in the service cache queue and updating the node state of the detected Zookeeper node.
[0067] In practical applications, when the service request corresponding to the service identification information at the head of the service cache queue is executed and completed, the service identification information dequeues from the service cache queue. Moreover, when dequeuing, each Zookeeper node established in Zookeeper based on the service identification information is used to determine the next Zookeeper node in the service cache queue, and the node state of this Zookeeper node is updated from inactive to active. The advantage of this setting is that: after the service is executed and completed, only the Zookeeper node corresponding to this service needs to be deleted, and the number of nodes to be deleted is less, thus the processing efficiency is higher.
[0068] In a specific implementation, when it is determined that the service identification information corresponding to the service request is not at the head of all associated service objects, a Zookeeper node with a listening function is created in Zookeeper based on the service identification information, and the service request corresponding to this service identification information is blocked through the thread blocking and wake-up mechanism of CountDownLatch. When the Zookeeper node monitors that the node state of the Zookeeper node corresponding to the service identification information changes from pending activation to active, the semaphore of CountDownLatch is decreased. When it is detected that the semaphore decreases to the preset wake-up threshold, the service request corresponding to the service identification information is awakened and executed. The advantage of this setting is that: creating nodes directly based on the service identification information corresponding to each service request can achieve a simpler and more efficient processing effect. Moreover, by controlling the process of the service identification information through CountDownLatch, concurrent service requests can be executed sequentially, which improves the execution efficiency of service requests to a certain extent.
[0069] Exemplarily, to clearly introduce the specific implementation manner of this technical solution, the above example is continued to illustrate it. As Figure 7 shown, when transaction 1 dequeues from the transaction queue of account A, the node state of the Zookeeper node of transaction 4 in this transaction queue is updated from pending activation to active, and the semaphore of CountDownLatch is decreased. Since transaction 4 is not at the head of the queue in the queue of another corresponding account D, transaction 4 cannot be awakened; when transaction 1 dequeues from the transaction queue of account B, transaction 2 in the transaction queue of account B will be at the head in the queues of the two involved accounts (C and D). Therefore, after transaction 1 dequeues, the node state of the Zookeeper node of transaction 2 is updated. When the Zookeeper node monitors that the node state changes, the semaphore of CountDownLatch is decreased, and transaction 2 is reawakened to continue completing the transfer request of transaction 2.
[0070] S250. Respond to the service request and execute the target service corresponding to the service request.
[0071] Specifically, if the service identification information corresponding to the service request is at the head of the service cache queue of all associated service objects, the service request can be responded to and the target service corresponding to the service request can be executed.
[0072] Exemplarily, continue to use the above application scenario to illustrate this step. For example, Figure 8 As shown, for the transaction queues of account A and account B, when it is detected that transaction 1 is at the head of both queues, this transaction can directly lock these two accounts and directly process this transaction.
[0073] S260. When the head of the service cache queue of the service object associated with the service request is the service identification information corresponding to the service request, respond to the service request and execute the target service corresponding to the service request.
[0074] Based on the above technical solution, it further includes: listening to the queuing time of the service identification information in the queue through the zookeeper node. If the queuing time exceeds the preset time threshold, delete the zookeeper node corresponding to the service identification information and return the service requested by the service request corresponding to the service identification information.
[0075] Among them, the preset time threshold can be the maximum queuing time of the service identification information in the service cache queue set in advance.
[0076] In practical applications, when the service identification information corresponding to the service request is put into the service cache queue for queuing and the zookeeper node is established based on the service identification information through the zookeeper, the queuing time of the corresponding service identification information in the service cache queue can also be listened to through the zookeeper node. If it is detected that the time of the service identification information in the service cache queue exceeds the preset maximum queuing time, the zookeeper node corresponding to this service identification information needs to be deleted and the service request corresponding to this service identification information is forced to return. The advantage of such a setting is that it can perform timeout processing on the service identification information in the service cache queue to improve the processing efficiency of the service request.
[0077] In the technical solution of the embodiment of the present invention, when a service request associated with at least two service objects is received, it is determined whether a service cache queue has been created for the service object associated with the service request. If not, corresponding service cache queues are established based on the service objects respectively, and the service identification information corresponding to the service request is used as queue elements and put into the service cache queues respectively for queuing. Then, it is judged whether the service identification information corresponding to the service request is at the head of the service cache queues of all associated service objects. If not, a listening node is set for the service identification information, and a thread blocking and wake-up mechanism is set for the service identification information, so that concurrent service requests can be executed sequentially, thereby achieving a higher processing efficiency. If so, the service request is responded to, and the target service corresponding to the service request is executed. When the service identification information corresponding to the service request is at the head of the service cache queues of all service objects associated with the service request, the service request is responded to, and the target service corresponding to the service request is executed. This solves the bottleneck problem caused by a large number of concurrent transactions of multiple objects, such as when multiple objects transfer money to one object at the same time, or when the transferred object transfers money to another party at the same time, and the deadlock problem caused by multiple objects queuing up with each other, achieving the effects of simplifying the service request processing process and higher processing efficiency. Moreover, it can also make concurrent service requests executed sequentially, improving the execution efficiency of service requests to a certain extent.
[0078] Embodiment III
[0079] Figure 9 and Figure 10 FIG. is a schematic flowchart of a method for processing concurrent services provided by Embodiment III of the present invention. The embodiment of the present invention is a preferred embodiment of the above-mentioned embodiments of the present invention. As Figure 9 and Figure 10 shown, taking the service request as a transaction request and the service cache queue as Redis as an example, the embodiment of the present invention may include a transaction enqueueing process and a transaction dequeueing process.
[0080] See Figure 9 shown, the method for transaction enqueueing in the embodiment of the present invention may include the following steps;
[0081] 1. Receive a transaction request;
[0082] 2. Determine whether a queue has been created in Redis for the transaction account associated with the transaction request;
[0083] 3. If not, create corresponding queues based on the transaction accounts respectively; if so, execute step 4;
[0084] 4. Put the transaction identification information corresponding to the transaction request into the corresponding account queues respectively;
[0085] 5. Check whether the transaction identification information corresponding to the transaction request is at the top of the queue of all associated transaction accounts;
[0086] 6. If no, create a zookeeper node based on the transaction identification information and listen through zookeeper; if yes, execute the transaction directly.
[0087] 7. Block the transaction process through CountDownLatch to keep the transaction in a state of waiting for wake-up.
[0088] See also Figure 10 As shown, the method for trading out of a queue in an embodiment of the present invention may include the following steps:
[0089] 1. When the previous transaction request is executed, its corresponding transaction identification information is dequeued from Redis;
[0090] 2. Check whether the transaction identification information corresponding to the next transaction request in the queue meets the transaction conditions;
[0091] 3. If yes, update the node status of the zookeeper node; if no, move the transaction identification information that does not meet the transaction conditions backward and continue to check the transaction identification information corresponding to the next transaction request;
[0092] 4. When the zookeeper node monitors the node status, it releases the CountDownLatch blocking the transaction so that the transaction can continue to execute.
[0093] The technical solution of the embodiment of the present invention is to determine whether the service object associated with the service request has created a service cache queue when a service request associated with at least two service objects is received. If not, corresponding service cache queues are established based on the service objects, and service identification information corresponding to the service request is placed in the service cache queue as a queue element for queuing. When the first element of the service cache queue of the service object associated with the service request is the service identification information corresponding to the service request, the service request is responded to and the target service corresponding to the service request is executed. The bottleneck problem caused by a large number of concurrent transactions of multiple objects due to multiple objects transferring money to one object at the same time, or the transferred object transferring money to another party at the same time in the prior art, and the deadlock problem caused by multiple objects queuing with each other are solved, and the beneficial effect of effectively improving the service throughput and concurrency of the service system is achieved, the robustness and concurrency of the service system are further enhanced, the response rate of service requests is improved, and the user experience is improved.
[0094] Embodiment 4
[0095] Figure 11A structural schematic diagram of a processing device for concurrent services provided in Embodiment 4 of the present invention. The processing device for concurrent services provided in this embodiment can be implemented by software and / or hardware, and can be configured in a terminal and / or a server to implement the processing method for concurrent services in the embodiments of the present invention. The device specifically may include: a request receiving module 310, a queue establishing module 320, and a service executing module 330.
[0096] Among them, the request receiving module 310 is configured to determine whether a service cache queue has been created for a service object associated with a service request when receiving a service request associated with at least two service objects.
[0097] The queue establishing module 320 is configured to, if not, respectively establish corresponding service cache queues based on the service objects, and place the service identification information corresponding to the service request as queue elements into the service cache queues respectively for queuing.
[0098] The service executing module 330 is configured to, when the first positions of the service cache queues of the service objects associated with the service request are all the service identification information corresponding to the service request, respond to the service request and execute the target service corresponding to the service request.
[0099] The technical solution of the embodiment of the present invention, by determining whether a service cache queue has been created for a service object associated with a service request when receiving a service request associated with at least two service objects, if not, respectively establishing corresponding service cache queues based on the service objects, and placing the service identification information corresponding to the service request as queue elements into the service cache queues respectively for queuing, when the first positions of the service cache queues of the service objects associated with the service request are all the service identification information corresponding to the service request, responding to the service request and executing the target service corresponding to the service request, solves the bottleneck problem caused by a large number of concurrent transactions of multiple objects and the deadlock problem of mutual queuing of multiple objects in the prior art, such as when multiple objects transfer money to one object at the same time, or the transferred object transfers money to another party at the same time, etc., realizes the beneficial effect of effectively improving the service throughput and concurrency of the service system, further enhances the robustness and concurrency of the service system, improves the response rate of service requests, and improves the user experience.
[0100] Optionally, after placing the service identification information corresponding to the service request as queue elements into the service cache queues respectively for queuing, the device further includes: a first position judging module, a node setting module, and a request response module.
[0101] Among them, the first-bit judgment module is used to judge whether the service identification information corresponding to the service request is at the first position of the service cache queues of all associated service objects; the node setting module is used to, if not, set a listening node for the service identification information and set a thread blocking and wake-up mechanism for the service identification information; the request response module is used to, if so, respond to the service request and execute the target service corresponding to the service request.
[0102] Optionally, the node setting module is further used to create a zookeeper node based on the service identification information through zookeeper and set a thread blocking and wake-up mechanism for the service identification information through CountDownLatch, where the zookeeper node is used to mark the response status of the service request corresponding to the service identification information, and the response status includes an active state and an inactive state, and the initial value of the semaphore of the CountDownLatch is greater than 0; when the zookeeper node monitors that the node status of the zookeeper node corresponding to the service identification information changes, the semaphore of the CountDownLatch is reduced, and when it is detected that the semaphore reaches a preset wake-up threshold, the service request corresponding to the service identification information is woken up and executed.
[0103] Optionally, the initial value of the semaphore is set based on the number of service objects that are not at the first position of the service cache queue when the service identification information is put into the service cache queue.
[0104] Optionally, the node setting module is further used to, after the service request corresponding to the service identification information at the first position of the service cache queue is executed, detect the next zookeeper node in the service cache queue and update the node status of the detected zookeeper node.
[0105] Optionally, the device further includes: a node deletion module, which is used to monitor the queuing time of the service identification information in the queue through the zookeeper node. If the queuing time exceeds a preset time threshold, the zookeeper node corresponding to the service identification information is deleted, and the service requested by the service request corresponding to the service identification information is returned.
[0106] Optionally, the device further includes: an information shifting module, which is used to, when it is detected that the service identification information at the first position of the service cache queues of all associated service objects does not meet the service execution condition, perform a position shifting process on the service identification information at the first position of the service cache queue.
[0107] The above device for processing concurrent services can execute the method for processing concurrent services provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects for executing the method for processing concurrent services.
[0108] Example 5
[0109] Figure 12 FIG. 6 is a schematic structural diagram of an electronic device provided in Example 5 of the present invention. Figure 12 FIG. 7 shows a block diagram of an exemplary electronic device 40 suitable for implementing the embodiments of the present invention. Figure 12 The shown electronic device 40 is merely an example and should not impose any limitation on the functions and usage scope of the embodiments of the present invention.
[0110] As shown in Figure 12 FIG. 8, the electronic device 40 is presented in the form of a general-purpose computing device. The components of the electronic device 40 may include, but are not limited to: one or more processors or processing units 401, a system memory 402, and a bus 403 connecting different system components (including the system memory 402 and the processing unit 401).
[0111] The bus 403 represents one or more of several types of bus structures, including a memory bus or a memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the multiple bus structures. For example, these architectures include, but are not limited to, Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
[0112] The electronic device 40 typically includes a variety of computer system-readable media. These media can be any available media accessible by the electronic device 40, including volatile and non-volatile media, removable and non-removable media.
[0113] The system memory 402 may include computer system-readable media in the form of volatile memory, such as random access memory (RAM) 404 and / or cache memory 405. The electronic device 40 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, a storage system 406 can be used to read and write non-removable, non-volatile magnetic media ( Figure 12 not shown, commonly referred to as a "hard disk drive"). Although Figure 12Not shown in the figure, a disk drive for reading and writing a removable non-volatile disk (such as a "floppy disk") and an optical disk drive for reading and writing a removable non-volatile optical disk (such as a CD-ROM, DVD-ROM or other optical medium) can be provided. In these cases, each drive can be connected to the bus 403 through one or more data medium interfaces. The memory 402 may include at least one program product having a set (such as at least one) of program modules configured to perform the functions of the embodiments of the present invention.
[0114] A program / utility 408 having a set (at least one) of program modules 407 can be stored in, for example, the memory 402. Such program modules 407 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include the implementation of a network environment. The program modules 407 generally perform the functions and / or methods in the embodiments described in the present invention.
[0115] The electronic device 40 can also communicate with one or more external devices 409 (such as a keyboard, a pointing device, a display 410, etc.), and can also communicate with one or more devices that enable a user to interact with the electronic device 40, and / or communicate with any device that enables the electronic device 40 to communicate with one or more other computing devices (such as a network card, a modem, etc.). Such communication can be carried out through an input / output (I / O) interface 411. Moreover, the electronic device 40 can also communicate with one or more networks (such as a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through a network adapter 412. As shown in the figure, the network adapter 412 communicates with other modules of the electronic device 40 through the bus 403. It should be understood that although Figure 12 not shown in the figure, other hardware and / or software modules can be used in combination with the electronic device 40, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.
[0116] The processing unit 401 executes various functional applications and data processing by running programs stored in the system memory 402, such as implementing a processing method for a concurrent service provided by the embodiments of the present invention.
[0117] Embodiment Seven
[0118] Embodiment Seven of the present invention also provides a storage medium containing computer-executable instructions, and the computer-executable instructions are used to execute a processing method for a concurrent service when executed by a computer processor. The method includes:
[0119] When a service request associated with at least two service objects is received, determine whether a service cache queue has been created for the service objects associated with the service request;
[0120] If not, establish corresponding service cache queues based on the service objects respectively, and place the service identification information corresponding to the service request as queue elements into the service cache queues respectively for queuing;
[0121] When the first elements of the service cache queues of the service objects associated with the service request are all the service identification information corresponding to the service request, then respond to the service request and execute the target service corresponding to the service request.
[0122] The computer storage medium of the embodiments of the present invention may adopt any combination of one or more computer-readable media. The computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (non-exhaustive list) of the computer-readable storage medium include: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, the computer-readable storage medium may be any tangible medium that contains or stores a program, which can be used by or in combination with an instruction execution system, apparatus, or device.
[0123] The computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries the computer-readable program code. Such a propagated data signal may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium may also be any computer-readable medium other than the computer-readable storage medium, which can send, propagate, or transmit a program for use by or in combination with an instruction execution system, apparatus, or device.
[0124] The program code contained on the computer-readable medium may be transmitted by any appropriate medium, including but not limited to wireless, wire, optical fiber, RF, etc., or any suitable combination of the above.
[0125] Computer program code for performing the operations of the embodiments of the present invention can be written in one or more programming languages or combinations thereof. The programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, executed as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (e.g., by connecting through the Internet using an Internet service provider).
[0126] Note that the above is only the preferred embodiment of the present invention and the technical principles applied. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein. Various obvious changes, re-adjustments, and substitutions can be made by those skilled in the art without departing from the protection scope of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments. Without departing from the concept of the present invention, more other equivalent embodiments can be included, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A method for processing concurrent services, characterized in that, Including: When receiving a service request associated with at least two service objects, determining whether a service cache queue has been created for the service objects associated with the service request; If not, respectively establishing corresponding service cache queues based on each service object associated with the service request, and putting the service identification information corresponding to the service request as queue elements into the service cache queues corresponding to each service object associated with the service request for queuing; wherein, the service identification information is identification information for identifying the current state of the service request; When the first place of the service cache queue of each service object associated with the service request is the service identification information corresponding to the service request, then responding to the service request and executing the target service corresponding to the service request.
2. The method according to claim 1, characterized in that After putting the service identification information corresponding to the service request as queue elements into the service cache queues for queuing, further including: Judging whether the service identification information corresponding to the service request is at the first place of the service cache queues of all associated service objects; If not, setting a monitoring node for the service identification information and setting a thread blocking and waking mechanism for the service identification information; If so, responding to the service request and executing the target service corresponding to the service request.
3. The method according to claim 2, wherein Saying setting a monitoring node for the service identification information and setting a thread blocking and waking mechanism for the service identification information includes: Creating a zookeeper node based on the service identification information through zookeeper, and setting a thread blocking and waking mechanism for the service identification information through CountDownLatch, wherein the zookeeper node is used to mark the response state of the service request corresponding to the service identification information, the response state includes an active state and an inactive state, and the initial value of the semaphore of the CountDownLatch is greater than 0; When the zookeeper node monitors that the node state of the zookeeper node corresponding to the service identification information changes, reducing the semaphore of the CountDownLatch, and when detecting that the semaphore reaches a preset wake-up threshold, waking up the service request corresponding to the service identification information and executing it.
4. The method according to claim 3, wherein The initial value of the semaphore is set based on the number of service objects that are not at the first place of the service cache queue when the service identification information is put into the service cache queue.
5. The method according to claim 3, wherein Saying when the zookeeper node monitors that the node state of the zookeeper node corresponding to the service identification information changes includes: After the service request corresponding to the service identification information at the first place of the service cache queue is executed, detecting the next zookeeper node in the service cache queue and updating the node state of the detected zookeeper node.
6. The method according to claim 3, characterized in that, Also including: Monitor the queuing time of the service identification information in the queue through the zookeeper node. If the queuing time exceeds the preset time threshold, delete the zookeeper node corresponding to the service identification information, and return the service requested by the service request corresponding to the service identification information.
7. The method according to claim 1, characterized in that It further includes: When it is detected that the service identification information at the head of the service cache queue of each associated service object does not meet the service execution condition, the service identification information at the head of the service cache queue is moved backward.
8. A processing device for concurrent services, characterized in that, It includes: A request receiving module, configured to determine whether a service cache queue has been created for the service object associated with the service request when receiving a service request associated with at least two service objects; A queue establishing module, configured to, if not, respectively establish corresponding service cache queues based on each service object associated with the service request, and place the service identification information corresponding to the service request as queue elements into the service cache queues corresponding to each service object associated with the service request for queuing; wherein, the service identification information is identification information for identifying the current state of the service request; A service execution module, configured to, when the service identification information corresponding to the service request is at the head of the service cache queue of each service object associated with the service request, respond to the service request and execute the target service corresponding to the service request.
9. An electronic device, characterized in that, The electronic device includes: One or more processors; A storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the concurrent service processing method according to any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the concurrent service processing method according to any one of claims 1-7.
Citation Information
Patent Citations
Method and device for realizing distributed transactions
CN103631647A
Service request processing method and apparatus, electronic device, and storage medium
CN109451051A