Inventory deduction method, device, computer equipment and storage medium
By chunking the total inventory and processing object acquisition requests in parallel, the problems of inaccurate inventory deduction and inefficiency in high concurrency scenarios are solved, and efficient and stable inventory management is achieved.
Patent Information
- Application Number
- CN202210202605.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-02
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2042-03-02
AI Technical Summary
In high concurrency scenarios, distributed locks based on database, cache or Zookeeper result in inaccurate inventory deductions and low efficiency.
By obtaining the number of requested objects and the total inventory object, determine the inventory chunk quantity, and perform chunking processing of the total inventory. The object acquisition request is processed in parallel, and the inventory blocks that meet the preset conditions are found according to the inventory block identification number and the inventory block number are deducted. The number of objects and inventory blocks in the inventory block are adjusted according to the request processing results.
It realizes parallel processing of inventory deduction requests, improves processing efficiency, reduces error occurrence, avoids system resource imbalance, and maintains system stability.
Smart Images

Figure CN114581008B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to an inventory deduction method, apparatus, computer equipment and storage medium. Background Art
[0002] With the development of artificial intelligence technology, high-concurrency scenarios have emerged. For example, large e-commerce platforms often have discounts, promotions, and flash sales, which result in a large number of business requests being input into computers.
[0003] Large-scale Internet applications facing a large number of users all use large-scale distributed clusters as their infrastructure. Among them, the most commonly used methods are distributed locks based on databases, distributed locks based on caches (such as Redis), and distributed locks based on Zookeeper. In high-concurrency scenarios, when dealing with inventory issues, inaccurate inventory deductions and low efficiency may occur. Summary of the invention
[0004] Based on this, it is necessary to provide a method, device, computer equipment, computer-readable storage medium and computer program product for inventory deduction that can be carried out in parallel and improve efficiency in order to solve the above technical problems.
[0005] In a first aspect, the present application provides a method for deducting inventory. The method comprises: obtaining at least two object acquisition requests; each object acquisition request is used to request the deduction of at least one object in the total inventory; determining the number of inventory blocks according to the number of object acquisition requests and the number of objects in the total inventory; dividing the total inventory into blocks according to the number of inventory blocks to obtain at least two inventory blocks corresponding to the total inventory, executing the block division and performing corresponding allocation of the objects in the total inventory at the same time; processing the at least two object acquisition requests in parallel, for each processing of an object acquisition request, the inventory block whose number of corresponding deduction objects meets a preset condition is obtained, and the request processing result corresponding to each object acquisition request is obtained; according to the request processing result corresponding to each object acquisition request, adjusting the number of objects in each inventory block and the number of inventory blocks.
[0006] In one of the embodiments, determining the number of inventory blocks according to the number of object acquisition requests and the number of objects in the total inventory includes: obtaining the minimum number of objects corresponding to each inventory block; determining the total inventory block ratio based on the number of object acquisition requests and the minimum number of objects corresponding to each inventory block, the total inventory block ratio being used to divide the block ratio of the total inventory; based on the total inventory block ratio, inputting the number of object acquisition requests and the number of objects in the total inventory into an inventory block optimization algorithm to determine the number of inventory blocks.
[0007] In one of the embodiments, the parallel processing of the at least two object acquisition requests, for each processing of the object acquisition request, correspondingly deducting the inventory block whose quantity of the object meets a preset condition to obtain a request processing result corresponding to each of the object acquisition requests, includes: identifying each of the inventory blocks using an identity identification number to obtain an inventory block identification number corresponding to each of the inventory blocks; for each processing of the object acquisition request, searching for an inventory block whose quantity of the object meets a preset condition according to the inventory block identification number as a target inventory block, and deducting the objects in the target inventory block to obtain a request processing result corresponding to each of the object acquisition requests.
[0008] In one of the embodiments, for each object acquisition request processed, an inventory block whose quantity of the objects meets a preset condition is searched according to the inventory block identification number as a target inventory block, and the objects in the target inventory block are deducted to obtain a request processing result corresponding to each object acquisition request, including: for the current object acquisition request, the target inventory block whose quantity of the objects corresponding to the current object acquisition request meets a preset condition is searched according to the inventory block identification number, and the objects in the target inventory block are deducted to obtain a request processing result corresponding to the current object acquisition request; the object acquisition request next to the current object acquisition request is used as the current object acquisition request, and the above steps are repeatedly executed until the request processing result corresponding to each object acquisition request is obtained.
[0009] In one of the embodiments, searching according to the inventory block identification number the target inventory block whose number of objects corresponding to the current object acquisition request meets a preset condition, and deducting the objects from the target inventory block, comprises: if a result of searching according to the inventory block identification number the inventory block whose number of objects meets the preset condition is one, directly deducting the inventory block whose number of objects meets the preset condition; if a result of searching according to the inventory block identification number the inventory block whose number of objects meets the preset condition is at least two, deducting the inventory block whose number of objects is the maximum value.
[0010] In one of the embodiments, adjusting the number of objects and the number of inventory blocks in each of the inventory blocks according to the request processing results corresponding to each of the object acquisition requests includes: analyzing the request processing results corresponding to each of the object acquisition requests to obtain inventory block analysis results; and adjusting the number of objects and the number of inventory blocks in each of the inventory blocks based on the inventory block analysis results to obtain the number of objects and the number of updated inventory blocks in each updated inventory block.
[0011] In a second aspect, the present application also provides a stock deduction device. The device comprises: an object acquisition request acquisition module, which is used to acquire at least two object acquisition requests; each object acquisition request is used to request the deduction of at least one object in the total inventory; an inventory block quantity determination module, which is used to determine the number of inventory blocks according to the number of object acquisition requests and the number of objects in the total inventory; an inventory block acquisition module, which is used to block the total inventory according to the number of inventory blocks, obtain at least two inventory blocks corresponding to the total inventory, execute the block division and simultaneously perform corresponding allocation of the objects in the total inventory; a request processing result acquisition module, which is used to process the at least two object acquisition requests in parallel, and for each object acquisition request, obtain the request processing result corresponding to each object acquisition request for the inventory block whose number of deduction objects meets the preset conditions; and an inventory block adjustment module, which is used to adjust the number of objects in each inventory block and the number of inventory blocks according to the request processing results corresponding to each object acquisition request.
[0012] In one of the embodiments, the inventory block quantity determination module is used to obtain the minimum number of objects corresponding to each inventory block; based on the number of object acquisition requests and the minimum number of objects corresponding to each inventory block, determine the total inventory block ratio, and the total inventory block ratio is used to divide the block ratio of the total inventory; based on the total inventory block ratio, the number of object acquisition requests and the number of objects in the total inventory are input into the inventory block optimization algorithm to determine the inventory block quantity.
[0013] In one of the embodiments, the request processing result obtaining module is used to identify each of the inventory blocks using an identity identification number to obtain an inventory block identification number corresponding to each of the inventory blocks; for each object acquisition request processed, an inventory block whose quantity of the object meets a preset condition is found according to the inventory block identification number, as a target inventory block, and the objects in the target inventory block are deducted to obtain a request processing result corresponding to each of the object acquisition requests.
[0014] In one of the embodiments, a request processing result obtaining module is used to find the target inventory block whose quantity of objects corresponding to the current object acquisition request meets a preset condition according to the inventory block identification number for the current object acquisition request, deduct the objects in the target inventory block, and obtain the request processing result corresponding to the current object acquisition request; take the object acquisition request next to the current object acquisition request as the current object acquisition request, and repeatedly execute the above steps until the request processing results corresponding to each object acquisition request are obtained.
[0015] In one of the embodiments, the request processing result obtaining module is used to directly deduct the inventory block corresponding to the quantity of the object that meets the preset condition if the result of searching the inventory block identification number for the inventory block corresponding to the quantity of the object that meets the preset condition is one; if the result of searching the inventory block identification number for the inventory block corresponding to the quantity of the object that meets the preset condition is at least two, then deduct the inventory block corresponding to the maximum value of the quantity of the object.
[0016] In one of the embodiments, the inventory block adjustment module is used to analyze the request processing results corresponding to each of the object acquisition requests to obtain an inventory block analysis result; based on the inventory block analysis result, the object quantity of each of the inventory blocks and the quantity of the inventory blocks are adjusted to obtain the object quantity of each updated inventory block and the updated inventory block quantity.
[0017] In a third aspect, the present application also provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program: obtaining at least two object acquisition requests; each object acquisition request is used to request the deduction of at least one object in the total inventory; determining the number of inventory blocks according to the number of object acquisition requests and the number of objects in the total inventory; dividing the total inventory according to the number of inventory blocks to obtain at least two inventory blocks corresponding to the total inventory, executing the block division and performing corresponding allocation of the objects in the total inventory at the same time; processing the at least two object acquisition requests in parallel, for each processing of an object acquisition request, deducting the inventory block whose number of objects meets the preset conditions, and obtaining the request processing results corresponding to each object acquisition request; adjusting the number of objects in each inventory block and the number of inventory blocks according to the request processing results corresponding to each object acquisition request.
[0018] In a fourth aspect, the present application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented: obtaining at least two object acquisition requests; each object acquisition request is used to request the deduction of at least one object in the total inventory; determining the number of inventory blocks according to the number of object acquisition requests and the number of objects in the total inventory; dividing the total inventory according to the number of inventory blocks to obtain at least two inventory blocks corresponding to the total inventory, executing the block division and performing corresponding allocation of the objects in the total inventory at the same time; processing the at least two object acquisition requests in parallel, for each processing of an object acquisition request, deducting the inventory block whose number of objects meets the preset conditions, and obtaining the request processing results corresponding to each object acquisition request; adjusting the number of objects in each inventory block and the number of inventory blocks according to the request processing results corresponding to each object acquisition request.
[0019] In a fifth aspect, the present application also provides a computer program product. The computer program product includes a computer program, which implements the following steps when executed by a processor: obtaining at least two object acquisition requests; each object acquisition request is used to request the deduction of at least one object in the total inventory; determining the number of inventory blocks according to the number of object acquisition requests and the number of objects in the total inventory; dividing the total inventory according to the number of inventory blocks to obtain at least two inventory blocks corresponding to the total inventory, executing the block division and performing corresponding allocation of the objects in the total inventory at the same time; processing the at least two object acquisition requests in parallel, for each processing of an object acquisition request, deducting the inventory block whose number of objects meets the preset conditions, and obtaining the request processing results corresponding to each object acquisition request; adjusting the number of objects in each inventory block and the number of inventory blocks according to the request processing results corresponding to each object acquisition request.
[0020] The above-mentioned inventory deduction method, device, computer equipment, storage medium and computer program product obtain at least two object acquisition requests; each object acquisition request is used to request the deduction of at least one object in the total inventory; the number of inventory blocks is determined according to the number of object acquisition requests and the number of objects in the total inventory; the total inventory is divided into blocks according to the number of inventory blocks, and the objects of the total inventory are correspondingly allocated to obtain at least two inventory blocks corresponding to the total inventory; at least two object acquisition requests are processed in parallel, and for each object acquisition request processed, the inventory block whose number of objects meets the preset conditions is deducted accordingly to obtain the request processing results corresponding to each object acquisition request; according to the request processing results corresponding to each object acquisition request, the number of objects in each inventory block and the number of inventory blocks are adjusted.
[0021] By acquiring at least two object acquisition requests from the terminal, the server can process different object acquisition requests in parallel, and the processing time can be greatly reduced; by accurately calculating the number of blocks that the total inventory needs to be divided into according to the number of object acquisition requests and the number of objects in the total inventory; by dividing the total inventory into blocks according to the number of inventory blocks, and executing the allocation of objects in the total inventory while executing the block division, the total inventory can be changed from being able to process only one object acquisition request at a time to processing multiple object acquisition requests at the same time; by processing multiple object acquisition requests in parallel, and processing the inventory blocks whose number of objects deducted from the object acquisition request meets the preset conditions, the efficiency of processing object acquisition requests can be improved while reducing errors caused by insufficient number of objects, and avoiding imbalance of system resources and maintaining system stability; by adjusting the number of objects in the inventory block and the number of inventory blocks according to the request processing results, the resources occupied by the computer can be reduced, and the allocation of computer resources can be optimized at the same time.
[0022] By splitting the total inventory according to the number of object acquisition requests and the number of objects in the total inventory, the effect of asynchronous multi-threaded inventory reduction is achieved, which solves the problem of low efficiency of serially reducing all inventories. At the same time, the inventory is split and reorganized to make each inventory block relatively evenly distributed, and the requests are processed more evenly, which avoids the problem of one thread having too many requests while other threads are idle. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 is an application environment diagram of an inventory deduction method in an embodiment;
[0024] Figure 2 A schematic diagram of a flow chart of an inventory deduction method in one embodiment;
[0025] Figure 3 A schematic diagram of a flow chart of an inventory deduction step in an embodiment;
[0026] Figure 4 It is a flowchart of the inventory deduction method in another embodiment;
[0027] Figure 5 It is a flowchart of an inventory deduction method in another embodiment;
[0028] Figure 6 A schematic diagram of a flow chart of an inventory deduction method in yet another embodiment;
[0029] Figure 7 is another flow chart of an inventory deduction method in one embodiment;
[0030] Figure 8 is an overall structural diagram of an inventory deduction method in one embodiment;
[0031] Fig. 9 A schematic diagram of the principle of generating an ID to identify each inventory block using a snowflake algorithm in one embodiment;
[0032] Fig.10 is a structural block diagram of an inventory deduction device in one embodiment;
[0033] Fig.11 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0034] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0035] The inventory deduction method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 sends a request to the server 104, the terminal 102 communicates with the server 104 through the network, and the server 104 performs calculations in response to the request of the terminal 102. After the calculation is completed, the server 104 returns the calculation result to the terminal 102. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. Obtain at least two object acquisition requests; each object acquisition request is used to request the deduction of at least one object in the total inventory; determine the number of inventory blocks according to the number of object acquisition requests and the number of objects in the total inventory; divide the total inventory into blocks according to the number of inventory blocks, and allocate the objects of the total inventory accordingly to obtain at least two inventory blocks corresponding to the total inventory; process at least two object acquisition requests in parallel, and for each object acquisition request, deduct the inventory block whose number of objects meets the preset conditions, and obtain the request processing results corresponding to each object acquisition request; according to the request processing results corresponding to each object acquisition request, adjust the number of objects in each inventory block and the number of inventory blocks. The terminal 102 may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, IoT devices, and portable wearable devices. The IoT devices may be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. The portable wearable devices may be smart watches, smart bracelets, head-mounted devices, etc. The server 104 may be implemented as an independent server or a server cluster consisting of multiple servers.
[0036] In one embodiment, Figure 2 As shown, a method of inventory deduction is provided, which is applied to Figure 1 The server in the example is used to illustrate the following steps:
[0037] Step 202: Obtain at least two object acquisition requests.
[0038] Among them, at least two can be two or more, which can be described in mathematical terms as greater than or equal to two.
[0039] The total inventory may be a way for the server to express the quantity of a certain item, a certain thing or a certain object. For example, the total inventory of mobile phones indicates the number of mobile phones.
[0040] The object may be an abstract noun for items stored in the total inventory, such as clothes in the total inventory, telephones in the total inventory, quilts in the total inventory, or medals in the total inventory.
[0041] The object acquisition request may be an instruction issued from the terminal to instruct the server to operate on the objects in the total inventory, and the operation may be a deduction of the corresponding object in the total inventory.
[0042] Specifically, the server responds to the instruction of the terminal to deduct the object corresponding to the total inventory stored in the storage unit of the server, and the deduction for the object is at least one. The object acquisition request can be input to the server in sequence in serial form, or it can be input to the server simultaneously in parallel form. The inventory coordinator in the server manages the object acquisition requests obtained from the terminal, greatly improving the processing efficiency of the server for object acquisition requests.
[0043] For example, the server receives 10 object acquisition requests from the terminal, and the objects that need to be deducted in each object acquisition request range from 1 to 5. These 10 object acquisition requests are input to the server in parallel. The inventory coordinator in the server manages these 10 object acquisition requests and reasonably calls computer resources to process these 10 object acquisition requests.
[0044] Step 204: Determine the number of inventory blocks according to the number of object acquisition requests and the number of objects in the total inventory.
[0045] The number of inventory blocks may be the number of inventory blocks into which the total inventory needs to be divided, obtained by calculating the total inventory through an inventory block optimization algorithm according to the number of object acquisition requests and the number of objects in the total inventory.
[0046] The inventory block may be a sub-inventory obtained by dividing the total inventory according to the number of inventory blocks, and the total number of the set of multiple sub-inventories is equal to the total inventory.
[0047] Specifically, the inventory block optimization algorithm is calculated according to the number of object acquisition requests and the number of objects in the total inventory. The block optimization algorithm can be a preset mathematical model, or a computer can intelligently select one from the built-in mathematical model according to the number of object acquisition requests and the number of objects in the total inventory to obtain the number of inventory blocks for dividing the total inventory. Since the total inventory is divided into blocks, the value of the inventory block number is greater than or equal to 2. The inventory coordinator in the server is responsible for calculating the number of inventory blocks, and the result will be sent to the next module after the calculation is completed.
[0048] For example, the number of object acquisition requests is 100, and the number of objects in the total inventory is 1000. The number of inventory blocks is calculated to be 20 through the linear congruential random number algorithm pre-set in the inventory coordinator. The result will be input into the next module for further processing.
[0049] Step 206, divide the total inventory into blocks according to the number of inventory blocks, and allocate the objects in the total inventory accordingly, so as to obtain at least two inventory blocks corresponding to the total inventory.
[0050] The block division may be to divide the total inventory according to the number of inventory blocks, and the total inventory after the division includes at least two inventory blocks, and each inventory block has a corresponding identifier to facilitate computer call.
[0051] The corresponding allocation of objects in the total inventory can be performed when the total inventory is split according to the number of inventory blocks, and the objects in the total inventory are allocated at the same time. Each inventory block can get a certain number of objects. The objects in each inventory block can be evenly allocated or differentially allocated according to demand.
[0052] Specifically, the total inventory is divided into blocks according to the number of inventory blocks calculated using the inventory block optimization algorithm. After the division, at least two inventory blocks corresponding to the total inventory can be obtained. While the total inventory is divided into blocks, objects in the total inventory are also allocated. The allocation can be an average allocation based on the number of inventory blocks or a differential allocation. The allocated objects are stored in the corresponding inventory blocks, and at least one object is allocated to each inventory block.
[0053] For example, the number of object acquisition requests is 100, and the number of objects in the total inventory is 1000. The linear congruential random number algorithm pre-set in the inventory coordinator is used to calculate that the number of inventory blocks is 20. Therefore, the total inventory is divided into 20 inventory blocks. While executing the blocks, the objects are also allocated. The objects in this example are allocated on the principle of average distribution, so 50 objects can be allocated to each inventory block.
[0054] Step 208, processing at least two object acquisition requests in parallel, for each object acquisition request processed, deducting the inventory block whose quantity of the object meets the preset condition, to obtain the request processing result corresponding to each object acquisition request.
[0055] Among them, parallel processing can be a computing method that can execute two or more processes simultaneously in a computer system. Parallel processing can work on different aspects of the same program at the same time. The main purpose of parallel processing is to save time in solving large and complex problems. Theoretically, the execution speed of n parallel processes may be n times that of serial execution.
[0056] Among them, the inventory blocks whose quantity of objects meets the preset conditions can be all inventory blocks whose quantity of objects meets the preset conditions after the total inventory is split. If the quantities of objects in multiple inventory blocks meet the preset conditions at the same time, then the multiple inventory blocks are inventory blocks whose quantity of objects meets the preset conditions at the same time.
[0057] Among them, the request processing result can be the deduction result corresponding to the inventory block where the quantity of the object meets the preset conditions and the corresponding deduction of the object has been carried out. If the quantity of objects in a certain inventory block always meets the preset conditions, multiple deduction results can correspond to the same inventory block.
[0058] Specifically, the number of objects that meet the conditions is preset, and multiple object acquisition requests are processed in the form of parallel processing. If the object acquisition requests are greater than or equal to two, for each object acquisition request, the computer will look for an inventory block whose current number of objects meets the preset conditions and deduct the number of objects. If there is only one inventory block that still belongs to the inventory block whose number of objects meets the preset conditions after the deduction of the number of objects, then the next deduction of the number of objects will still select this inventory block. If multiple inventory blocks are inventory blocks whose number of objects meets the preset conditions at the same time, a inventory block with the maximum number of objects is selected for deduction of the number of objects, thereby obtaining a request processing result corresponding to each object acquisition request.
[0059] For example, a stock block with the maximum number of objects to be deducted is preset, the number of objects in stock block A is 10, the number of objects in stock block B is 15, and the number of objects in stock block C is 12. There are 5 object acquisition requests processed in parallel, and each object acquisition request needs to deduct two object quantities. Then for the first object acquisition request, the stock block corresponding to the maximum number of objects, that is, stock block B, is deducted. After deduction, the number of objects in stock block B is 13, and the second object acquisition request will still deduct the number of objects in stock block B. After the second object acquisition request is deducted, the number of objects in stock block B is 11. The third object acquisition request will select stock block C for deduction. After deduction, the number of objects in stock block C is 10. The fourth object acquisition request will choose to deduct stock block B, so that the number of objects in stock block B after deduction is 9. When the fifth object acquisition request is processed, the number of objects in stock block A and stock block C is 10 at the same time. The computer will randomly deduct from stock block A or stock block C, and finally obtain the request processing result corresponding to each object acquisition request.
[0060] Step 210: adjusting the number of objects in each inventory block and the number of inventory blocks according to the request processing results corresponding to each object acquisition request.
[0061] The adjustment may be to change the number of objects in each inventory block and the number of inventory blocks according to demand, so that the available resources are more evenly distributed and the stability of the system is increased.
[0062] Specifically, according to the request processing result corresponding to each object acquisition request, the number of objects in the inventory block from which the number of objects has been deducted and the number of inventory blocks are adjusted. If it is found that the number of objects in the inventory block is close to the threshold or even lower than the threshold, the inventory in the inventory block with an inventory number higher than the threshold is split and allocated to the inventory blocks with a lower inventory number. If a large number of objects have been deducted, and even the number of objects in some inventory blocks is already 0, the number of inventory blocks is adjusted.
[0063] For example, the server receives 5 object acquisition requests from the terminal, of which 4 object acquisition requests need to deduct 2 objects, and one object acquisition request needs to deduct 20 objects. Therefore, 5 request processing results are obtained, of which 4 processing results contain information on deducting 2 objects, and 1 processing result contains information on deducting 20 objects. Because the number of objects in inventory block A is deducted by 20, it is obviously lower than the threshold. Therefore, the computer adjusts the objects in inventory block B and inventory block C to inventory block A, so that the object quantities of the three inventory blocks are relatively close, keeping the system resources evenly distributed.
[0064] In the above-mentioned inventory deduction method, at least two object acquisition requests are obtained; each object acquisition request is used to request the deduction of at least one object in the total inventory; the number of inventory blocks is determined according to the number of object acquisition requests and the number of objects in the total inventory; the total inventory is divided into blocks according to the number of inventory blocks, and the objects of the total inventory are correspondingly allocated to obtain at least two inventory blocks corresponding to the total inventory; at least two object acquisition requests are processed in parallel, and for each object acquisition request processed, the inventory block whose number of objects meets the preset conditions is deducted accordingly to obtain the request processing results corresponding to each object acquisition request; according to the request processing results corresponding to each object acquisition request, the number of objects in each inventory block and the number of inventory blocks are adjusted.
[0065] By acquiring at least two object acquisition requests from the terminal, the server can process different object acquisition requests in parallel, and the processing time can be greatly reduced; by accurately calculating the number of blocks that the total inventory needs to be divided into according to the number of object acquisition requests and the number of objects in the total inventory; by dividing the total inventory into blocks according to the number of inventory blocks, and executing the allocation of objects in the total inventory while executing the block division, the total inventory can be changed from being able to process only one object acquisition request at a time to processing multiple object acquisition requests at the same time; by processing multiple object acquisition requests in parallel, and processing the inventory blocks whose number of objects deducted from the object acquisition request meets the preset conditions, the efficiency of processing object acquisition requests can be improved while reducing errors caused by insufficient number of objects, and avoiding imbalance of system resources and maintaining system stability; by adjusting the number of objects in the inventory block and the number of inventory blocks according to the request processing results, the resources occupied by the computer can be reduced, and the allocation of computer resources can be optimized at the same time.
[0066] By splitting the total inventory according to the number of object acquisition requests and the number of objects in the total inventory, the effect of asynchronous multi-threaded inventory reduction is achieved, which solves the problem of low efficiency of serially reducing all inventories. At the same time, the inventory is split and reorganized to make each inventory block relatively evenly distributed, and the requests are processed more evenly, which avoids the problem of one thread having too many requests while other threads are idle.
[0067] In one embodiment, Figure 3 As shown, according to the number of object acquisition requests and the number of objects in the total inventory, the number of inventory blocks is determined, including:
[0068] Step 302, obtaining the minimum number of objects corresponding to each inventory block.
[0069] Among them, the minimum number of objects corresponding to each inventory block can be the minimum number of objects pre-set in each inventory block according to demand, and the minimum number of objects can be a threshold, indicating that the number of objects in the inventory block needs to be greater than or equal to the threshold, otherwise the computer will adjust the objects in the inventory block or adjust the inventory block.
[0070] Specifically, the computer obtains the minimum number of objects corresponding to each inventory block. The minimum number of objects corresponding to each inventory block can be consistent, or different thresholds can be set according to needs. The setting of the minimum number of objects can be manually set, or the computer can make a judgment based on the inventory block and the object acquisition request. Generally, the computer sets it by itself, which can greatly improve the operating efficiency of the system.
[0071] For example, a minimum number of objects is set for inventory block A, inventory block B, and inventory block C in the server, the threshold of inventory block A is 10, the threshold of inventory block B is 8, and the threshold of inventory block C is 12.
[0072] Step 304: Determine the total inventory block ratio based on the number of object acquisition requests and the minimum number of objects corresponding to each inventory block.
[0073] The total inventory block ratio can be the ratio of the part called for block to the total inventory. This ratio changes in real time and is determined based on the number of different object acquisition requests and the minimum number of objects corresponding to each inventory block. A more special total inventory block ratio is the entire total inventory or half of the total inventory.
[0074] Specifically, based on the number of object acquisition requests obtained by the server and the minimum number of objects corresponding to each inventory block, a built-in computer algorithm is used, which uses the inventory coordinator in the system to determine the proportion of the total inventory used for blocks, for example, the proportion used for blocks is one-third of the total inventory, or three-quarters, etc.
[0075] For example, the number of object acquisition requests obtained by the server is X, and there is also the minimum number of objects in the three inventory blocks, inventory block A, inventory block B, and inventory block C. Based on these four data, the proportion of the total inventory occupied is determined to be divided into blocks, such as seven-tenths, five-ninths, etc.
[0076] Step 306 , based on the total inventory block ratio, the number of object acquisition requests and the number of objects in the total inventory are input into the inventory block optimization algorithm to determine the number of inventory blocks.
[0077] Among them, the inventory block optimization algorithm can be a mathematical algorithm that calculates the number of inventory blocks based on the number of object acquisition requests and the number of objects in the total inventory. The algorithm can give a relatively reasonable value for the specific value of the number of inventory blocks, which can ensure the processing speed while reducing the occupation of computer resources.
[0078] Specifically, according to the proportion of blocks occupying the total inventory, two parameters, namely the number of object acquisition requests and the number of objects in the total inventory, are input into the inventory block optimization algorithm for calculation. The inventory block optimization algorithm can be a random number algorithm, such as a linear congruential random number algorithm and a pseudo-random number algorithm. After calculation, a relatively reasonable number of inventory blocks is obtained. Based on the number of inventory blocks, another algorithm can be used to further search for the optimal solution.
[0079] For example, through calculation, the total inventory block ratio is obtained to be one-half, and the object acquisition request quantity X and the total inventory object quantity Y are input into the linear congruential random number algorithm to calculate the specific value of the inventory block quantity. After calculation, the value of the inventory block quantity is Z, which is a relatively reasonable inventory block quantity that can meet business needs.
[0080] In this embodiment, the number of object acquisition requests and the minimum number of objects corresponding to each inventory block are used to determine the block ratio of the total inventory. By dividing part of the total inventory into blocks, the number of objects in the inventory blocks can be reduced, thereby improving the efficiency of the computer in processing object acquisition requests.
[0081] In one embodiment, Figure 4 As shown, at least two object acquisition requests are processed in parallel. For each object acquisition request, the inventory block whose quantity of the object meets the preset condition is deducted accordingly to obtain the request processing result corresponding to each object acquisition request, including:
[0082] Step 402: Identify each inventory block using the identity identification number to obtain the inventory block identification number corresponding to each inventory block.
[0083] The identification number may be a code for identifying each inventory block, each code corresponds to an inventory block, and the code can accurately represent the information in the inventory block. The code may be generated by a computer algorithm, such as a snowflake algorithm.
[0084] The inventory block identification number may be a number obtained by identifying the inventory block using the identity identification number to obtain a unique identification number for each inventory block, that is, the identity identification number becomes the inventory block identification number after identification.
[0085] Specifically, a computer algorithm is used to generate multiple identity identification numbers, the number of which must be greater than or equal to the number of inventory blocks, and each identity identification number corresponds to each inventory block. After identification, each inventory block obtains an inventory block identification number corresponding to the identity identification number. The identity identification number can be saved in a cache and the minimum threshold of the inventory quantity in the inventory block, the real-time inventory number, etc. can be set and associated with it. The generation of the identity identification number does not rely on a database and is completely operated in memory. Millions of self-incrementing identity identification numbers can be generated per second, and the efficiency is very high.
[0086] For example, the total inventory is divided into M inventory blocks by blocking, and the snowflake algorithm is used to generate identification numbers greater than or equal to M. These identification numbers are used to identify the M inventory blocks one by one to obtain the inventory block identification numbers corresponding to each of the M inventory blocks.
[0087] Step 404, for each object acquisition request, a stock block whose number of objects meets a preset condition is searched according to the stock block identification number as a target stock block, and the objects in the target stock block are deducted to obtain a request processing result corresponding to each object acquisition request.
[0088] Among them, satisfying the preset condition may be that the number of objects in the inventory block meets a predetermined condition, which may be set manually or by a computer based on actual conditions. The condition is a dynamic parameter that changes in real time as the system parameters change.
[0089] Among them, the target inventory block can be an inventory block that meets the preset conditions but has not yet been deducted. If there are multiple inventory blocks that meet the conditions, the inventory block with the largest number of selected objects will be selected as the target inventory block. When deducting, it will be deducted from the inventory block with the largest number of selected objects.
[0090] Specifically, for each object acquisition request, the computer will search for an inventory block whose number of objects meets the pre-set conditions based on the inventory block identification number, and use it as the target inventory block. If there are multiple inventory blocks that meet the conditions, the inventory block with the largest number of objects will be selected as the target inventory block. Then, the objects in the target inventory block will be deducted according to the data in the object acquisition request to obtain the request processing results corresponding to each object acquisition request.
[0091] For example, the number of object acquisition requests obtained by the server is X, and it is preset that the number of objects in the inventory blocks participating in the object deduction must not be less than 100. For an object acquisition request, the computer will look for an inventory block with an object number greater than or equal to 100 as the target inventory block. The result is that the number of objects in the 8 target inventory blocks meets the preset condition. Therefore, the server selects the one with the largest number of objects from the 8 target inventory blocks as the target inventory block for deduction. After the deduction, the request processing result corresponding to the object acquisition request is obtained. For each object acquisition request, the above process is repeated to obtain the request processing result corresponding to each object acquisition request.
[0092] In this embodiment, by using an identity number to identify each inventory block, it is possible to quickly and accurately locate inventory blocks that meet preset conditions, and perform object deductions on these inventory blocks, which greatly improves the efficiency and accuracy of deducting objects, while also avoiding excessive deductions of inventory blocks with a low number of objects.
[0093] In one embodiment, Figure 5 As shown, for each object acquisition request, a stock block whose number of objects meets a preset condition is found according to the stock block identification number as the target stock block, and the objects in the target stock block are deducted to obtain the request processing result corresponding to each object acquisition request, including:
[0094] Step 502, for the current object acquisition request, find the target inventory block whose quantity of objects corresponding to the current object acquisition request meets the preset conditions according to the inventory block identification number, deduct the objects in the target inventory block, and obtain the request processing result corresponding to the current object acquisition request.
[0095] The current object acquisition request may be an object acquisition request that is currently being processed by the server, or an object acquisition request that the server is currently idle and is ready to process.
[0096] Specifically, the conditions for the inventory blocks that can be used as deduction objects are set in advance. For the object acquisition request that needs to be processed currently, the target inventory block whose quantity of objects meets the preset conditions is found according to the inventory block identification number in the identified inventory block to process the current object acquisition request, and then the objects in the target inventory block are deducted to obtain the request processing result corresponding to the current object acquisition request.
[0097] For example, only inventory blocks with a preset number of objects greater than or equal to 1000 can be used as deduction objects. For the object acquisition request H that currently needs to be processed, the target inventory block A that can satisfy the object acquisition request for deduction that currently needs to be processed is found according to the inventory block identification number, and then the objects in the target inventory block A are deducted to obtain the request processing result corresponding to the current object acquisition request H.
[0098] Step 504: take the next object acquisition request of the current object acquisition request as the current object acquisition request, and repeat the above steps until the request processing results corresponding to each object acquisition request are obtained.
[0099] The next object acquisition request may be the next object acquisition request that needs to be processed in the processing order from the server relative to the current object acquisition request. The two object acquisition requests have the same properties and require the same processing steps.
[0100] Specifically, after processing all steps of the current object acquisition request, the next object acquisition request is used as the current object acquisition request, that is, the server will process the next object acquisition request, and then repeat all the above steps to obtain the request processing result corresponding to the next object acquisition request. The same processing is performed on all object acquisition requests until the request processing result corresponding to each object acquisition request is obtained.
[0101] For example, it is preset that only inventory blocks with a quantity of objects greater than or equal to 1000 can be used as deduction objects, and the next object acquisition request I to be processed is used as the object acquisition request currently to be processed, and then the above steps are repeated to obtain the request processing result corresponding to the next object acquisition request I to be processed, and the same processing is performed on all object acquisition requests until the request processing result corresponding to each object acquisition request is obtained.
[0102] In this embodiment, each object acquisition request is processed in a loop, and the target inventory block that meets the preset conditions is deducted each time a deduction operation is performed until the request processing results corresponding to all object acquisition requests are obtained. This ensures that each object acquisition request can be deducted from the target inventory block that meets the preset conditions, thereby making the resources of the computer system relatively balanced and maintaining the stability of computer processing.
[0103] In one embodiment, Figure 6 As shown, according to the inventory block identification number, searching for a target inventory block whose quantity of objects corresponding to the current object acquisition request meets a preset condition, and deducting the objects in the target inventory block, includes:
[0104] Step 602: if the result of searching for the inventory block whose quantity of the object meets the preset condition according to the inventory block identification number is one, then directly deduct the inventory block whose quantity of the object meets the preset condition.
[0105] Specifically, if the number of objects found according to the inventory block identification number can meet the preset conditions and the result of the corresponding inventory block is one, then for the object acquisition request that currently needs to be processed, the objects in the inventory block that meet the preset conditions are directly deducted to complete the processing of the object acquisition request that currently needs to be processed.
[0106] For example, only inventory blocks with a preset number of objects greater than or equal to 1000 can be used as deduction objects. The number of objects found through the inventory block identification number can meet the preset conditions, and the corresponding inventory block result is one, which is inventory block A. Then, for the object acquisition request H that currently needs to be processed, inventory block A is the only choice. Therefore, by selecting the objects in inventory block A for deduction, the processing of the object acquisition request H that currently needs to be processed can be completed.
[0107] Step 604: if the result of searching for inventory blocks corresponding to the quantity of objects that meets the preset condition according to the inventory block identification number is at least two, then deduct the inventory block corresponding to the maximum quantity of objects.
[0108] Specifically, if the number of objects found according to the inventory block identification number can satisfy the preset condition that the corresponding inventory block is at least two, then for the object acquisition request that currently needs to be processed, the objects of the inventory block with the maximum number of objects in the inventory block that satisfies the preset condition are deducted, and the processing of the object acquisition request that currently needs to be processed can be completed.
[0109] For example, only inventory blocks with a preset number of objects greater than or equal to 1000 can be used as deduction objects, and the number of objects found through the inventory block identification number can meet the preset conditions, and the corresponding inventory blocks are at least two results. For example, there are 2000 objects in inventory block A, 2100 objects in inventory block B, 2050 objects in inventory block C, and 2080 objects in inventory block D. Then, for the object acquisition request I that currently needs to be processed, the inventory block with the largest number of objects in the inventory block is selected for deduction. Therefore, the objects in inventory block B are selected for deduction, and the processing of the object acquisition request I that currently needs to be processed can be completed.
[0110] In this embodiment, by computer identifying the inventory blocks to be deducted in different situations, it is possible to always deduct the inventory block with the largest number of objects when processing object acquisition requests, ensuring that insufficient number of objects is unlikely to occur during deduction.
[0111] In one embodiment, Figure 7 As shown, according to the request processing result corresponding to each object acquisition request, the number of objects in each inventory block and the number of inventory blocks are adjusted, including:
[0112] Step 702: Analyze the request processing results corresponding to each object acquisition request to obtain the inventory block analysis results.
[0113] The inventory block analysis result may be a result obtained by analyzing the request processing results corresponding to each object acquisition request using a mathematical model, thereby including the features of each request processing result.
[0114] Specifically, the request processing result corresponding to each object acquisition request is input into a preset mathematical model for analysis. The mathematical model is at least two and is pre-set in the computer. When needed, it is automatically retrieved according to actual conditions, and can also be selected through human intervention. After analysis, the inventory block analysis result is obtained.
[0115] For example, mathematical analysis model 1, mathematical analysis model 2 and mathematical analysis model 3 are pre-set in the computer, and the request processing results corresponding to each object acquisition request are simultaneously input into the computer. The computer selects mathematical analysis model 3 to analyze each request processing result according to the actual situation to obtain the analyzed inventory block analysis results.
[0116] Step 704: adjust the object quantity and the quantity of each inventory block based on the inventory block analysis result to obtain the object quantity and the updated inventory block quantity of each updated inventory block.
[0117] The updated inventory block object quantity may be the quantity of each inventory block object obtained by appropriately adjusting the current inventory block object quantity according to the inventory block analysis result.
[0118] The updated inventory block quantity may be the quantity of inventory blocks obtained by appropriately adjusting the current inventory block quantity according to the inventory block analysis result.
[0119] Specifically, according to the inventory block analysis results, the object quantity of the inventory block that has processed the object acquisition request and the inventory block quantity are adjusted. The adjustment can be splitting, reorganization, extraction and new creation, etc. After the adjustment, the object quantity of each updated inventory block and the updated inventory block quantity are obtained.
[0120] For example, after analysis, an inventory block analysis result Q is obtained, and the number of objects in the inventory block and the number of inventory blocks are split, extracted, and reorganized according to the inventory block analysis result Q. After the adjustment, a relatively average number of objects in each updated inventory block and the number of updated inventory blocks are obtained.
[0121] In this embodiment, by analyzing the processing results of each request, and then using the inventory block analysis results to adjust the number of objects and the number of inventory blocks in the inventory block, it is possible to adjust computer resources and provide a good system environment for the next processing.
[0122] In one embodiment, for this technical solution, the specific implementation method is as follows. This technical solution implements the "inventory coordinator" based on the snowflake algorithm to evenly distribute the total inventory into N inventory blocks. For example, if the inventory is 100, 10 requests are initiated at the same time, and the total inventory is evenly divided into 10 inventory blocks, each with 10 inventory. Each request is calculated in the corresponding inventory block, which is equivalent to 10 threads operating in parallel. The inventory is deducted through distributed locks in the inventory block of each thread to ensure that there is no overselling problem. In this way, the method of asynchronous inventory deduction is implemented, which greatly improves efficiency. The distributed locks mentioned above are the following: database locks, cache locks, and Zookeeper locks. The overall structure is as follows: Figure 8 shown.
[0123] The inventory coordinator evenly distributes the total inventory into a corresponding number of inventory blocks, monitors the inventory quantity in the inventory blocks in real time, evenly distributes requests to the corresponding inventory blocks, and can replenish the inventory to the inventory blocks that are about to be consumed in advance. When the number of requests increases, the inventory quantity in each inventory block can be adjusted in real time, a certain number of stocks can be drawn and then new inventory blocks can be added. When the number of requests decreases, a certain number of inventory blocks can be deleted and the inventory quantity can be evenly distributed to other inventory blocks.
[0124] 1. Inventory allocation device: Linear congruential random number algorithm divides the inventory into multiple inventory blocks.
[0125] Formula: RandSeed=(A*RandSeed+B)%M
[0126] The most important thing about the linear congruential method is to define three integers, the multiplier A, the increment B, and the modulus M, where A, B, and M are constants set by the generator. The maximum period of LCG is M, but in most cases it will be less than M. To make LCG reach the maximum period, the following conditions should be met:
[0127] ① B and M are mutually prime;
[0128] ②All prime factors of M can divide A-1;
[0129] ③If M is a multiple of 4, so is A-1;
[0130] ④A, B, N[0] are all smaller than M;
[0131] ⑤A and B are positive integers.
[0132] This algorithm is the oldest and most widely known random number generator algorithm, which generates pseudo-random numbers through a recursive formula. Because the total inventory quantity is variable and needs to be determined according to specific needs, the algorithm can split the inventory blocks according to the specific total inventory quantity and the request quantity. The total inventory can be split completely, or only half of the inventory can be split if the request is small.
[0133] For example: the total inventory is 100, we set the minimum inventory number of each inventory block to 10 and the maximum inventory number to 20. If the current request number is 10, the entire inventory is split into 10 inventory blocks, and the inventory number in each inventory block is 10. If the current request number is 5, the entire inventory can be split into 5 inventory blocks, and the inventory number in each inventory block is 20, or half of the total inventory can be split into 5 inventory blocks, and the inventory number in each inventory block is 10. Of course, the latter is more efficient, because the latter has a smaller number of inventory blocks, and the waiting time for locking and releasing locks will be much shorter.
[0134] Receive notifications from monitoring devices in real time and split or reorganize inventory. If it is found that the inventory count in an inventory block is close to the threshold or even below the threshold, the inventory in the inventory block with inventory count higher than the threshold will be split and allocated to the inventory block with lower inventory count. If the number of real-time requests increases and the number of existing inventory blocks cannot meet the demand, the inventory count will be extracted from the inventory block with higher inventory count and a new inventory block will be created, which is equivalent to adding threads to process requests and realize inventory reorganization.
[0135] 2. Snowflake algorithm generates ID (structure such as Fig. 9 as shown) to identify each inventory block.
[0136] The ID is saved in the cache and the minimum threshold of the inventory quantity in the inventory block, the real-time inventory quantity, etc. are associated with it. The ID generation does not rely on the database, and is completely operated in memory. Millions of self-incrementing IDs can be generated per second, which is very efficient.
[0137] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0138] 3. The monitoring device processes inventory in real time.
[0139] The number of requests is monitored in real time and the inventory allocation device is notified. The allocation device performs inventory reorganization operations according to the real-time number of requests.
[0140] The inventory quantity in the existing inventory block is monitored in real time by ID and compared with the minimum threshold. If it is found to be close to the threshold or even lower than the threshold, the inventory allocation device is notified to perform the inventory splitting operation.
[0141] This technical solution splits the total inventory through the inventory coordinator to achieve the effect of asynchronous multi-threaded inventory reduction, solving the problem of low efficiency of serially reducing all inventories. It can also monitor, split and reorganize the inventory in real time, so that each inventory block is relatively even, processing requests more evenly, and there will be no problem of one thread having too many requests while other threads are idle.
[0142] Based on the same inventive concept, the embodiment of the present application also provides an inventory deduction device for implementing the above-mentioned inventory deduction method. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above-mentioned method, so the specific limitations in one or more inventory deduction device embodiments provided below can refer to the above-mentioned limitations on the inventory deduction method, and will not be repeated here.
[0143] In one embodiment, Fig.10 As shown, a stock deduction device is provided, comprising: an object acquisition request acquisition module, an inventory block quantity determination module, an inventory block acquisition module, a request processing result acquisition module and an inventory block adjustment module, wherein:
[0144] The object acquisition request acquisition module 1002 is used to acquire at least two object acquisition requests; each object acquisition request is used to request the deduction of at least one object in the total inventory;
[0145] The inventory block quantity determination module 1004 is used to determine the inventory block quantity according to the quantity of object acquisition requests and the number of objects in the total inventory;
[0146] The inventory block obtaining module 1006 is used to divide the total inventory into blocks according to the inventory block quantity, and to make corresponding allocations to the objects of the total inventory to obtain at least two inventory blocks corresponding to the total inventory;
[0147] The request processing result obtaining module 1008 is used to process at least two object acquisition requests in parallel, and for each object acquisition request processed, the inventory block whose quantity of the object meets the preset condition is deducted accordingly to obtain the request processing result corresponding to each object acquisition request;
[0148] The inventory block adjustment module 1010 is used to adjust the number of objects in each inventory block and the number of inventory blocks according to the request processing results corresponding to each object acquisition request.
[0149] In one of the embodiments, an inventory block quantity determination module is used to obtain the minimum number of objects corresponding to each inventory block; based on the number of object acquisition requests and the minimum number of objects corresponding to each inventory block, a total inventory block ratio is determined, and the total inventory block ratio is used to divide the block ratio of the total inventory; based on the total inventory block ratio, the number of object acquisition requests and the number of objects in the total inventory are input into the inventory block optimization algorithm to determine the inventory block quantity.
[0150] In one of the embodiments, the request processing result obtaining module is used to identify each inventory block using an identity identification number to obtain an inventory block identification number corresponding to each inventory block; for each object acquisition request processed, an inventory block whose number of objects meets a preset condition is found according to the inventory block identification number, as the target inventory block, and the objects in the target inventory block are deducted to obtain the request processing result corresponding to each object acquisition request.
[0151] In one of the embodiments, a request processing result obtaining module is used to find a target inventory block whose quantity of objects corresponding to the current object acquisition request meets a preset condition according to an inventory block identification number for the current object acquisition request, deduct the objects in the target inventory block, and obtain a request processing result corresponding to the current object acquisition request; use the next object acquisition request of the current object acquisition request as the current object acquisition request, and repeatedly execute the above steps until the request processing results corresponding to each object acquisition request are obtained.
[0152] In one of the embodiments, a request processing result obtaining module is used to directly deduct the inventory block whose quantity of objects meets the preset condition if the result of searching the inventory block identification number for the inventory block corresponding to the quantity of objects that meets the preset condition is one; if the result of searching the inventory block identification number for the inventory block corresponding to the quantity of objects that meets the preset condition is at least two, then deduct the inventory block corresponding to the maximum value of the quantity of objects.
[0153] In one of the embodiments, the inventory block adjustment module is used to analyze the request processing results corresponding to each object acquisition request to obtain an inventory block analysis result; based on the inventory block analysis result, the object quantity and the quantity of inventory blocks of each inventory block are adjusted to obtain the object quantity and the updated inventory block quantity of each updated inventory block.
[0154] Each module in the above-mentioned inventory deduction device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0155] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.11 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store server data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for inventory deduction is implemented.
[0156] Those skilled in the art will understand that Fig.11 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0157] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0158] In one embodiment, a computer-readable storage medium is provided, storing a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0159] In one embodiment, a computer program product or computer program is provided, the computer program product or computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the steps in the above-mentioned method embodiments.
[0160] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0161] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0162] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0163] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be construed as limiting the scope of the present application. It should be noted that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for reducing inventory, characterized in that: The method comprises: Obtain at least two object acquisition requests; each of the object acquisition requests is used to request a deduction of at least one object in the total inventory; Get the minimum number of objects corresponding to each inventory block; Determine a total inventory block ratio based on the number of object acquisition requests and the minimum number of objects corresponding to each inventory block, wherein the total inventory block ratio is used to divide the total inventory into block ratios; Based on the total inventory block ratio, the number of the object acquisition requests and the number of objects in the total inventory are input into an inventory block optimization algorithm to determine the number of inventory blocks; Divide the total inventory into blocks according to the number of inventory blocks, and allocate the objects of the total inventory accordingly to obtain at least two inventory blocks corresponding to the total inventory; Processing the at least two object acquisition requests in parallel, and for each object acquisition request processed, deducting the inventory block whose quantity of the object meets a preset condition, to obtain a request processing result corresponding to each object acquisition request; According to the request processing result corresponding to each of the object acquisition requests, the number of objects and the number of inventory blocks in each of the inventory blocks are adjusted.
2. The method according to claim 1, characterized in that The parallel processing of the at least two object acquisition requests, for each processing of the object acquisition request, correspondingly deducting the inventory block whose quantity of the object meets a preset condition, to obtain a request processing result corresponding to each of the object acquisition requests, includes: Identify each of the inventory blocks using an identity identification number to obtain an inventory block identification number corresponding to each of the inventory blocks; For each object acquisition request, an inventory block whose quantity of the object meets a preset condition is searched according to the inventory block identification number as a target inventory block, and the object in the target inventory block is deducted to obtain a request processing result corresponding to each object acquisition request.
3. The method according to claim 2, characterized in that The object acquisition request is a current object acquisition request. For each processing of the object acquisition request, searching, according to the inventory block identification number, for an inventory block whose quantity of the object meets a preset condition as a target inventory block, and deducting the object in the target inventory block to obtain a request processing result corresponding to each object acquisition request, includes: For the current object acquisition request, searching, according to the inventory block identification number, for the target inventory block whose quantity of objects corresponding to the current object acquisition request meets a preset condition, deducting the objects in the target inventory block to obtain a request processing result corresponding to the current object acquisition request; The object acquisition request next to the current object acquisition request is used as the current object acquisition request, and the above steps are repeatedly executed until the request processing results corresponding to each object acquisition request are obtained.
4. The method according to claim 3, characterized in that: The step of searching, according to the inventory block identification number, for the target inventory block whose quantity of objects corresponding to the current object acquisition request meets a preset condition, and deducting the objects in the target inventory block comprises: If the result of searching the inventory block identification number for the inventory block corresponding to the quantity of the object that meets the preset condition is one, directly deduct the inventory block corresponding to the quantity of the object that meets the preset condition; If the result of searching the inventory blocks for the quantity of the objects that meets the preset condition according to the inventory block identification number is at least two, the inventory block corresponding to the maximum quantity of the objects is deducted.
5. The method according to claim 1, characterized in that The adjusting the number of objects and the number of inventory blocks in each inventory block according to the request processing result corresponding to each object acquisition request includes: Analyze the request processing results corresponding to the object acquisition requests to obtain inventory block analysis results; The object quantity of each inventory block and the quantity of the inventory block are adjusted based on the inventory block analysis result to obtain the object quantity of each updated inventory block and the updated inventory block quantity.
6. A stock deduction device, characterized in that: The device comprises: An object acquisition request acquisition module, used to acquire at least two object acquisition requests; each of the object acquisition requests is used to request the deduction of at least one object in the total inventory; An inventory block quantity determination module, used to determine the inventory block quantity according to the quantity of the object acquisition request and the quantity of objects in the total inventory; An inventory block obtaining module is used to divide the total inventory into blocks according to the inventory block quantity, obtain at least two inventory blocks corresponding to the total inventory, and perform the block division and corresponding allocation of objects in the total inventory at the same time; a request processing result obtaining module, configured to process the at least two object acquisition requests in parallel, and for each processing of the object acquisition request, deduct the inventory block whose quantity of the object meets the preset condition, to obtain the request processing result corresponding to each of the object acquisition requests; An inventory block adjustment module, configured to adjust the number of objects in each inventory block and the number of inventory blocks according to a request processing result corresponding to each object acquisition request; The inventory block quantity determination module is specifically used to obtain the minimum number of objects corresponding to each inventory block; based on the number of object acquisition requests and the minimum number of objects corresponding to each inventory block, determine the total inventory block ratio, and the total inventory block ratio is used to divide the block ratio of the total inventory; based on the total inventory block ratio, the number of object acquisition requests and the number of objects in the total inventory are input into the inventory block optimization algorithm to determine the inventory block quantity.
7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
9. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Fragment-based inventory management method and device
CN110310060A