A virtual resource allocation method and device based on distribution
By generating message queues and establishing mapping relationships in a distributed architecture, and adopting a 'generate-consume' model, the problem of uneven distribution of virtual resources in different databases is solved, achieving fair resource allocation and high concurrency capabilities, and improving user experience.
Patent Information
- Application Number
- CN202210497328.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-09
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2042-05-09
AI Technical Summary
In a distributed application architecture, the uneven storage of different virtual resources in different distributed databases can lead to poor user experience. This is especially true in e-commerce activities, where uneven resource consumption in some sets can result in some sets being unavailable while overall resources remain.
By generating message queues and establishing mapping relationships based on virtual resource IDs stored in a distributed database, a 'generate-consume' model is adopted to achieve fair allocation of virtual resources. Distributed message queues are used to ensure high concurrency, high capacity, and scalability of resources.
It solves the problem of uneven resource consumption, achieves fair resource allocation, improves user experience, has high concurrency and scalability, and is suitable for the balanced allocation of resource-related data.
Smart Images

Figure CN114896062B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of distributed technology, specifically relating to a distributed virtual resource allocation method and apparatus. Background Technology
[0002] With the application of distributed technology, the problem of the performance and capacity of conventional single-point application servers and databases being difficult to expand has been greatly solved. Distributed architecture is a stable and reliable architecture with elastic scalability of capacity and service capabilities. It has the capabilities of automated horizontal partitioning, transparent read-write separation, online smooth expansion service, etc., providing more favorable technical support for business systems with long-term growth or fluctuation in business volume.
[0003] However, with the increasing number of application scenarios, existing distributed technologies are no longer suitable for some. Taking the allocation of resources in e-commerce activities as an example, the current method is to route requests from different users through consistent hashing to a designated set for processing, thereby achieving flexible scaling of the system's concurrent throughput. This rule works well for process data such as transaction logs and transaction details, as well as user-related protocol data. However, it may present certain problems for resource-related data, such as product inventory. For example: see... Figure 1 The inventory was divided into 10 sets for a promotional event, with the stock evenly distributed across sets 1-10, each containing 1 million coupon codes. After a certain period, the inventory distribution within each set became irregular, eventually leading to some sets running out of stock. User A, for example, was routed to set 1, which was already depleted. Meanwhile, user B was routed to set 2, which still had stock remaining. This resulted in user A being unable to participate in the promotion due to technical issues. Summary of the Invention
[0004] This invention can be applied to the technical field of computer distributed technology in finance, and can also be applied to any field other than finance. This invention solves the problem of poor user experience caused by the uneven storage of different virtual resources in different distributed databases under distributed application architecture.
[0005] To address the technical problems in the background section of this application, the present invention provides the following technical solutions:
[0006] In a first aspect, the present invention provides a distributed virtual resource allocation method comprising:
[0007] Receive users' virtual resource request requests;
[0008] Message queues are generated based on the IDs corresponding to the virtual resources stored in each distributed database.
[0009] The virtual resources are allocated according to the message queue and the virtual resource request.
[0010] In one embodiment, allocating the virtual resource according to the message queue and the virtual resource request includes:
[0011] Modify the current message in the message queue according to the number of virtual resources stored in the distributed database;
[0012] Establish a mapping relationship between the distributed database and the corresponding IDs of the virtual resources it stores;
[0013] The distributed database storing the virtual resources is determined based on the current message;
[0014] The virtual resource request is allocated to a distributed database storing the virtual resources according to the mapping relationship.
[0015] In one embodiment, modifying the current message in the message queue according to the number of virtual resources stored in the distributed database includes:
[0016] The number of messages is increased accordingly based on the increase in the number of virtual resources;
[0017] The number of messages is reduced accordingly based on the reduction in the number of virtual resources.
[0018] In one embodiment, generating a message queue based on the ID corresponding to the virtual resource stored in each distributed database includes:
[0019] The virtual resources are numbered according to the categories of virtual resources stored in the distributed database and the quantity of virtual resources in each category;
[0020] The message queue is generated based on the virtual resource IDs of the same category in each of the distributed databases.
[0021] In one embodiment, the distributed virtual resource allocation method further includes:
[0022] The virtual resource request is parsed to determine the user ID and the virtual resource requested by the user.
[0023] In one embodiment, allocating the virtual resource request to a distributed database storing the virtual resources according to the mapping relationship includes:
[0024] The message queue corresponding to the virtual resources requested by the user is determined;
[0025] Determine whether there are any messages stored in the message queue;
[0026] If so, the virtual resource request is allocated to the corresponding distributed database based on the user ID, the current message in the message queue, and the mapping relationship.
[0027] Secondly, the present invention provides a distributed virtual resource allocation device, the device comprising:
[0028] The application request receiving module is used to receive users' virtual resource application requests;
[0029] The message queue generation module is used to generate message queues based on the IDs corresponding to the virtual resources stored in each distributed database.
[0030] The virtual resource allocation module is used to allocate the virtual resources according to the message queue and the virtual resource application request.
[0031] In one embodiment, the virtual resource allocation module includes:
[0032] The message quantity modification unit is used to modify the current message in the message queue according to the number of virtual resources stored in the distributed database;
[0033] The mapping relationship establishment unit is used to establish a mapping relationship between the distributed database and the corresponding numbers of the virtual resources it stores;
[0034] A database determination unit is used to determine, based on the current message, a distributed database that stores the virtual resources;
[0035] The application request allocation unit is used to allocate the virtual resource application request to a distributed database storing the virtual resources according to the mapping relationship.
[0036] In one embodiment, the message quantity modification unit includes:
[0037] The message quantity increment unit is used to increase the message quantity by the amount of the increase in the virtual resource quantity when the virtual resource quantity increases;
[0038] The message quantity reduction unit is used to reduce the message quantity by the amount by which the virtual resource quantity increases when the virtual resource quantity decreases.
[0039] In one embodiment, the message queue generation module includes:
[0040] The virtual resource numbering unit is used to number the virtual resources according to the categories of virtual resources stored in the distributed database and the quantity of virtual resources of that category;
[0041] A message queue generation unit is used to generate the message queue based on the virtual resource IDs of the same category in each of the distributed databases.
[0042] In one embodiment, the distributed virtual resource allocation device further includes:
[0043] The application request parsing module is used to parse the virtual resource application request to determine the user ID and the virtual resource applied for by the user.
[0044] In one embodiment, the application request allocation unit includes:
[0045] The message queue determination unit is used to determine the message queue corresponding to the virtual resource requested by the user.
[0046] A message determination unit is used to determine whether a message is stored in the message queue;
[0047] The resource request allocation unit is used to allocate the virtual resource request to the corresponding distributed database, if applicable, based on the user ID, the current message in the message queue, and the mapping relationship.
[0048] Thirdly, the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of a distributed virtual resource allocation method.
[0049] Fourthly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of a distributed virtual resource allocation method.
[0050] As described above, embodiments of the present invention provide a distributed virtual resource allocation method and apparatus. The method includes: first, receiving a user's virtual resource request; then, generating a message queue based on the ID corresponding to the virtual resource stored in each distributed database; and finally, allocating virtual resources according to the message queue and the virtual resource request. This invention transforms the deduction process of virtual resources (inventory) into a "generation-consumption" model, innovatively proposing a distributed resource usage mechanism based on a distributed message queue. This solves the problem of uneven resource consumption caused by differences in load across different sets, where overall resources remain but some sets are unavailable. Simultaneously, the distributed message middleware ensures high concurrency, high capacity, and scalability of overall resource usage. Attached Figure Description
[0051] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0052] Figure 1 This is a schematic diagram illustrating a prior art method for virtual resource allocation in an embodiment of the present invention;
[0053] Figure 2 This is a flowchart illustrating a distributed virtual resource allocation method in an embodiment of the present invention. Figure 1 ;
[0054] Figure 3 This is a flowchart illustrating step 300 in an embodiment of the present invention;
[0055] Figure 4 This is a flowchart illustrating step 301 in an embodiment of the present invention;
[0056] Figure 5 This is a flowchart illustrating step 200 in an embodiment of the present invention;
[0057] Figure 6 This is a flowchart illustrating a distributed virtual resource allocation method in an embodiment of the present invention. Figure 2 ;
[0058] Figure 7 This is a flowchart illustrating step 304 in an embodiment of the present invention;
[0059] Figure 8 This is a flowchart illustrating a distributed virtual resource allocation method in a specific embodiment of the present invention.
[0060] Figure 9 This is a schematic diagram of a method for allocating virtual resources provided in a specific embodiment of the present invention;
[0061] Figure 10 The block shown in the embodiment of the present invention is based on a distributed virtual resource allocation device. Figure 1 ;
[0062] Figure 11 This is a block diagram of the virtual resource allocation module 30 in an embodiment of the present invention;
[0063] Figure 12 This is a block diagram of the message quantity modification unit 301 in an embodiment of the present invention;
[0064] Figure 13This is a block diagram of the message queue generation module 20 in an embodiment of the present invention;
[0065] Figure 14 The block shown in the embodiment of the present invention is based on a distributed virtual resource allocation device. Figure 2 ;
[0066] Figure 15 This is a block diagram of the application request allocation unit 304 in an embodiment of the present invention;
[0067] Figure 16 This is a schematic diagram of the structure of an electronic device in an embodiment of the present invention. Detailed Implementation
[0068] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0069] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0070] It should be noted that the terms "comprising" and "having," and any variations thereof, in the specification, claims, and accompanying drawings of this application are intended to cover a non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not necessarily limited to those explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or apparatuses. Without conflict, the embodiments and features in the embodiments of this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0071] Based on the aforementioned technical shortcomings of the prior art, embodiments of the present invention provide a specific implementation of a distributed virtual resource allocation method, see below. Figure 2 The method specifically includes the following:
[0072] Step 100: Receive the user's virtual resource request;
[0073] With the rapid development of internet technology, online shopping has become increasingly popular. Consequently, major e-commerce platforms launch promotional activities during major holidays, such as Singles' Day (November 11th) and Double Twelve (December 12th). These promotions are often offered to users in a virtual form, such as coupons like "¥5 off ¥100" or "buy ¥100 get ¥20 free." Furthermore, with the increasing number of e-commerce platforms, merchants offer these coupons to consumers on different platforms. In this scenario, problems often arise: even after e-commerce platform A has exhausted its coupons, some users still want to participate in the promotion, but platform A has run out of coupons, while other e-commerce platforms still have some available. Even worse, some e-commerce platforms lack concurrent control over shopping data, leading to situations where some users who were initially informed they could participate are later told that their coupons have been claimed and they cannot participate, resulting in numerous user complaints and customer loss.
[0074] Preferably, virtual resources include: shopping coupons, website memberships, movie tickets, sports event tickets, and electronic vouchers for discounts at physical stores, such as: a discount of 5 yuan off for every 30 yuan spent at a convenience store (consumers can enjoy the corresponding discount by presenting the voucher at the time of checkout in the physical store), etc.
[0075] Step 200: Generate a message queue based on the ID corresponding to the virtual resource stored in each distributed database;
[0076] A message queue is a container that stores messages during transmission. The message queue manager acts as an intermediary, relaying messages from their source to their destination. The primary purpose of queues is to provide routing and guarantee message delivery; they mainly address issues such as application decoupling, asynchronous messaging, and traffic shaping, achieving high-performance, highly available, scalable, and eventually consistent architectures.
[0077] In step 200, the message queue is viewed as a linked list of messages, meaning each message can be considered a record with a specific format and priority. Processes with write permissions to the message queue can add new messages according to certain rules; processes with read permissions can read messages from the message queue. This avoids the poor user experience caused by uneven distribution of virtual resources in the distributed database and ensures the consistency of virtual resource data.
[0078] Step 300: Allocate the virtual resources according to the message queue and the virtual resource request;
[0079] Specifically, based on the current message queue, the database storing the virtual resource that the user wants to request can be determined (or the resource is not found in any of the distributed databases). The user's virtual resource request is then allocated to the corresponding distributed database storing the virtual resource in sequence (or according to priority) according to the message queue, thereby ensuring that each virtual resource request is processed fairly (sorted according to request priority or request time).
[0080] As described above, embodiments of the present invention provide a distributed virtual resource allocation method, comprising: first, receiving a user's virtual resource request; then, generating a message queue according to the ID corresponding to the virtual resource stored in each distributed database; and finally, allocating virtual resources according to the message queue and the virtual resource request. This invention transforms the deduction process of virtual resources (inventory) into a "generation-consumption" model, innovatively proposing a distributed resource usage mechanism based on a distributed message queue. This solves the problem of uneven resource consumption caused by differences in load across different sets, where overall resources remain but some sets are unavailable. Simultaneously, the distributed message middleware ensures high concurrency, high capacity, and scalability of overall resource usage.
[0081] In one embodiment, see Figure 3 Step 300 specifically includes:
[0082] Step 301: Modify the current message in the message queue according to the number of virtual resources stored in the distributed database;
[0083] It must be noted that the number of virtual resources in all distributed databases corresponds one-to-one with the number of messages in their corresponding message queues, and this synchronization is real-time. Furthermore, the same virtual resource in all distributed databases is stored in the same message queue (forming the same message queue). Step 301 specifically involves modifying the current message (number) in the message queue based on the number of virtual resources stored in the distributed database. For example, if the distributed database currently stores 95 units of product A, then the current message's value is 95.
[0084] Step 302: Establish a mapping relationship between the distributed database and the corresponding IDs of the virtual resources it stores;
[0085] Understandably, different virtual resources (such as coupons) can be offered for different products, and even different virtual resources can be offered for the same product (such as setting different coupons based on different purchase amounts). Therefore, it is necessary to establish multiple message queues. Specifically, virtual resources are first classified and numbered within the same category. Finally, a mapping relationship is established between the virtual resource number stored in each distributed data and the distributed data itself, so as to ensure accuracy and speed when allocating virtual resource request requests.
[0086] Step 303: Determine the distributed database storing the virtual resources based on the current message;
[0087] Step 304: Allocate the virtual resource request to the distributed database storing the virtual resources according to the mapping relationship.
[0088] In steps 303 and 304, the distributed database corresponding to the current message is determined according to the mapping relationship. Then, the virtual resource request is allocated to that distributed database. For example, if step 302 determines that the current message corresponding to the virtual resource request is 95, it means that there are a total of 95 such virtual resources stored in all distributed databases. Then, the distributed database corresponding to the current message (the 95th virtual resource) is determined according to the mapping relationship, and finally, the virtual resource request is allocated to that distributed database.
[0089] In one embodiment, see Figure 4 Step 301 includes:
[0090] Step 3011: Increase the number of messages accordingly based on the increase in the number of virtual resources;
[0091] Step 3012: Reduce the number of messages accordingly based on the reduction in the number of virtual resources;
[0092] From the above description, it is easy to understand that the number of virtual resources corresponds one-to-one with the number of messages in the message queue, and changes relative to each other in real time. Under normal circumstances, the number of virtual resources gradually decreases (and the number of messages also gradually decreases relatively). However, under special circumstances, the number of virtual resources may increase. For example, if a merchant decides to temporarily increase the number of virtual resources, the number of messages in the message queue should also increase by the same amount.
[0093] In one embodiment, see Figure 5 Step 200 includes:
[0094] Step 201: Number the virtual resources according to the categories of virtual resources stored in the distributed database and the quantity of virtual resources in that category;
[0095] Step 202: Generate the message queue based on the virtual resource IDs of the same category in each distributed database.
[0096] In steps 201 and 202, it is understood that different merchants push different virtual resources. For example, merchant A offers a coupon of 100 minus 5, while merchant B offers 100 minus 10. Furthermore, the coupons offered by the same merchant are also different. For example, merchant A offers coupons of 100 minus 5 and 200 minus 15, etc. Therefore, it is necessary to establish multiple message queues to store the numbers of different virtual resources. Before this, it is necessary to determine the category of virtual resources, determine the affiliation of different virtual resources, and number the same virtual resource to form the message queue corresponding to the virtual resource.
[0097] Furthermore, each virtual resource ID of the same category is treated as an element in the message queue, i.e., a single message, and its order in the message queue is set according to the order of the virtual resource IDs to form the message queue in step 200.
[0098] In one embodiment, see Figure 6 Distributed virtual resource allocation methods also include:
[0099] Step 400: Parse the virtual resource request to determine the user ID and the virtual resource requested by the user.
[0100] First, locate the class file in the virtual resource request. Then, find the header file in the class file and parse the header file using the Document object to obtain the different elements of the virtual resource request, such as the user ID and the virtual resource requested by the user.
[0101] In one embodiment, see Figure 7 Step 304 includes:
[0102] Step 3041: Determine the message queue corresponding to the virtual resources requested by the user;
[0103] As can be seen from the above description, different virtual resources correspond to different message queues, so the message queue corresponding to a virtual resource can be found based on the virtual resource.
[0104] Step 3042: Determine whether there are any messages stored in the message queue;
[0105] Step 3043: If so, allocate the virtual resource request to the corresponding distributed database according to the user ID, the current message in the message queue, and the mapping relationship.
[0106] It is understandable that the following situation may occur: multiple distributed databases may contain the virtual resource that the user wants to request. In this case, the virtual resource may not be allocated according to the current message. Instead, the optimal corresponding distributed database may be determined based on the user ID (which can be divided according to network type and geographical location to reduce network pressure). That is, it corresponds to a message in the message queue, rather than the current message. It should be noted that in this case, the message count in the message queue still needs to be decremented by one.
[0107] In one specific embodiment, the present invention also provides a specific implementation of a distributed virtual resource allocation method, see [link to implementation details]. Figure 8 as well as Figure 9 Specifically, it includes the following:
[0108] In existing distributed application scenarios, requests from different users can be routed through a consistent hash to a designated set for processing, thereby enabling flexible scaling of the system's concurrent throughput.
[0109] Specifically, routing can channel data of different categories / characteristics to specified distributed database sets. Based on user IDs, activity IDs, and other factors calculated using a specific algorithm, the data is evenly distributed across N sets, ensuring a relatively even distribution of business data across multiple databases. This rule works well for process data such as transaction logs and transaction details, as well as user-related protocol data. However, it may present some challenges for resource-based data, such as product inventory.
[0110] Based on the aforementioned technical pain points, the distributed virtual resource allocation method provided in this specific embodiment includes the following steps:
[0111] S1: Before the activity begins, the resources of each set are written to a distributed message queue via a "resource creation thread," and all sets share the same topic. It's even possible to complete the writing of all resources before the activity starts.
[0112] Specifically, before the activity begins, the resources of each set are written to the distributed message queue through the "resource generation thread". All sets share the same topic, see Table 1.
[0113] Table 1
[0114] Resource A Inventory Quantity information Set1 100 Resource 1-1, Resource 1-2, Resource 1-3... Resource 1-100 Set2 100 Resource 2-1, Resource 2-2, Resource 2-3... Resource 2-100 Set3 100 Resource 3-1, Resource 3-2, Resource 3-3... Resource 3-100 …… …… …… SetN 100 Resource N-1, Resource N-2, Resource N-3... Resource N-100
[0115] S2: After the event starts, the coupon redemption service will redeem resources by consuming messages. If there are still messages available to consume, it means that the coupon can be redeemed; otherwise, it means that the resources have been used up and the event ends.
[0116] Once the event starts, the coupon redemption service uses consumption messages to claim resources. If there are still consumption messages available, the coupon can be claimed; otherwise, the resources have been used up and the event ends.
[0117] S3: After receiving the message, you can determine which set library's inventory is being used based on the resource number in the message. You need to connect to the corresponding set library or call the corresponding set library's inventory deduction service to complete the inventory deduction.
[0118] After an event ends, the event status can be written to a distributed data cache and a set database to ensure that the event list is updated in a timely manner.
[0119] S4: Set an appropriate number of partitions to improve the overall system's high concurrency capability during resource acquisition.
[0120] As described above, embodiments of the present invention provide a distributed virtual resource allocation method, comprising: first, receiving a user's virtual resource request; then, generating a message queue according to the number corresponding to the virtual resource stored in each distributed database; and finally, allocating virtual resources according to the message queue and the virtual resource request.
[0121] Specifically, the present invention has the following beneficial effects:
[0122] 1. It fundamentally solves the problem in distributed application architectures where uneven resource consumption due to differences in load among different sets results in some sets being unavailable while overall resources remain.
[0123] 2. By using distributed message queues, a "generate-consume" pattern is introduced, which is transparent to users, meets the design requirements of high cohesion and low coupling, and has good scalability.
[0124] 3. It has universal applicability to the use of resource-type data (such as product inventory) in distributed application architectures, other than "process data such as transaction logs and transaction details; user-related protocol data, etc."
[0125] Based on the same inventive concept, this application also provides a distributed virtual resource allocation device, which can be used to implement the method described in the above embodiments, as shown in the following embodiments. Since the principle of the distributed virtual resource allocation device in solving the problem is similar to that of the distributed virtual resource allocation method, the implementation of the distributed virtual resource allocation device can refer to the implementation of the distributed virtual resource allocation method, and repeated details will not be elaborated further. As used below, the terms "unit" or "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the system described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0126] This invention provides a specific implementation of a distributed virtual resource allocation device capable of implementing a distributed virtual resource allocation method. See [link to relevant documentation]. Figure 10 The distributed virtual resource allocation device specifically includes the following components:
[0127] Application request receiving module 10 is used to receive virtual resource application requests from users;
[0128] The message queue generation module 20 is used to generate message queues based on the ID corresponding to the virtual resources stored in each distributed database.
[0129] The virtual resource allocation module 30 is used to allocate the virtual resources according to the message queue and the virtual resource application request.
[0130] In one embodiment, see Figure 11 The virtual resource allocation module 30 includes:
[0131] The message quantity modification unit 301 is used to modify the current message in the message queue according to the number of virtual resources stored in the distributed database;
[0132] The mapping relationship establishment unit 302 is used to establish a mapping relationship between the distributed database and the corresponding number of the virtual resources it stores;
[0133] Database determination unit 303 is used to determine, based on the current message, a distributed database storing the virtual resources;
[0134] The application request allocation unit 304 is used to allocate the virtual resource application request to a distributed database storing the virtual resources according to the mapping relationship.
[0135] In one embodiment, see Figure 12 The message quantity modification unit 301 includes:
[0136] The message quantity increase unit 3011 is used to increase the message quantity by the amount of the increase in the virtual resource quantity when the virtual resource quantity increases;
[0137] The message quantity reduction unit 3012 is used to reduce the message quantity by the amount by which the virtual resource quantity increases when the virtual resource quantity decreases.
[0138] In one embodiment, see Figure 13 The message queue generation module 20 includes:
[0139] The virtual resource numbering unit 201 is used to number the virtual resources according to the virtual resource categories stored in the distributed database and the quantity of virtual resources of that category;
[0140] The message queue generation unit 202 is used to generate the message queue based on the virtual resource IDs of the same category in each distributed database.
[0141] In one embodiment, see Figure 14 The distributed virtual resource allocation device also includes:
[0142] The application request parsing module 40 is used to parse the virtual resource application request to determine the user ID and the virtual resource applied for by the user.
[0143] In one embodiment, see Figure 15 The application request allocation unit 304 includes:
[0144] The message queue determination unit 3041 is used to determine the message queue corresponding to the virtual resource requested by the user.
[0145] The message judgment unit 3042 is used to determine whether there is a message stored in the message queue;
[0146] Resource request allocation unit 3043 is used to allocate the virtual resource request to the corresponding distributed database according to the user ID, the current message in the message queue, and the mapping relationship, if applicable.
[0147] As described above, embodiments of the present invention provide a distributed virtual resource allocation device, comprising: firstly receiving a user's virtual resource request; then generating a message queue according to the number corresponding to the virtual resource stored in each distributed database; and finally allocating virtual resources according to the message queue and the virtual resource request.
[0148] Specifically, the present invention has the following beneficial effects:
[0149] 1. It fundamentally solves the problem in distributed application architectures where uneven resource consumption due to differences in load among different sets results in some sets being unavailable while overall resources remain.
[0150] 2. By using distributed message queues, a "generate-consume" pattern is introduced, which is transparent to users, meets the design requirements of high cohesion and low coupling, and has good scalability.
[0151] 3. It has universal applicability to the use of resource-type data (such as product inventory) in distributed application architectures, other than "process data such as transaction logs and transaction details; user-related protocol data, etc."
[0152] The embodiments of this application also provide a specific implementation of an electronic device capable of implementing all the steps in the distributed virtual resource allocation method described in the above embodiments, see [link to implementation details]. Figure 16 The electronic devices specifically include the following:
[0153] Processor 1201, memory 1202, communications interface 1203, and bus 1204;
[0154] The processor 1201, memory 1202, and communication interface 1203 communicate with each other via bus 1204; the communication interface 1203 is used to realize information transmission between server-side devices and client-side devices and other related devices.
[0155] The processor 1201 is used to call the computer program stored in the memory 1202. When the processor executes the computer program, it implements all the steps in the distributed virtual resource allocation method in the above embodiments. For example, when the processor executes the computer program, it implements the following steps:
[0156] Step 100: Receive the user's virtual resource request;
[0157] Step 200: Generate a message queue based on the ID corresponding to the virtual resource stored in each distributed database;
[0158] Step 300: Allocate the virtual resources according to the message queue and the virtual resource request.
[0159] Embodiments of this application also provide a computer-readable storage medium capable of implementing all steps of the distributed virtual resource allocation method in the above embodiments. The computer-readable storage medium stores a computer program that, when executed by a processor, implements all steps of the distributed virtual resource allocation method in the above embodiments. For example, when the processor executes the computer program, it implements the following steps:
[0160] Step 100: Receive the user's virtual resource request;
[0161] Step 200: Generate a message queue based on the ID corresponding to the virtual resource stored in each distributed database;
[0162] Step 300: Allocate the virtual resources according to the message queue and the virtual resource request.
[0163] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on its differences from other embodiments. In particular, hardware + program embodiments are relatively simple in description because they are fundamentally similar to method embodiments; relevant parts can be referred to the descriptions in the method embodiments.
[0164] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.
[0165] While this application provides method operation steps as shown in the embodiments or flowcharts, more or fewer operation steps may be included based on conventional or non-inventive labor. The order of steps listed in the embodiments is merely one possible execution order among many and does not represent the only execution order. In actual device or client product execution, the method can be executed sequentially as shown in the embodiments or drawings, or in parallel (e.g., in a parallel processor or multi-threaded processing environment).
[0166] For ease of description, the above devices are described in terms of function, divided into various modules. Of course, in implementing the embodiments of this specification, the functions of each module can be implemented in one or more software and / or hardware components, or a module that performs the same function can be implemented by a combination of multiple sub-modules or sub-units. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, or indirect coupling or communication connection between devices or units, and may be electrical, mechanical, or other forms.
[0167] Those skilled in the art will also know that, besides implementing the controller using purely computer-readable program code, the same functions can be achieved by logically programming the method steps, making the controller function as logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers (PLCs), and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the devices within it used to implement various functions can also be considered structures within that hardware component. Alternatively, the devices used to implement various functions can be considered as both software modules implementing the method and structures within a hardware component.
[0168] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0169] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0170] The embodiments described in this specification can be described in the general context of computer-executable instructions, such as program modules, that are executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a specific task or implement a specific abstract data type. The embodiments of this specification can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0171] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, system embodiments are basically similar to method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments. In the description of this specification, the terms "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of the embodiments in this specification. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described can be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0172] The above description is merely an embodiment of the present specification and is not intended to limit the embodiments of the present specification. For those skilled in the art, various modifications and variations can be made to the embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principle of the embodiments of the present specification should be included within the scope of the claims of the embodiments of the present specification.
Claims
1. A distributed virtual resource allocation method, characterized in that, include: Receive users' virtual resource request requests; A message queue is generated based on the ID corresponding to the virtual resource stored in each distributed database; wherein, the virtual resources include: shopping coupons, website memberships, movie tickets, sports event tickets, and electronic vouchers for discounts from physical stores; The virtual resources are allocated according to the message queue and the virtual resource request; The step of allocating the virtual resource according to the message queue and the virtual resource request includes: Modify the current message in the message queue according to the number of virtual resources stored in the distributed database; Establish a mapping relationship between the distributed database and the corresponding IDs of the virtual resources it stores; The distributed database storing the virtual resources is determined based on the current message; The virtual resource request is allocated to a distributed database storing the virtual resources according to the mapping relationship, so as to allocate the virtual resources; The step of modifying the current message in the message queue according to the number of virtual resources stored in the distributed database includes: The number of messages is increased accordingly based on the increase in the number of virtual resources; The number of messages is reduced accordingly based on the reduction in the number of virtual resources.
2. The distributed virtual resource allocation method as described in claim 1, characterized in that, The step of generating a message queue based on the ID corresponding to the virtual resource stored in each distributed database includes: The virtual resources are numbered according to the category of the virtual resources stored in the distributed database and the quantity of virtual resources in that category; The message queue is generated based on the virtual resource IDs of the same category in each of the distributed databases.
3. The distributed virtual resource allocation method as described in claim 2, characterized in that, Also includes: The virtual resource request is parsed to determine the user ID and the virtual resource requested by the user.
4. The distributed virtual resource allocation method as described in claim 3, characterized in that, The step of allocating the virtual resource request to a distributed database storing the virtual resources according to the mapping relationship includes: The message queue corresponding to the virtual resources requested by the user is determined; Determine whether there are any messages stored in the message queue; If so, the virtual resource request is allocated to the corresponding distributed database based on the user ID, the current message in the message queue, and the mapping relationship.
5. A distributed virtual resource allocation device, characterized in that, include: The application request receiving module is used to receive users' virtual resource application requests; The message queue generation module is used to generate message queues based on the IDs corresponding to the virtual resources stored in each distributed database; wherein, the virtual resources include: shopping coupons, website memberships, movie tickets, sports event tickets, and electronic vouchers for discounts from physical stores; The virtual resource allocation module is used to allocate the virtual resources according to the message queue and the virtual resource application request; The virtual resource allocation module includes: The message quantity modification unit is used to modify the current message in the message queue according to the number of virtual resources stored in the distributed database; The mapping relationship establishment unit is used to establish a mapping relationship between the distributed database and the corresponding numbers of the virtual resources it stores; A database determination unit is used to determine, based on the current message, a distributed database that stores the virtual resources; The application request allocation unit is used to allocate the virtual resource application request to a distributed database storing the virtual resources according to the mapping relationship, so as to allocate the virtual resources; The message quantity modification unit includes: The message quantity increase unit is used to increase the message quantity accordingly based on the increase in the virtual resource quantity; The message quantity reduction unit is used to reduce the message quantity accordingly based on the amount by which the virtual resource quantity is reduced.
6. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instruction is executed by the processor, it implements the steps of the distributed virtual resource allocation method according to any one of claims 1 to 4.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the distributed virtual resource allocation method according to any one of claims 1 to 4.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the steps of the distributed virtual resource allocation method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Virtual asset transfer data processing method and device and computer equipment
CN110134531A
Message processing system and method based on distributed queue
CN111459689A