Virtual resource allocation method and device
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING WODONG TIANJUN INFORMATION TECH CO LTD
- Filing Date
- 2024-11-21
- Publication Date
- 2026-05-29
Smart Images

Figure CN122111701A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method and apparatus for distributing virtual resources. Background Technology
[0002] In current e-commerce scenarios, users are often rewarded and rewarded with virtual resources, such as points awarded after a user places an order. The real-time requirements for this virtual resource distribution are not high, and asynchronous distribution is generally used in practice. The main methods currently employed include: using message queues or API calls to perform virtual resource calculation, distribution, and accounting. The disadvantages of this approach are: First, using a single program to perform the calculation, distribution, and accounting of indivisible virtual resources means that if an error occurs, the entire process must be re-executed, leading to low efficiency. Second, virtual resource distribution between different orders can only be performed serially, limiting system throughput. Third, when an order's calculation fails, it is immediately archived, which can easily lead to a backlog of erroneous data, triggering alarms and impacting system performance. Summary of the Invention
[0003] In view of this, embodiments of the present invention provide a method and apparatus for distributing virtual resources, which can improve the efficiency of virtual resource distribution.
[0004] To achieve the above objectives, according to one aspect of the present invention, a method for distributing virtual resources is provided.
[0005] The virtual resource distribution method of this invention includes: in response to order completion, storing information of multiple completed orders in a pre-created first database table; processing the information of the completed orders based on multiple preset working nodes to determine the virtual resources corresponding to the completed orders; distributing the virtual resources to the user indicated by the completed order; wherein, the multiple working nodes correspond one-to-one with multiple tasks included in the virtual resource distribution process and executed in a preset sequential order, and each working node deploys multiple instances to process multiple completed orders in parallel; the multiple working nodes process the same completed order serially in the predetermined sequential order; the instance of the earlier node among any two adjacent working nodes stores the intermediate processing results in the database table so that the instance of the later node can read and process them.
[0006] Optionally, the plurality of tasks includes: a resource computing task; the plurality of working nodes includes: a computing node corresponding to the resource computing task; the initial state of the records containing the information of the completed orders and the intermediate processing results in the database table is "pending processing"; and the processing of the information of the completed orders based on the preset plurality of working nodes includes: reading the information of the target completed orders with a state of "pending processing" from the first database table based on the instance of the computing node, and updating the state of the corresponding records to "processing"; calculating the information of the target completed orders to obtain a virtual resource computing result as the intermediate processing result, and writing the virtual resource computing result into the second database table; after successful writing, deleting the corresponding record of the information in the first database table; wherein, the writing operation and the deletion operation are in the same database transaction.
[0007] Optionally, the plurality of tasks further includes: a resource distribution task, the plurality of working nodes including: a distribution node corresponding to the resource distribution task; and, the step of distributing the virtual resources to the user with the completed order instruction includes: reading the virtual resource calculation result of the target completed order with a status of "pending processing" from the second database table based on the instance of the distribution node, and updating the status of the corresponding record to "processing"; performing resource distribution to the user with the target completed order instruction according to the virtual resource calculation result, and writing the virtual resource distribution result as the intermediate processing result into the third database table; after successful writing, deleting the corresponding record of the virtual resource calculation result in the second database table; wherein, the writing operation and the deletion operation are in the same database transaction.
[0008] Optionally, the plurality of tasks further includes: a distribution result recording task, and the plurality of working nodes include: a recording node corresponding to the distribution result recording task; and the method further includes: reading the virtual resource distribution results of the target completed order with a status of "pending processing" from a third database table based on an instance of the recording node, and updating the status of the corresponding record to "processing"; recording accounts according to the virtual resource distribution results, and writing the record results as the intermediate processing results into a fourth database table; after successful writing, deleting the corresponding record of the virtual resource distribution results in the third database table; wherein the writing operation and the deletion operation are in the same database transaction.
[0009] Optionally, the plurality of tasks further includes: a downstream system notification task, and the plurality of working nodes include: a notification node corresponding to the downstream system notification task; and the method further includes: reading the record results of the target completed order with a status of "pending processing" from the fourth database table based on the instance of the notification node, updating the status of the corresponding record to "processing"; sending a notification to the downstream system according to the record results, and deleting the corresponding record of the record results in the fourth database table after the notification is completed.
[0010] Optionally, the method further includes: detecting records in any database table that have remained in a "processing" state for a first preset duration based on a preset monitoring node; performing a retry for the detected record and the task to which the record belongs; setting the retry count of the record to 1 and obtaining the retry time; if the retry time of any record reaches a second preset duration and the current retry count has not reached the preset maximum retry count, performing the next retry and incrementing the retry count of the record by 1; if the retry count of any record reaches the maximum retry count, issuing an alarm message.
[0011] To achieve the above objectives, according to another aspect of the present invention, a virtual resource distribution device is provided.
[0012] The virtual resource distribution device of this invention embodiment may include: an order storage unit, configured to store information of multiple completed orders in a pre-created first database table in response to order completion; a virtual resource processing unit, configured to process the information of the completed orders based on a preset number of working nodes to determine the virtual resources corresponding to the completed orders; and to distribute the virtual resources to the user indicated by the completed orders; wherein, the multiple working nodes correspond one-to-one with multiple tasks included in the virtual resource distribution process and executed in a preset sequential order, and each working node deploys multiple instances to process multiple completed orders in parallel; the multiple working nodes process the same completed order serially in the predetermined sequential order; the instance of the earlier node among any two adjacent working nodes stores the intermediate processing results in the database table so that the instance of the later node can read and process them.
[0013] Optionally, the plurality of tasks includes: a resource computing task, a resource allocation task, an allocation result recording task, and a downstream system notification task, and the plurality of working nodes includes: a computing node corresponding to the resource computing task, an allocation node corresponding to the resource allocation task, a recording node corresponding to the allocation result recording task, and a notification node corresponding to the downstream system notification task.
[0014] To achieve the above objectives, according to another aspect of the present invention, an electronic device is provided.
[0015] An electronic device according to the present invention includes: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the virtual resource distribution method provided by the present invention.
[0016] To achieve the above objectives, according to another aspect of the present invention, a computer-readable storage medium is provided.
[0017] The present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the virtual resource distribution method provided by the present invention.
[0018] According to the technical solution of the present invention, the embodiments described above have the following advantages or beneficial effects:
[0019] First, information on completed orders is stored in a pre-created database table. Then, based on multiple pre-defined worker nodes, this information is processed to determine the corresponding virtual resources and distribute them to the users indicated by the completed orders. Each worker node corresponds one-to-one with multiple tasks executed in a preset order during the virtual resource distribution process. Each worker node deploys multiple instances to process multiple completed orders in parallel. Multiple worker nodes process the same completed order sequentially. The instance of the earlier node among any two adjacent worker nodes stores intermediate processing results in a database table, allowing subsequent nodes to read and process them. This allows each node to deploy multiple instances to process multiple orders in parallel, thereby improving system throughput. When processing the same order, each worker node completes its task's processing steps and stores the data in the database sequentially according to a preset order. Subsequent worker nodes read data from the database and process it accordingly. This divides the virtual resource distribution process into multiple independently executed fine-grained tasks, facilitating multiple retries for the current specific task and improving virtual resource distribution efficiency.
[0020] The further effects of the aforementioned unconventional alternative methods will be explained below in conjunction with specific implementation methods. Attached Figure Description
[0021] The accompanying drawings are provided to better understand the invention and are not intended to unduly limit the scope of the invention. Wherein:
[0022] Figure 1 This is a schematic diagram illustrating the main steps of the virtual resource distribution method in this embodiment of the invention;
[0023] Figure 2 This is a schematic diagram of the system structure of the virtual resource distribution method in an embodiment of the present invention;
[0024] Figure 3This is a schematic diagram illustrating the specific execution of the virtual resource allocation method in this embodiment of the invention;
[0025] Figure 4 This is a schematic diagram of the components of the virtual resource distribution device in an embodiment of the present invention;
[0026] Figure 5 This is an exemplary system architecture diagram that can be applied thereto according to embodiments of the present invention;
[0027] Figure 6 This is a schematic diagram of the electronic device structure used to implement the virtual resource distribution method in the embodiments of the present invention. Detailed Implementation
[0028] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0029] It should be noted that, unless otherwise specified, the embodiments of the present invention and the technical features thereof can be combined with each other.
[0030] Figure 1 This is a schematic diagram of the main steps of the virtual resource distribution method in an embodiment of the present invention.
[0031] like Figure 1 As shown, the virtual resource allocation method of this embodiment of the invention can be executed by a computer system or server for performing virtual resource allocation (hereinafter referred to as the virtual resource allocation system), and can be specifically executed according to the following steps:
[0032] Step S101: In response to order completion, information on multiple completed orders is stored in a pre-created first database table. In this step, after an order is completed, the order system can send an order completion message to the virtual resource distribution system via a message queue. The virtual resource distribution system can then store the information of the completed orders in a pre-created database table. This information may include order details such as order identifier, user identifier, product identifier, user level, product category, and order amount. The virtual resources mentioned above refer to any resource presented on computing devices such as computers and smart terminals, such as points or coupons. Points will be used as an example below.
[0033] Step S102: Based on multiple pre-set working nodes, process the information of completed orders to determine the virtual resources corresponding to the completed orders; distribute the virtual resources to the users indicated by the completed orders.
[0034] In this step, the virtual resource distribution system processes information related to completed orders based on multiple pre-defined work nodes. It then calculates the virtual resources corresponding to the completed orders according to a pre-defined virtual resource distribution strategy and distributes the virtual resources to the users indicated by the completed orders. These work nodes refer to pre-written programs or services that perform periodic checks on database tables. Specifically, these multiple work nodes correspond one-to-one with multiple tasks executed in a pre-defined order within the virtual resource distribution process. For example, these tasks may include a sequential sequence: a resource calculation task, a resource distribution task, a distribution result recording task, and a downstream system notification task. The resource calculation task calculates the virtual resource data corresponding to the order (e.g., virtual resource type, quantity, distribution method, etc.), the resource distribution task distributes the virtual resources to the user, the distribution result recording task records the distribution result, and the downstream system notification task notifies the downstream system to perform subsequent processing after the recording is completed.
[0035] Accordingly, the above multiple working nodes can include: a computing node corresponding to the resource computing task, a distribution node corresponding to the resource distribution task, a recording node corresponding to the distribution result recording task, and a notification node corresponding to the downstream system notification task. Each working node can be deployed with multiple instances to process multiple completed orders in parallel, thereby improving system throughput. It can be understood that in practical applications, the number of instances can be deployed according to the workload of each working node. Furthermore, the above multiple working nodes can process the same completed order serially in the above order. The order of the working nodes is: computing node, distribution node, recording node, notification node, with the computing node preceding the distribution node, the distribution node preceding the recording node, and the recording node preceding the notification node.
[0036] Instances of the earlier node among any two adjacent working nodes store intermediate processing results in a database table, allowing instances of the later node to read and process them. It can be understood that for adjacent nodes (calculation node and issuing node), the calculation node is the earlier node, and the issuing node is the later node; for adjacent nodes (issuing node and recording node), the issuing node is the earlier node, and the recording node is the later node; for adjacent nodes (recording node and notification node), the recording node is the earlier node, and the notification node is the later node. As a preferred solution, the initial state of the records containing information about completed orders and intermediate processing results in the database table is "pending processing."
[0037] Based on the above settings, each worker node can process multiple orders in parallel using multiple instances configured separately. However, for the same order, processing must be sequential. That is, after the previous task node performs its processing, it stores the result in the database. The next task node then reads the result from the database table and performs its own processing, until the entire virtual resource delivery process is complete. These steps improve the data processing throughput of the virtual resource delivery system. Furthermore, dividing the virtual resource delivery process into multiple independently executed fine-grained tasks facilitates multiple retries for the current specific task, thereby improving the efficiency of virtual resource delivery.
[0038] Figure 2 This is a schematic diagram of the system structure of the virtual resource allocation method in an embodiment of the present invention. See [link / reference]. Figure 2 The virtual resource allocation system interacts with the order system and downstream systems through message queues. Internally, the virtual resource allocation system includes compute nodes, allocation nodes, recording nodes, and notification nodes, each with multiple instances deployed.
[0039] Figure 3 This is a schematic diagram illustrating the specific execution of the virtual resource allocation method in this embodiment of the invention. See [link / reference]. Figure 3 The first step is for the virtual resource allocation system to consume order completion messages from the message queue, store the information of completed orders in the first database table, and record the corresponding records in the first database table as "pending processing".
[0040] In the second step, after the virtual resource allocation system detects new data in the first database table based on the instance of the computing node, it reads the information of the target completed order with a status of "pending processing" from the first database table and updates the status of the corresponding record to "processing". Through this status update operation, a distributed lock mechanism can prevent multiple instances from reading and processing the same record, thus ensuring data consistency. Next, the virtual resource allocation system calculates the information of the target completed order based on the instance of the computing node to obtain the virtual resource calculation result as an intermediate processing result. For example, the virtual resource calculation result may include: order identifier, user identifier, product identifier, virtual resource type, virtual resource quantity, virtual resource allocation method, etc. Afterwards, the virtual resource allocation system writes the virtual resource calculation result to the second database table based on the instance of the computing node; after successful writing, the corresponding record of this information in the first database table is deleted; wherein, the write operation and the deletion operation are within the same database transaction. Through the above settings, atomic operations can be used to avoid data errors or loss.
[0041] Third, after detecting new data in the second database table based on the instance of the distribution node, the virtual resource distribution system reads the virtual resource calculation results of the target completed orders with a status of "pending processing" from the second database table, updates the status of the corresponding records to "processing," and performs resource distribution to the users indicated by the target completed orders according to the virtual resource calculation results. The virtual resource distribution results, as intermediate processing results, are written to the third database table. For example, the virtual resource distribution results may include: order identifier, user identifier, product identifier, whether the virtual resource distribution was successful, the type of virtual resource distributed, the quantity of virtual resources distributed, and the virtual resource distribution method. After successful writing, the virtual resource distribution system deletes the corresponding record of the virtual resource calculation results in the second database table based on the instance of the distribution node; the write operation and the delete operation are within the same database transaction.
[0042] In the fourth step, after the virtual resource allocation system detects new data in the third database table based on the instance of the record node, it reads the virtual resource allocation results of completed target orders with a status of "pending processing" from the third database table, updates the status of the corresponding records to "processing," and records the transactions based on the virtual resource allocation results. The record results, as intermediate processing results, are then written to the fourth database table. These record results may include: order identifier, user identifier, product identifier, whether the accounting was successful, and account details. After successful writing, the virtual resource allocation system deletes the corresponding record of the virtual resource allocation result in the third database table based on the instance of the record node; this write operation and the deletion operation are within the same database transaction.
[0043] Fifth, after the virtual resource allocation system detects the new data in the fourth database table based on the instance of the notification node, it reads the record results of the target completed order with the status of "pending processing" from the fourth database table, updates the status of the corresponding record to "processing", and sends a notification to the downstream system based on the record results, for example, generating a message notification and sending it to the message queue for the downstream system to consume. After the notification is completed, the virtual resource allocation system deletes the corresponding record in the fourth database table based on the instance of the notification node.
[0044] As a preferred solution, the virtual resource allocation system can detect records in any database table that have remained in a "processing" state for a first preset time (e.g., 2 hours) based on pre-set monitoring nodes. These monitoring nodes refer to pre-written monitoring programs or services, and the database tables include the first, second, third, and fourth database tables. If such a record is detected, it indicates that the record has been unable to complete calculations successfully for an extended period. The virtual resource allocation system can then retry the detected record and the task containing that record based on the monitoring nodes—that is, retry the current task without starting from the beginning. The retry count for that record is set to 1, and the retry time is obtained.
[0045] If the retry time for any record reaches the second preset duration and the current number of retries has not reached the preset maximum number of retries, the virtual resource allocation system can execute the next retry based on the monitoring node, incrementing the retry count for that record by 1. If the retry count for any record reaches the maximum number of retries, the virtual resource allocation system can issue an alarm message based on the monitoring node. Through these settings, most computational problems can be solved through multiple automatic retries, with alarms only issued if multiple retries still fail. This avoids the frequent alarms caused by large amounts of data archiving and backlog in existing technologies, thus improving system performance.
[0046] In the technical solution of this invention embodiment, the virtual resource allocation process is divided into multiple independent tasks executed in a preset order: a resource calculation task, a resource allocation task, an allocation result recording task, and a downstream system notification task. Corresponding worker nodes are configured, namely, a calculation node for the resource calculation task, an allocation node for the resource allocation task, a recording node for the allocation result recording task, and a notification node for the downstream system notification task. Each node can deploy multiple instances to process multiple orders in parallel, thereby improving system throughput. When processing the same order, each worker node completes the processing steps of its task and writes the data to the database sequentially in a preset order. The next worker node reads data from the database and processes it accordingly. This divides the virtual resource allocation process into multiple fine-grained tasks that are executed independently, which helps to perform multiple retries for the current specific task, thereby improving the efficiency of virtual resource allocation. Each worker node instance updates its status after reading the record in the database table, thereby avoiding data errors caused by multiple instances reading the same record. Furthermore, after each worker node instance executes its task and writes the data to the database table, it deletes the previously read record. The above write and delete operations are within the same database transaction, thereby ensuring data consistency. In this embodiment of the invention, the processing time of each database table is detected by monitoring nodes. When the processing time reaches a threshold, a retry for the current task is automatically triggered, and an alarm is only triggered when the number of retries reaches the threshold. This avoids frequent alarms caused by a large amount of data archiving and backlog, thereby improving system performance.
[0047] It should be noted that the technical solutions of this invention, including the collection, updating, analysis, processing, use, transmission, and storage of user personal information, all comply with relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. Necessary measures are taken to prevent unauthorized access to user personal information data and to safeguard user personal information security, network security, and national security.
[0048] For the foregoing method embodiments, they are described as a series of actions for ease of description. However, those skilled in the art should understand that the present invention is not limited to the described order of actions, and some steps may actually be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential for implementing the present invention.
[0049] To facilitate better implementation of the above-described solutions of the embodiments of the present invention, related apparatus for implementing the above-described solutions is also provided below.
[0050] Please see Figure 4 As shown, the virtual resource distribution device 400 provided in this embodiment of the invention may include: an order storage unit 401 and a virtual resource processing unit 402.
[0051] The order storage unit 401 is used to store information of multiple completed orders in a pre-created first database table in response to order completion; the virtual resource processing unit 402 is used to process the information of the completed orders based on multiple preset working nodes to determine the virtual resources corresponding to the completed orders; and to distribute the virtual resources to the user indicated by the completed order; wherein, the multiple working nodes correspond one-to-one with multiple tasks included in the virtual resource distribution process and executed in a preset order, and each working node deploys multiple instances to process multiple completed orders in parallel; the multiple working nodes process the same completed order serially in the preset order; the instance of the earlier node among any two adjacent working nodes stores the intermediate processing results in the database table so that the instance of the later node can read and process them.
[0052] In this embodiment of the invention, the plurality of tasks include: a resource computing task, a resource allocation task, an allocation result recording task, and a downstream system notification task. The plurality of working nodes include: a computing node corresponding to the resource computing task, an allocation node corresponding to the resource allocation task, a recording node corresponding to the allocation result recording task, and a notification node corresponding to the downstream system notification task.
[0053] In a specific application, the initial state of the records containing the information of the completed orders and the intermediate processing results in the database table is "pending processing"; and the virtual resource processing unit 402 can be further used to: read the information of the target completed orders with the state "pending processing" from the first database table based on the instance of the computing node, and update the state of the corresponding records to "processing"; calculate the information of the target completed orders to obtain the virtual resource calculation result as the intermediate processing result, and write the virtual resource calculation result into the second database table; after successful writing, delete the corresponding record of the information in the first database table; wherein, the writing operation and the deletion operation are in the same database transaction.
[0054] In practical applications, the virtual resource processing unit 402 can be further used to: read the virtual resource calculation results of the target completed order with a status of "pending processing" from the second database table based on the instance of the distribution node, and update the status of the corresponding record to "processing"; perform resource distribution to the user indicated by the target completed order according to the virtual resource calculation results, and write the virtual resource distribution result as the intermediate processing result into the third database table; after successful writing, delete the corresponding record of the virtual resource calculation result in the second database table; wherein, the writing operation and the deletion operation are in the same database transaction.
[0055] As a preferred embodiment, the virtual resource processing unit 402 can be further configured to: read the virtual resource allocation results of the target completed order with a status of "pending processing" from the third database table based on the instance of the record node, and update the status of the corresponding record to "processing"; record the accounts according to the virtual resource allocation results, and write the record results as the intermediate processing results into the fourth database table; after successful writing, delete the corresponding record of the virtual resource allocation results in the third database table; wherein the writing operation and the deletion operation are in the same database transaction.
[0056] Preferably, the virtual resource processing unit 402 can be further configured to: read the record results of the target completed order with a status of "pending processing" from the fourth database table based on the instance of the notification node, update the status of the corresponding record to "processing"; send a notification to the downstream system according to the record results, and delete the corresponding record of the record results in the fourth database table after the notification is completed.
[0057] Furthermore, in this embodiment of the invention, the device 400 may further include a monitoring unit, configured to: detect records in any database table that have maintained a "processing" state for a first preset duration based on preset monitoring nodes; perform retries for the detected records and the tasks to which the records belong; set the retry count of the record to 1 and obtain the retry time; if the retry time of any record reaches a second preset duration and the current retry count has not reached the preset maximum retry count, perform the next retry and increment the retry count of the record by 1; and if the retry count of any record reaches the maximum retry count, issue an alarm message.
[0058] According to the technical solution of this invention, the virtual resource allocation process is divided into multiple independent tasks executed in a preset order: a resource calculation task, a resource allocation task, an allocation result recording task, and a downstream system notification task. Corresponding working nodes are configured, namely, a calculation node for the resource calculation task, an allocation node for the resource allocation task, a recording node for the allocation result recording task, and a notification node for the downstream system notification task. Each node can deploy multiple instances to process multiple orders in parallel, thereby improving system throughput. When processing the same order, each working node completes the processing steps of its task and writes the data to the database sequentially in a preset order. The next working node reads data from the database and processes it accordingly. This divides the virtual resource allocation process into multiple fine-grained tasks that are executed independently, which helps to perform multiple retries for the current specific task, thereby improving the efficiency of virtual resource allocation. Each working node instance updates its status after reading the record in the database table, thereby avoiding data errors caused by multiple instances reading the same record. Furthermore, after each working node instance executes its task and writes the data to the database table, it deletes the previously read record. The above write and delete operations are within the same database transaction, thereby ensuring data consistency. In this embodiment of the invention, the processing time of each database table is detected by monitoring nodes. When the processing time reaches a threshold, a retry for the current task is automatically triggered, and an alarm is only triggered when the number of retries reaches the threshold. This avoids frequent alarms caused by a large amount of data archiving and backlog, thereby improving system performance.
[0059] Figure 5 An exemplary system architecture 500 is shown that can be applied to the virtual resource distribution method or virtual resource distribution apparatus of the present invention.
[0060] like Figure 5As shown, system architecture 500 may include terminal devices 501, 502, and 503, network 504, and server 505 (this architecture is merely an example; the components included in a specific architecture may be adjusted according to the specific application). Network 504 serves as the medium for providing a communication link between terminal devices 501, 502, and 503 and server 505. Network 504 may include various connection types, such as wired or wireless communication links or fiber optic cables.
[0061] Users can use terminal devices 501, 502, and 503 to interact with server 505 via network 504 to receive or send messages, etc. Various client applications, such as virtual resource distribution applications, can be installed on terminal devices 501, 502, and 503 (for example only).
[0062] Terminal devices 501, 502, and 503 can be various electronic devices with displays that support web browsing, including but not limited to smartphones, tablets, laptops, and desktop computers.
[0063] Server 505 can be a server that provides various services, such as a backend server that supports the virtual resource provisioning application operated by users using terminal devices 501, 502, and 503 (for example only). The backend server can process the received virtual resource provisioning requests and feed back the processing results (such as virtual resource provisioning results - for example only) to terminal devices 501, 502, and 503.
[0064] It should be noted that the virtual resource distribution method provided in this embodiment of the invention is generally executed by server 505, and correspondingly, the virtual resource distribution device is generally set in server 505.
[0065] It should be understood that Figure 5 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.
[0066] The present invention also provides an electronic device. The electronic device according to an embodiment of the present invention includes: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the virtual resource distribution method provided by the present invention.
[0067] The following is for reference. Figure 6 It shows a schematic diagram of the structure of a computer system 600 suitable for implementing an electronic device according to embodiments of the present invention. Figure 6 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of use of the embodiments of the present invention.
[0068] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 602 or programs loaded from storage section 608 into random access memory (RAM) 603. The RAM 603 also stores various programs and data required for the operation of the computer system 600. The CPU 601, ROM 602, and RAM 603 are interconnected via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0069] The following components are connected to I / O interface 605: an input section 606 including a keyboard, mouse, etc.; an output section 607 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to I / O interface 605 as needed. A removable medium 611, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 610 as needed so that computer programs read from it can be installed into storage section 608 as needed.
[0070] In particular, according to the embodiments disclosed in this invention, the processes described in the above main step diagrams can be implemented as computer software programs. For example, embodiments of this invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the main step diagrams. In the above embodiments, the computer program can be downloaded and installed from a network via communication section 609, and / or installed from removable medium 611. When the computer program is executed by central processing unit 601, it performs the functions defined in the system of this invention.
[0071] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0072] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0073] The units described in the embodiments of the present invention can be implemented in software or hardware. The described units can also be housed in a processor; for example, a processor can be described as including an order storage unit and a virtual resource processing unit. The names of these units do not necessarily limit the specific unit; for example, the order storage unit can also be described as "a unit that provides completed order information to the virtual resource processing unit."
[0074] In another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs, which, when executed by the device, cause the device to perform the following steps: in response to order completion, storing information of multiple completed orders in a pre-created first database table; processing the information of the completed orders based on a pre-set plurality of working nodes to determine the virtual resources corresponding to the completed orders; and distributing the virtual resources to the user indicated by the completed order.
[0075] In the technical solution of this invention embodiment, the virtual resource allocation process is divided into multiple independent tasks executed in a preset order: a resource calculation task, a resource allocation task, an allocation result recording task, and a downstream system notification task. Corresponding worker nodes are configured, namely, a calculation node for the resource calculation task, an allocation node for the resource allocation task, a recording node for the allocation result recording task, and a notification node for the downstream system notification task. Each node can deploy multiple instances to process multiple orders in parallel, thereby improving system throughput. When processing the same order, each worker node completes the processing steps of its task and writes the data to the database sequentially in a preset order. The next worker node reads data from the database and processes it accordingly. This divides the virtual resource allocation process into multiple fine-grained tasks that are executed independently, which helps to perform multiple retries for the current specific task, thereby improving the efficiency of virtual resource allocation. Each worker node instance updates its status after reading the record in the database table, thereby avoiding data errors caused by multiple instances reading the same record. Furthermore, after each worker node instance executes its task and writes the data to the database table, it deletes the previously read record. The above write and delete operations are within the same database transaction, thereby ensuring data consistency. In this embodiment of the invention, the processing time of each database table is detected by monitoring nodes. When the processing time reaches a threshold, a retry for the current task is automatically triggered, and an alarm is only triggered when the number of retries reaches the threshold. This avoids frequent alarms caused by a large amount of data archiving and backlog, thereby improving system performance.
[0076] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A method for distributing virtual resources, characterized in that, include: In response to order completion, information on multiple completed orders is stored in a pre-created first database table; The information of completed orders is processed based on multiple pre-defined working nodes to determine the virtual resources corresponding to the completed orders; the virtual resources are then distributed to the user indicated by the completed order; wherein, The multiple work nodes correspond one-to-one with the multiple tasks included in the virtual resource distribution process, which are executed in a preset order. Each work node deploys multiple instances to process multiple completed orders in parallel. The multiple working nodes process the same completed order serially in the specified order; the instance of the earlier node among any two adjacent working nodes stores the intermediate processing results in a database table so that the instance of the later node can read and process them.
2. The method according to claim 1, characterized in that, The multiple tasks include: resource computing tasks; the multiple working nodes include: computing nodes corresponding to the resource computing tasks; the initial state of the records containing the information of completed orders and the intermediate processing results in the database table is "pending processing"; and the processing of the information of completed orders based on the preset multiple working nodes includes: Based on the instance of the computing node, information on target completed orders with a status of "pending processing" is read from the first database table, and the status of the corresponding records is updated to "processing"; The information of the completed orders of the target is calculated to obtain the virtual resource calculation result as the intermediate processing result, and the virtual resource calculation result is written into the second database table; after successful writing, the corresponding record of the information is deleted from the first database table; wherein, the writing operation and the deletion operation are in the same database transaction.
3. The method according to claim 2, characterized in that, The plurality of tasks further includes: a resource distribution task, the plurality of working nodes including: a distribution node corresponding to the resource distribution task; and, the step of distributing the virtual resources to the user who has completed the order instruction includes: Based on the instance of the issuing node, the virtual resource calculation results of the target completed order with the status of "pending processing" are read from the second database table, and the status of the corresponding record is updated to "processing"; Based on the virtual resource calculation results, resources are allocated to the target user who has completed the order instruction, and the virtual resource allocation result, which is the intermediate processing result, is written to the third database table; after successful writing, the corresponding record of the virtual resource calculation result is deleted from the second database table; wherein, the writing operation and the deletion operation are in the same database transaction.
4. The method according to claim 3, characterized in that, The plurality of tasks further includes: a result recording task, the plurality of working nodes including: a recording node corresponding to the result recording task; and the method further includes: Based on the instance of the record node, the virtual resource allocation results of the target completed order with the status of "pending processing" are read from the third database table, and the status of the corresponding record is updated to "processing"; The accounting records are made based on the virtual resource allocation results, and the record results, which are the intermediate processing results, are written to the fourth database table; after the writing is successful, the corresponding record of the virtual resource allocation results in the third database table is deleted; wherein, the writing operation and the deletion operation are in the same database transaction.
5. The method according to claim 4, characterized in that, The plurality of tasks further includes: a downstream system notification task, the plurality of working nodes including: a notification node corresponding to the downstream system notification task; and the method further includes: Based on the instance of the notification node, the records of the target completed orders with a status of "pending processing" are read from the fourth database table, and the status of the corresponding records is updated to "processing"; Based on the recorded results, a notification is sent to the downstream system. After the notification is completed, the corresponding record of the recorded results is deleted from the fourth database table.
6. The method according to any one of claims 2-5, characterized in that, The method further includes: Based on the preset monitoring nodes, any record in any database table that has remained in the "processing" state for a first preset duration is detected. For the detected record and the task to which the record belongs, a retry is performed, the retry count of the record is set to 1 and the retry time is obtained. If the second preset time is reached during the retry of any record and the current number of retries has not reached the preset maximum number of retries, the next retry will be performed, and the retry count of the record will be incremented by 1. An alarm message is issued if the number of retries for any record reaches the maximum number of retries.
7. A virtual resource distribution device, characterized in that, include: An order storage unit is used to store information about multiple completed orders in a pre-created first database table in response to order completion. A virtual resource processing unit is configured to process information of completed orders based on multiple preset working nodes to determine the virtual resources corresponding to the completed orders; and to distribute the virtual resources to the user indicated by the completed order; wherein, the multiple working nodes correspond one-to-one with multiple tasks included in the virtual resource distribution process and executed in a preset sequential order, and each working node deploys multiple instances to process multiple completed orders in parallel; the multiple working nodes process the same completed order serially in the predetermined sequential order; The instance of the earlier node among any two adjacent working nodes stores the intermediate processing results in a database table so that the instance of the later node can read and process them.
8. The apparatus according to claim 7, characterized in that, The multiple tasks include: resource computing task, resource allocation task, allocation result recording task, and downstream system notification task. The multiple working nodes include: computing node corresponding to the resource computing task, allocation node corresponding to the resource allocation task, recording node corresponding to the allocation result recording task, and notification node corresponding to the downstream system notification task.
9. An electronic device, characterized in that, include: One or more processors; 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 method as described in any one of claims 1-6.
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 method as described in any one of claims 1-6.