Detailed Description
The present application will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present application more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
The inventory deduction method provided by the embodiment of the application can be applied to an application environment shown in fig. 1. The terminal 102 sends a request to the server 104, the terminal 102 communicates with the server 104 through a network, the server 104 calculates corresponding to the request of the terminal 102, and the server 104 returns the calculation result to the terminal 102 after the calculation is completed. The data storage system may store data that the server 104 needs to process. The data storage system may be integrated on the server 104 or may be located on a cloud or other network server. The method comprises the steps of obtaining at least two object obtaining requests, obtaining at least one object in a total stock by each object obtaining request, determining the stock partition number according to the number of the object obtaining requests and the number of the objects in the total stock, partitioning the total stock according to the stock partition number, correspondingly distributing the objects in the total stock to obtain at least two stock blocks corresponding to the total stock, processing the at least two object obtaining requests in parallel, correspondingly deducting the stock blocks of which the number of the objects meets the preset condition for each object obtaining request to obtain a request processing result corresponding to each object obtaining request, and adjusting the number of the objects in each stock block and the number of the stock blocks according to the request processing result corresponding to each object obtaining request. The terminal 102 may be, but not limited to, various personal computers, notebook computers, smart phones, tablet computers, internet of things devices, and portable wearable devices, where the internet of things devices may be smart speakers, smart televisions, smart air conditioners, smart vehicle devices, and the like. The portable wearable device may be a smart watch, smart bracelet, headset, or the like. The server 104 may be implemented as a stand-alone server or as a server cluster of multiple servers.
In one embodiment, as shown in fig. 2, there is provided an inventory deduction method, which is illustrated by taking the server in fig. 1 as an example, and includes the following steps:
Step 202, at least two object acquisition requests are acquired.
Wherein, at least two can be two or more, and the description is more than or equal to two by mathematical language.
The total stock may be a way of indicating the number of the same article, something or an object, for example, the total stock of the mobile phone indicates the number of the article.
The object may be an abstract term of an item stored in the main memory, such as clothes in the main memory, telephone in the main memory, quilt in the main memory or medal in the main memory, etc.
The object obtaining request may be an instruction sent from the terminal to instruct the server to operate on the object in the total repository, where the operation may be deduction on a corresponding object in the total repository.
Specifically, the server responds to the instruction of the terminal to deduct the object corresponding to the master repository stored in the storage unit of the server, at least one deduction is performed on the object, the object acquisition request can be sequentially and serially input to the server or can be simultaneously input to the server in a parallel mode, and the inventory coordinator in the server manages the object acquisition request acquired from the terminal, so that the processing efficiency of the object-oriented acquisition request of the server is greatly improved.
For example, the server obtains 10 object obtaining requests from the terminal, and the objects to be deducted in each object obtaining request are different from 1 to 5, the 10 object obtaining requests are input to the server in a parallel manner, the inventory coordinator in the server manages the 10 object obtaining requests, and reasonably invokes the computer resource to process the 10 object obtaining requests.
Step 204, determining the inventory blocking number according to the number of the object acquisition requests and the number of the objects in the total inventory.
The number of inventory blocks may be the number of inventory blocks required to be divided into a plurality of inventory blocks according to the number of object acquisition requests and the number of objects in the total inventory, which are obtained by calculating the total inventory through an inventory block optimization algorithm.
The inventory block may be a sub-inventory obtained by dividing the total inventory according to the number of inventory dividing blocks, and the total number of the sets of the plurality of sub-inventories is equal to the total inventory.
Specifically, according to the number of object acquisition requests and the number of objects in the total inventory, the inventory blocking optimization algorithm is calculated, and the blocking optimization algorithm can be a preset mathematical model, or a computer can intelligently select one from the built-in mathematical models according to the number of object acquisition requests and the number of objects in the total inventory, so as to obtain the inventory blocking number for blocking the total inventory, and because the total inventory is blocked, the value of the inventory blocking number is greater than or equal to 2, the calculation of the inventory blocking number is the responsibility of an inventory coordinator in a server, and after the calculation is finished, the result is sent to the next module.
For example, the number of object acquisition requests is 100, and the number of objects in the total inventory is 1000, and the number of inventory blocks is 20 by calculating through a linear congruence random number algorithm preset in the inventory coordinator, and the obtained result is input into the next module for further processing.
And 206, partitioning the total inventory according to the inventory partitioning number, and correspondingly distributing the objects of the total inventory to obtain at least two inventory blocks corresponding to the total inventory.
The partitioning can be performed by splitting the total stock according to the stock partitioning quantity, the split total stock comprises at least two stock blocks, and each stock block is provided with a corresponding identifier, so that the computer can conveniently call.
The corresponding allocation of the objects of the total inventory can be that the objects of the total inventory are allocated when the total inventory is split according to the inventory partition number, each inventory block can obtain a certain number of objects, and the objects in each inventory block can be evenly allocated or differentially allocated according to the requirement.
Specifically, the total inventory is partitioned according to the inventory partition number calculated by using the inventory partition optimization algorithm, at least two inventory blocks corresponding to the total inventory can be obtained after the partitioning, the partitioning of the total inventory is performed, and meanwhile, the distribution of the objects in the total inventory is also performed, wherein the distribution can be performed according to the average distribution or the difference distribution of the inventory blocks, the distributed objects are stored in the corresponding inventory blocks, and at least one object is distributed in each inventory block.
For example, the number of object acquisition requests is 100, and the number of objects in the total inventory is 1000, and the number of inventory blocks is 20 by calculating through a linear congruence random number algorithm preset in the inventory coordinator, so that the total inventory is divided into 20 inventory blocks, the distribution of the objects is performed while the block division is performed, and the distribution of the objects in this example adopts the principle of average distribution, so that 50 objects can be distributed in each inventory block.
Step 208, processing at least two object acquisition requests in parallel, and for each object acquisition request, correspondingly deducting inventory blocks of which the number of objects meets a preset condition, so as to obtain a request processing result corresponding to each object acquisition request.
The parallel processing may be a calculation method capable of executing two or more processes simultaneously in a computer system, the parallel processing may work on different aspects of the same program simultaneously, the main purpose of the parallel processing is to save the time for solving large and complex problems, and the execution speed of n parallel processing may be n times of the speed of serial execution in theoretical calculation.
The inventory blocks with the number of the objects meeting the preset conditions can be all inventory blocks with the number of the objects meeting the preset conditions after the total inventory is split, and if the number of the objects in the inventory blocks meets the preset conditions at the same time, the inventory blocks are all inventory blocks with the number of the objects meeting the preset conditions at the same time.
The request processing result may be a deduction result corresponding to the inventory block after the number of objects meets the preset condition and the inventory block has performed corresponding deduction on the objects, and if the number of objects in a certain inventory block is always equal to the preset condition, the plurality of deduction results may be corresponding to the same inventory block.
Specifically, the number of preset objects satisfies the condition, processing a plurality of object acquisition requests in a parallel processing mode, for the number of object acquisition requests being greater than or equal to two, searching for an inventory block with the number of current objects satisfying the preset condition for object number deduction corresponding to each object acquisition request, if only one inventory block is deducted by the number of objects and still belongs to the inventory block with the number of objects satisfying the preset condition, still selecting the inventory block for next object number deduction, and if a plurality of inventory blocks are simultaneously inventory blocks with the number of objects satisfying the preset condition, selecting one inventory block with the number of objects being the maximum value for object number deduction, thereby obtaining the request processing result corresponding to each object acquisition request.
For example, an inventory block with the maximum number of deducted objects is preset, the number of objects of the inventory block a is 10, the number of objects of the inventory block B is 15, the number of objects of the inventory block C is 12, 5 object obtaining requests are processed in parallel, each object obtaining request needs to deduct two object numbers, then for a first object obtaining request, the inventory block corresponding to the maximum number of deducted objects, that is, the inventory block B is deducted, the number of objects of the inventory block B after deduction is 13, while a second object obtaining request still deducts the number of objects of the inventory block B, when the second object obtaining request deducts, the number of objects of the inventory block B is 11, a third object obtaining request selects the inventory block C for deduction, the number of objects of the inventory block C after deduction is 10, a fourth object obtaining request selects the inventory block B for deduction, so that the number of objects of the inventory block B after deduction is 9, when a fifth object obtaining request is processed, the number of objects of the inventory block a and the inventory block C is 10 at the same time, and a computer obtains a result corresponding to each of the deducted objects from the inventory block a.
Step 210, according to the request processing result corresponding to each object obtaining request, the number of objects in each inventory block and the number of inventory blocks are adjusted.
The adjustment may be to change the number of objects in each inventory block and the number of inventory blocks according to the requirement, so that the available resources are more even, and the stability of the system is increased.
Specifically, according to the request processing result corresponding to each object obtaining request, the number of objects in the inventory blocks with the object number reduced and the number of inventory blocks are adjusted, if the object number in the inventory blocks is found to be close to the threshold value or even lower than the threshold value, the inventory in the inventory blocks with the inventory number higher than the threshold value is split and distributed into the inventory blocks with lower inventory number, and if a large number of objects are already reduced and even the object number in some inventory blocks is 0, the number of inventory blocks is adjusted.
For example, the server obtains 5 object obtaining requests from the terminal, wherein 4 object obtaining requests need to deduct 2 object numbers, one object obtaining request needs to deduct 20 object numbers, so as to obtain 5 request processing results, wherein the 4 processing results contain information of deducting 2 object numbers, the 1 processing result contains information of deducting 20 object numbers, and the inventory block A is obviously lower than a threshold value because of deducting 20 object numbers, so that the computer adjusts the object numbers in the inventory block B and the inventory block C into the inventory block A, the object numbers of three inventory blocks are relatively close, and the average allocation of resources of the system is maintained.
The inventory deduction method comprises the steps of obtaining at least two object obtaining requests, obtaining at least one object in a total inventory by each object obtaining request, determining the inventory blocking number according to the number of the object obtaining requests and the number of the objects in the total inventory, blocking the total inventory according to the inventory blocking number, correspondingly distributing the objects in the total inventory to obtain at least two inventory blocks corresponding to the total inventory, processing the at least two object obtaining requests in parallel, obtaining a request processing result corresponding to each object obtaining request by corresponding deduction of the number of the objects to the inventory blocks meeting preset conditions, and adjusting the number of the objects in each inventory block and the number of the inventory blocks according to the request processing result corresponding to each object obtaining request.
The server can process different object acquisition requests in parallel by acquiring at least two object acquisition requests from the terminal, processing time can be greatly reduced, the number of the blocks to be processed can be accurately calculated according to the number of the object acquisition requests and the number of the objects in the total stock, the total stock can be changed from processing only one object acquisition request to processing a plurality of object acquisition requests at the same time by executing the block division on the total stock while the block division is executed on the total stock, the efficiency of processing the object acquisition requests can be improved, errors caused by the insufficient number of the objects can be reduced while the unbalance of system resources is avoided, the stability of the system is maintained, and the resource occupying a computer can be reduced and the resource allocation of the computer is optimized by adjusting the number of the objects in the stock blocks and the number of the stock blocks according to the request processing result.
The total stock is split according to the number of the object acquisition requests and the number of the objects in the total stock, so that the asynchronous multithreading stock reduction effect is realized, the problem of low stock reduction efficiency of all stock serial is solved, meanwhile, the stock is split and recombined, the relative average in each stock block is realized, the processing requests are more uniform, the problems that one thread has excessive requests and other threads are idle are avoided.
In one embodiment, as shown in FIG. 3, determining the number of inventory chunks based on the number of object acquisition requests and the number of objects in the total inventory includes:
step 302, obtaining the minimum number of objects corresponding to each inventory block.
The minimum number of objects corresponding to each inventory block may be a minimum number of objects preset according to the requirement in each inventory block, and the minimum number of objects may be a threshold value, which indicates that the number of objects in the inventory block needs to be greater than or equal to the threshold value, otherwise, the computer will adjust the objects in the inventory block or adjust the inventory block.
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, different thresholds can be set according to requirements, the setting of the minimum number of objects can be manually set, the computer can judge according to the conditions of the inventory blocks and the object obtaining requests, and the computer can set the minimum number of objects generally, so that the operation efficiency of the system can be greatly improved.
For example, the minimum number of objects is set for inventory block a, inventory block B, and inventory block C in the server, the threshold for inventory block a is 10, the threshold for inventory block B is 8, and the threshold for inventory block C is 12.
Step 304, determining the total stock partition proportion based on the number of the object acquisition requests and the minimum number of objects corresponding to each stock block.
The proportion of the total stock memory blocks can be the proportion of the parts which are called to be blocked to the total stock, the proportion is changed in real time and can be determined according to the number of different object acquisition requests and the minimum object number corresponding to each stock block, and the proportion of the specific total stock memory blocks is the whole stock or half of the total stock.
Specifically, according to the number of object acquisition requests acquired by the server and the minimum number of objects corresponding to each inventory block, an internal computer algorithm is used for determining the proportion of the total inventory for blocking by using an inventory coordinator in the system, for example, the proportion for blocking is one third, one fourth, and the like of the total inventory.
For example, the number of object acquisition requests acquired by the server is X, and the minimum number of objects of three inventory blocks, namely, inventory block a, inventory block B and inventory block C, is determined according to the four data to occupy the total inventory, and the blocks are partitioned, for example, seven tenths, five nineths and the like.
Step 306, based on the total stock blocking proportion, inputting the number of the object acquisition requests and the number of the objects in the total stock into the stock blocking optimization algorithm, and determining the stock blocking number.
The inventory blocking optimization algorithm can be a mathematical algorithm for calculating the inventory blocking number according to the number of object acquisition requests and the number of objects in the total inventory, and can give a relatively reasonable value to a specific value of the inventory blocking number, so that the occupation of computer resources can be reduced while the processing speed can be ensured.
Specifically, according to the block proportion of the total inventory, two parameters, namely the number of object acquisition requests and the number of objects in the total inventory, are used and input into an inventory block optimization algorithm for calculation, wherein the inventory block optimization algorithm can be a random number algorithm, such as a linear congruence random number algorithm, a pseudo-random number algorithm and the like, the relatively reasonable inventory block number is obtained after calculation, and through the inventory block number, further optimization can be performed by using another algorithm to obtain an optimal solution.
For example, the total stock partition proportion is calculated to be one half, the object acquisition request number X and the total stock object number Y are input into a linear congruence random number algorithm to calculate a specific value of the stock partition number, and the calculated value of the stock partition number is Z, which is a relatively reasonable stock partition number, so that the service requirement can be met.
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 total inventory blocking proportion, and the total inventory is partially blocked, so that the number in the inventory blocks is smaller, and the efficiency of processing the object acquisition requests by the computer is improved.
In one embodiment, as shown in fig. 4, at least two object acquisition requests are processed in parallel, for each object acquisition request, the inventory blocks whose number of objects satisfies a preset condition are correspondingly deducted, so as to obtain a request processing result corresponding to each object acquisition request, where the request processing result includes:
step 402, identifying each inventory block by using an identification number to obtain an inventory block identification number corresponding to each inventory block.
The identification number may be a code for identifying each stock block, each code corresponds to one stock block, the code can accurately represent information in the stock block, and the code may be generated by a computer algorithm, for example, a snowflake algorithm.
The identification number of the stock block may be a number that has been used to identify the stock block by using the identification number to obtain that each stock block has a unique identification, that is, the identification number becomes the identification number of the stock block after identification.
Specifically, a plurality of identification numbers are generated by using a computer algorithm, the number of the identification numbers is required to be larger than or equal to the number of the stock blocks, each identification number corresponds to each stock block, after identification, each stock block obtains the stock block identification number corresponding to the identification number one by one, the identification numbers can be stored in a cache and are associated with the lowest threshold value of the stock number in the stock block, the real-time stock number and the like, the identification numbers are generated independently of a database, the operation is completely carried out in a memory, millions of self-increasing identification numbers can be generated in each second, and the efficiency is very high.
For example, the total inventory is divided into M inventory blocks by partitioning, a snowflake algorithm is used to generate M identification numbers, the M inventory blocks are identified one by using the identification numbers, and the inventory block identification numbers corresponding to each M inventory blocks are obtained.
Step 404, for each object acquisition request, searching for the inventory blocks with the number of objects meeting the 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 the request processing result corresponding to each object acquisition request.
The preset condition may be that the number of objects in the stock block meets a preset setting condition, the condition may be that the setting is performed manually, or that the setting is performed by a computer according to actual conditions, the condition is a dynamic parameter, and the dynamic parameter changes in real time along with the change of the parameter of the system.
The target stock block may be a stock block which satisfies a preset condition but is not deducted, if a plurality of stock blocks satisfy the condition, the stock block with the largest number of selected objects is used as the target stock block, and deduction is performed from the stock block with the largest number of selected objects.
Specifically, for each object acquisition request, the computer searches for an inventory block with the number of objects meeting a preset condition according to the inventory block identification number, and takes the inventory block as a target inventory block, if a plurality of inventory blocks meet the condition, the inventory block with the largest number of objects is selected as the target inventory block, and then the objects in the target inventory block are deducted according to the data in the object acquisition request, so as to obtain the request processing result corresponding to each object acquisition request.
For example, the number of object acquisition requests obtained by the server is X, the number of objects of the inventory blocks involved in object deduction is preset to be not less than 100, for one object acquisition request, the computer searches for inventory blocks with the number of objects greater than or equal to 100 as target inventory blocks, and the obtained result is that the number of objects in 8 target inventory blocks meets the preset condition, so that the server selects the target inventory block with the largest number of objects from the 8 target inventory blocks to deduct, and obtains the request processing result corresponding to the object acquisition request after deduction, and for each object acquisition request, the above process is repeatedly executed, so as to obtain the request processing result corresponding to each object acquisition request.
In this embodiment, by using the identification number to identify each inventory block, it is possible to quickly and accurately locate inventory blocks that can meet the preset condition, and subject deduction is performed on these inventory blocks, so that the subject deduction efficiency and accuracy are greatly improved, and meanwhile, excessive deduction of inventory blocks with low subject number is avoided.
In one embodiment, as shown in fig. 5, for each object acquisition request, searching for an inventory block whose number of objects meets a preset condition according to an inventory block identification number as a target inventory block, and deducting objects in the target inventory block to obtain a request processing result corresponding to each object acquisition request, where the request processing result includes:
Step 502, for the current object obtaining request, searching a target inventory block, corresponding to the current object obtaining request, of which the number of objects meets a preset condition according to the inventory block identification number, deducting the objects in the target inventory block, and obtaining a request processing result corresponding to the current object obtaining request.
The current object acquisition request may be an object acquisition request that the server is currently processing, or that the server is currently idle and ready to process.
Specifically, a condition of an inventory block capable of being a deduction object is preset, for an object acquisition request to be processed currently, a target inventory block, the number of which can meet the preset condition, is searched according to the inventory block identification number in the identified inventory block to process the current object acquisition request, and then the object in the target inventory block is deducted to obtain a request processing result corresponding to the current object acquisition request.
For example, inventory blocks with the number of objects greater than or equal to 1000 can be preset as deduction objects, for the object acquisition request H to be processed currently, a target inventory block a capable of meeting the object acquisition request for deducting the object to be processed currently is found according to the inventory block identification number, and then deduction is performed on the objects in the target inventory block a to obtain a request processing result corresponding to the current object acquisition request H.
Step 504, taking the next object acquisition request of the current object acquisition request as the current object acquisition request, and executing the steps repeatedly until the request processing result corresponding to each object acquisition request is obtained.
The next object obtaining request may be an object obtaining request to be processed next in the processing sequence from the server relative to the current object obtaining request, and the two object obtaining requests have the same property and need the same processing steps.
Specifically, after all the steps of processing the current object acquisition request are completed, the next object acquisition request is taken as the current object acquisition request, that is, the server is about to process the next object acquisition request, then all the steps are repeatedly executed to obtain a request processing result corresponding to the next object acquisition request, and the same processing is performed on all the object acquisition requests until a request processing result corresponding to each object acquisition request is obtained.
For example, an inventory block with the number of objects greater than or equal to 1000 can be preset as a deduction object, the next object acquisition request I to be processed is taken as the current object acquisition request to be processed, and then the steps are repeatedly executed to obtain a request processing result corresponding to the next object acquisition request I to be processed, and the same processing is performed on all the object acquisition requests until a request processing result corresponding to each object acquisition request is obtained.
In this embodiment, each object acquisition request is processed in a cyclic manner, and the target inventory blocks meeting the preset conditions are deducted each time a deduction operation is performed until the request processing results corresponding to all the object acquisition requests are obtained, so that the deduction of each object acquisition request from the target inventory blocks meeting the preset conditions can be achieved, the resources of the computer system are relatively balanced, and the stability of computer processing is maintained.
In one embodiment, as shown in fig. 6, searching for a target inventory block with the number of objects corresponding to the current object obtaining request meeting a preset condition according to the inventory block identification number, deducting the objects in the target inventory block, including:
step 602, if the result of searching for the inventory blocks corresponding to the number of objects satisfying the preset condition according to the inventory block identification number is one, directly deducting the inventory blocks corresponding to the number of objects satisfying the preset condition.
Specifically, if the number of objects found according to the inventory block identification number can meet the result of the inventory block corresponding to the preset condition, then for the object acquisition request to be processed currently, the objects in the inventory block corresponding to the preset condition are directly deducted, and then the processing of the object acquisition request to be processed currently can be completed.
For example, an inventory block with the number of objects greater than or equal to 1000 can be preset as the deduction object, the number of objects found by the inventory block identification number can satisfy the result of the inventory block corresponding to the preset condition, and the result is an inventory block a, and then the inventory block a is the only choice for the object to be processed currently to obtain the request H, so that the object in the inventory block a is selected to be deducted, and the processing of the object to be processed currently to obtain the request H can be completed.
Step 604, if the number of the objects found according to the inventory block identification number satisfies at least two inventory blocks corresponding to the preset condition, deducting the inventory block corresponding to the maximum number of the objects.
Specifically, if the number of the objects found according to the inventory block identification number can meet at least two inventory blocks corresponding to the preset condition, then for the object acquisition request to be processed currently, the object of the inventory block with the maximum number of the objects in the inventory block corresponding to the preset condition is deducted, and then the processing of the object acquisition request to be processed currently can be completed.
For example, if the number of the preset objects is greater than or equal to 1000, and the number of the objects found by the inventory block identification number can satisfy the result of the inventory blocks corresponding to the preset condition, for example, 2000 objects in the inventory block a, 2100 objects in the inventory block B, 2050 objects in the inventory block C, and 2080 objects in the inventory block D, then the current object to be processed is acquired, and the inventory block with the largest number of the objects in the inventory block is selected for deduction, so that the object in the inventory block B is selected for deduction, and the current object to be processed is acquired.
In this embodiment, the inventory blocks which are deducted under different conditions are identified by the computer, so that the inventory blocks with the largest quantity of deducted objects can be always obtained when the object acquisition request is processed, and the situation that the quantity of objects is insufficient when deducted is ensured.
In one embodiment, as shown in fig. 7, according to a request processing result corresponding to each object acquisition request, adjusting the number of objects in each inventory block and the number of inventory blocks includes:
step 702, analyzing according to the request processing result corresponding to each object acquisition request to obtain an inventory block analysis result.
The inventory block analysis result may be a result including characteristics of each request processing result obtained by analyzing a request processing result corresponding to each object acquisition request by using a mathematical model.
Specifically, the request processing result corresponding to each object acquisition request is input into a preset mathematical model for analysis, at least two mathematical models are preset in a computer, automatic calling is performed according to actual conditions when the object acquisition request is needed, manual intervention can be used for selection, and an inventory block analysis result is obtained after analysis.
For example, a mathematical analysis model 1, a mathematical analysis model 2 and a mathematical analysis model 3 are preset in a computer, the request processing results corresponding to each object acquisition request are input into a value computer at the same time, and the computer selects the mathematical analysis model 3 according to the actual situation to analyze each request processing result, so as to obtain the analyzed stock block analysis result.
Step 704, adjusting the object number of each inventory block and the number of the inventory blocks based on the analysis result of the inventory blocks to obtain the object number of each updated inventory block and the number of updated inventory blocks.
The updated inventory block object number may be the object number of each inventory block obtained by properly adjusting the current inventory block object number according to the inventory block analysis result.
The updated inventory block number may be the number of inventory blocks obtained by appropriately adjusting the current inventory block number according to the inventory block analysis result.
Specifically, the number of objects of the inventory blocks and the number of inventory blocks after the object acquisition request is processed are adjusted according to the analysis result of the inventory blocks, wherein the adjustment can be the steps of splitting, reorganizing, extracting, newly creating and the like, and the number of objects of each updated inventory block and the number of updated inventory blocks are obtained after the adjustment.
For example, the inventory block analysis result Q is obtained after analysis, and the object number of the inventory blocks and the number of the inventory blocks are split, extracted and reorganized according to the inventory block analysis result Q, so that the relatively average updated inventory block object number and updated inventory block number are obtained after adjustment.
In this embodiment, by analyzing the processing result of each request and then adjusting the number of objects in the stock block and the number of stock blocks by using the analysis result of the stock block, the adjustment of computer resources can be achieved, and a good system environment is provided for the next processing.
In one embodiment, for the present technical solution, a specific method is implemented as follows. According to the technical scheme, the inventory coordinator is used for uniformly distributing the total inventory into N inventory blocks based on a snowflake algorithm, for example, the inventory is 100, 10 requests are simultaneously initiated, the total inventory is uniformly divided into 10 inventory blocks, each inventory is 10, each request is calculated in the corresponding inventory block, the inventory is deducted through a distributed lock in the inventory block of each thread, which is equivalent to the parallel operation of 10 threads, the problem of overstock is avoided, the asynchronous inventory deduction method is realized, the efficiency is greatly improved, and the mentioned distributed locks comprise the following types, namely a database lock, a cache lock and a Zookeeper lock, and the overall structure is shown in figure 8.
The inventory coordinator uniformly distributes the total inventory into inventory blocks with corresponding quantity, monitors the inventory quantity in the inventory blocks in real time, uniformly distributes the request to the corresponding inventory blocks, can supplement the inventory in advance to the inventory blocks which are rapidly consumed, can adjust the inventory quantity in each inventory block in real time when the request is increased, extracts a certain inventory quantity to newly increase the inventory blocks, can delete a certain quantity of inventory blocks when the request is reduced, and uniformly distributes the inventory quantity to other inventory blocks.
1. And the inventory distribution device is used for dividing the inventory into a plurality of inventory blocks by using a linear congruence random number algorithm.
Equation RandSeed = (a. RandSeed + B)% M
The linear congruence method is most important to define three integers, multiplier a, increment B and modulus M, where a, B, M are constants set by the generator. The period of LCG is max M, but most cases will be less than M. To maximize the period of LCG, the following conditions should be met:
① B. M is mutually mass;
② All prime factors of M can divide A-1;
③ If M is a multiple of 4, A-1 is also;
④ A. B, N [0] are all smaller than M;
⑤ A. B is a positive integer.
The algorithm is the oldest and most widely known bit random number generator algorithm, which generates pseudo-random numbers by a recursive formula. Because the number of the total stock is variable and needs to be determined according to specific requirements, the algorithm can split the stock blocks according to the specific total stock number and the request number, can split the total stock completely, and can split only half of the stock if the request is less.
For example, the total stock is 100, we set the minimum stock number of each stock block to 10 and the maximum stock number to 20. If the current request number is 10, the whole 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 whole inventory can be split into 5 inventory blocks, the inventory number of each inventory block is 20, or half of the total inventory can be split into 5 inventory blocks, and the inventory number of each inventory block is 10. When the latter is more efficient, the waiting time for locking and unlocking will be much less because the latter has a small number of stock blocks.
And receiving the notification of the monitoring device in real time, and splitting or reorganizing the inventory. If the stock number in the stock block is found to be close to the threshold value or even lower than the threshold value, the stock in the stock block with the stock number higher than the threshold value is split and distributed into the stock blocks with lower stock numbers. If the number of real-time requests is increased and the number of existing stock blocks cannot meet the requirement, the stock number is extracted from the stock blocks with higher stock number, and the new stock blocks are built, which is equivalent to adding threads to process the requests, so that the stock reorganization is realized.
2. The snowflake algorithm generates an ID (structured as shown in fig. 9) to identify each inventory chunk.
The ID is saved in the cache and a minimum threshold for the amount of inventory within the inventory block, the real-time inventory number, etc. is set in association therewith. The ID generation process is independent of a database, is completely operated in a memory, can generate millions of self-increment IDs per second, and has high efficiency.
It should be understood that, although the steps in the flowcharts related to the above embodiments are sequentially shown as indicated by arrows, these steps are not necessarily sequentially performed in the order indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in the flowcharts described in the above embodiments may include a plurality of steps or a plurality of stages, which are not necessarily performed at the same time, but may be performed at different times, and the order of the steps or stages is not necessarily performed sequentially, but may be performed alternately or alternately with at least some of the other steps or stages.
3. The monitoring device processes the inventory in real time.
And monitoring the request number in real time, informing the inventory allocation device, and carrying out inventory reorganization operation by the allocation device according to the real-time request number.
The real-time monitoring of the number of the stock in the existing stock block through the ID is compared with the lowest threshold value, and if the threshold value is found to be close to or even lower than the threshold value, the stock distributing device is informed to carry out the stock splitting operation.
According to the technical scheme, the inventory coordinator is used for splitting the total inventory, so that the asynchronous multithreading inventory reduction effect is realized, and the problem of low inventory reduction efficiency of all the inventories in series in the prior art is solved. And the inventory can be monitored, split and reorganized in real time, so that the relative average in each inventory block is realized, the processing request is more uniform, and the problems that one thread requests too much and other threads are idle are avoided.
Based on the same inventive concept, the embodiment of the application also provides an inventory deduction device for realizing the inventory deduction method. The implementation of the solution provided by the device is similar to the implementation described in the above method, so the specific limitation of the embodiment of the inventory deduction device or embodiments provided below may refer to the limitation of the inventory deduction method hereinabove, and will not be repeated here.
In one embodiment, as shown in fig. 10, there is provided an inventory deduction device, which includes an object obtaining request obtaining module, an inventory partition number determining module, an inventory block obtaining module, a request processing result obtaining module, and an inventory block adjusting module, wherein:
An object acquisition request acquisition module 1002, configured to acquire at least two object acquisition requests, where each object acquisition request is used to request deduction of at least one object in the total inventory;
an inventory partition number determining module 1004, configured to determine an inventory partition number according to the number of object acquisition requests and the number of objects in the total inventory;
the inventory block obtaining module 1006 is configured to block the total inventory according to the number of inventory blocks, and perform corresponding allocation on the objects of the total inventory to obtain at least two inventory blocks corresponding to the total inventory;
A request processing result obtaining module 1008, configured to process at least two object obtaining requests in parallel, and for each object obtaining request, correspondingly deduct inventory blocks whose number of objects meets a preset condition, to obtain a request processing result corresponding to each object obtaining request;
The inventory block adjusting module 1010 is 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.
In one embodiment, the inventory block number determining module is configured to obtain a minimum number of objects corresponding to each inventory block, determine a total inventory block proportion based on the number of object obtaining requests and the minimum number of objects corresponding to each inventory block, the total inventory block proportion is used for dividing the total inventory block proportion, and input the number of object obtaining requests and the total inventory number of objects to the inventory block optimization algorithm based on the total inventory block proportion, to determine the inventory block number.
In one embodiment, the request processing result obtaining module is used for identifying each inventory block by using an identity number to obtain an inventory block identification number corresponding to each inventory block, searching inventory blocks with the number meeting the preset condition according to the inventory block identification number as target inventory blocks for each object acquisition request, and deducting the objects in the target inventory blocks to obtain a request processing result corresponding to each object acquisition request.
In one embodiment, the request processing result obtaining module is configured to find, for the current object obtaining request, a target inventory block, corresponding to the current object obtaining request, according to the inventory block identification number, where the number of objects corresponding to the current object obtaining request meets a preset condition, deduct objects in the target inventory block to obtain a request processing result corresponding to the current object obtaining request, take a next object obtaining request of the current object obtaining request as the current object obtaining request, and execute repeatedly the steps until obtaining the request processing result corresponding to each object obtaining request.
In one embodiment, the request processing result obtaining module is configured to directly deduct the inventory blocks corresponding to the preset condition if the number of the objects found according to the inventory block identification number satisfies one inventory block corresponding to the preset condition, and deduct the inventory blocks corresponding to the maximum number of the objects if the number of the objects found according to the inventory block identification number satisfies at least two inventory blocks corresponding to the preset condition.
In one embodiment, the inventory block adjusting module is configured to analyze a request processing result corresponding to each object obtaining request to obtain an inventory block analysis result, and adjust the number of objects and the number of inventory blocks of each inventory block based on the inventory block analysis result to obtain the number of objects of each updated inventory block and the number of updated inventory blocks.
The various modules in the inventory deduction device described above may be implemented in whole or in part by software, hardware, and combinations thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
In one embodiment, a computer device is provided, which may be a server, and the internal structure of which may be as shown in fig. 11. The computer device includes a processor, a memory, and a network interface connected by a system bus. Wherein the processor of the computer device is configured 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, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The database of the computer device is for storing server data. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a stock deduction method.
It will be appreciated by those skilled in the art that the structure shown in FIG. 11 is merely a block diagram of some of the structures associated with the present inventive arrangements and is not limiting of the computer device to which the present inventive arrangements may be applied, and that a particular computer device may include more or fewer components than shown, or may combine some of the components, or have a different arrangement of components.
In an embodiment, there is also provided a computer device comprising a memory and a processor, the memory having stored therein a computer program, the processor implementing the steps of the method embodiments described above when the computer program is executed.
In one embodiment, a computer-readable storage medium is provided, storing a computer program which, when executed by a processor, implements the steps of the method embodiments described above.
In one embodiment, a computer program product or computer program is provided that includes computer instructions stored in a computer readable storage medium. The processor of the 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-described method embodiments.
The user information (including but not limited to user equipment information, user personal information, etc.) and the data (including but not limited to data for analysis, stored data, presented data, etc.) related to the present application are information and data authorized by the user or sufficiently authorized by each party.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, database, or other medium used in embodiments provided herein may include at least one of non-volatile and volatile memory. The nonvolatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical Memory, high density embedded nonvolatile Memory, resistive random access Memory (ReRAM), magneto-resistive random access Memory (Magnetoresistive Random Access Memory, MRAM), ferroelectric Memory (Ferroelectric Random Access Memory, FRAM), phase change Memory (PHASE CHANGE Memory, PCM), graphene Memory, and the like. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory, and the like. By way of illustration, and not limitation, RAM can be in various forms such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), etc. The databases referred to in the embodiments provided herein may include at least one of a relational database and a non-relational database. The non-relational database may include, but is not limited to, a blockchain-based distributed database, and the like. The processor referred to in the embodiments provided in the present application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computing, or the like, but is not limited thereto.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The foregoing examples illustrate only a few embodiments of the application and are described in detail herein without thereby limiting the scope of the application. It should be noted that it will be apparent to those skilled in the art that several variations and modifications can be made without departing from the spirit of the application, which are all within the scope of the application. Accordingly, the scope of the application should be assessed as that of the appended claims.