Inventory deduction processing method and system, storage medium and electronic device
By dynamically monitoring the concurrency of inventory deduction requests and utilizing database transaction features and pre-defined memory queues for batch I/O operations, the reliability and performance issues of the inventory deduction method were resolved, achieving efficient inventory management under high concurrency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING JINGDONG TUOXIAN TECH CO LTD
- Filing Date
- 2022-11-04
- Publication Date
- 2026-05-22
AI Technical Summary
Existing inventory deduction methods suffer from low reliability and low database performance, especially under high concurrency conditions, which can easily lead to overselling or underselling, and database I/O operations cause performance bottlenecks.
By dynamically monitoring the concurrency of inventory deduction requests, the system leverages the transaction characteristics of the database to ensure reliability under low concurrency conditions, and uses a pre-defined memory queue to implement batch database I/O operations under high concurrency conditions, thereby improving performance.
It ensures the reliability of inventory deduction under low concurrency conditions, improves database performance under high concurrency conditions, avoids overselling or underselling, and improves the overall performance of the inventory deduction method.
Smart Images

Figure CN115544043B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the fields of intelligent supply chain and e-commerce technology, and more specifically, to an inventory deduction processing method, system, storage medium, and electronic device. Background Technology
[0002] When a product is to be sold online, issues such as controlling the quantity of the product that can be sold, how many of the product can be sold online, and the maximum quantity that a user is allowed to purchase are collectively referred to as inventory issues.
[0003] Inventory is a public resource for all users. Existing inventory can be deducted in three ways: based on the database, based on the distributed cache Redis, and based on the local cache.
[0004] However, database-based inventory deduction suffers from low throughput due to database I / O operations, row-level locking, and transaction characteristics, thus reducing database performance. Redis-based inventory deduction, on the other hand, suffers from low reliability because data in the Redis cache can be lost.
[0005] Therefore, the existing inventory deduction method is unreliable and reduces database performance. Summary of the Invention
[0006] In view of this, this application discloses an inventory deduction processing method, system, storage medium, and electronic device, aiming to improve the reliability and performance of the inventory deduction method.
[0007] To achieve the above objectives, the disclosed technical solution is as follows:
[0008] The first aspect of this application discloses an inventory deduction processing method, the method comprising:
[0009] Dynamically monitor the concurrent requests for inventory deduction; the concurrent requests for inventory deduction are the concurrent requests for inventory changes of the current product.
[0010] When the concurrency of the inventory deduction request represents a low concurrency of requests, the inventory deduction operation is performed through the database; the low concurrency of requests is the request concurrency where the current query rate per second is less than a preset threshold.
[0011] When the concurrency of the inventory deduction request represents a high concurrency of requests, all inventory change counts in the preset memory queue are merged, and the inventory quantity specified in the database is modified in batches using the merged inventory change count; the high concurrency of requests is the request concurrency with a current query rate per second greater than or equal to a preset threshold; the preset memory queue represents a blocking queue with a ring array structure.
[0012] Preferred options also include:
[0013] When an inventory operation request is received, the server engine and a preset algorithm are used to calculate the number of requests for inventory changes of the current product to obtain the current query rate per second. The current query rate per second represents the size of the concurrent requests for inventory deduction. The current query rate per second is used to determine whether to enable the merging function of the preset memory queue.
[0014] Preferably, when the concurrency of the inventory deduction request represents a low concurrency of requests, the inventory deduction operation is performed through the database, including:
[0015] When the current query rate per second is less than a preset threshold, the concurrency of the inventory deduction request is determined to represent the low concurrency of the request.
[0016] When the concurrency of the inventory deduction request represents a low concurrency level, the inventory deduction operation is performed through the database.
[0017] Preferably, when the concurrency of the inventory deduction request represents a high concurrency of requests, merging all inventory change counts in a preset memory queue and batch modifying the specified inventory quantity in the database using the merged inventory change count includes:
[0018] When the current query rate per second is greater than or equal to a preset threshold, the concurrency of the inventory deduction request is determined to represent the high concurrency of the request.
[0019] When the concurrency of the inventory deduction request represents a high level of concurrency, obtain the current request thread corresponding to the inventory operation request;
[0020] Obtain the request context of the currently requesting thread;
[0021] The request context is encapsulated into a merge object and stored in the preset memory queue;
[0022] When the number of objects in the preset memory queue is equal to the preset memory queue length, or the queue waiting time of the preset memory queue is equal to the preset waiting time, all inventory change counts in the preset memory queue are merged through the server engine.
[0023] The database can be modified in batches using the merged inventory change data.
[0024] Preferred options also include:
[0025] When the remaining inventory in the database is greater than the total deducted inventory in the merged preset memory queue, the server engine splits the merged preset memory queue to obtain the inventory deduction quantity for each different inventory operation request.
[0026] For each different inventory operation request, a separate inventory deduction operation is performed to obtain the deduction result for each different inventory operation request. The deduction result for each different inventory operation request is stored in the request context of the request thread corresponding to each different inventory operation request, so as to wake up the blocked request thread and return the deduction result of each different inventory operation request to the user.
[0027] A second aspect of this application discloses an inventory deduction processing system, the system comprising:
[0028] The monitoring unit is used to dynamically monitor the concurrent requests for inventory deduction; the concurrent requests for inventory deduction are the concurrent requests for inventory changes of the current product.
[0029] The first operation unit is used to perform an inventory deduction operation through the database when the concurrency of the inventory deduction request represents a low concurrency of requests; the low concurrency of requests is the request concurrency where the current query rate per second is less than a preset threshold.
[0030] The modification unit is used to merge all inventory change counts in a preset memory queue when the concurrency of the inventory deduction request represents a high concurrency of requests, and to batch modify the inventory quantity specified in the database using the merged inventory change count; the high concurrency of requests is the request concurrency with a current query rate per second greater than or equal to a preset threshold; the preset memory queue represents a blocking queue with a ring array structure.
[0031] Preferred options also include:
[0032] The calculation unit is used to calculate the number of requests for inventory changes of the current product when an inventory operation request is received, through the server engine and a preset algorithm, to obtain the current query rate per second; the current query rate per second represents the magnitude of the concurrent requests for inventory deduction; the current query rate per second is used to determine whether to enable the merging function of the preset memory queue.
[0033] Preferably, the first operating unit includes:
[0034] The first determining module is used to determine the low concurrency of the inventory deduction request when the current query rate per second is less than a preset threshold.
[0035] The operation module is used to perform inventory deduction operations through the database when the concurrency of the inventory deduction request represents a low concurrency of requests.
[0036] A third aspect of this application discloses a storage medium comprising stored instructions, wherein, when the instructions are executed, the device in which the storage medium is located is controlled to perform an inventory deduction processing method as described in any one of the first aspects.
[0037] The fourth aspect of this application discloses an electronic device including a memory and one or more instructions, wherein one or more instructions are stored in the memory and configured to be executed by one or more processors using the inventory deduction processing method as described in any of the first aspects.
[0038] As described above, this application discloses an inventory deduction processing method, system, storage medium, and electronic device. It dynamically monitors the concurrency of inventory deduction requests, where the concurrency is the number of requests for inventory changes of the current product. When the concurrency represents low concurrency, the inventory deduction operation is performed through the database. Low concurrency is defined as the number of requests with a query rate per second less than a preset threshold. When the concurrency represents high concurrency, all inventory changes in a preset memory queue are merged, and the specified inventory quantity in the database is modified in batches using the merged inventory changes. High concurrency is defined as the number of requests with a query rate per second greater than or equal to a preset threshold. The preset memory queue is a blocking queue with a circular array structure. Through this, due to the atomicity, consistency, isolation, and persistence of database transactions, the reliability of the inventory deduction method is ensured under low concurrency conditions. In the case of high concurrency requests, a pre-defined memory queue is used to perform batch database input / output operations to modify the specified inventory quantity in the database, thereby improving the performance of the database and thus the performance of the inventory deduction method. Attached Figure Description
[0039] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0040] Figure 1 This is a schematic flowchart of an inventory deduction processing method disclosed in an embodiment of this application;
[0041] Figure 2 This is a schematic diagram of the core steps of the inventory deduction operation disclosed in the embodiments of this application;
[0042] Figure 3 This is a schematic diagram of the structure of an inventory deduction processing system disclosed in an embodiment of this application;
[0043] Figure 4 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of this application. Detailed Implementation
[0044] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0045] In this application, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0046] As the background technology indicates, database-based inventory deduction methods suffer from low throughput due to database input / output (I / O) operations, row-level locking, and transaction characteristics, thus reducing database performance. Inventory deduction methods based on distributed caches like Redis suffer from low reliability because data in the Redis cache can be lost. Therefore, existing inventory deduction methods suffer from low reliability and degrade database performance.
[0047] To address the aforementioned issues, this application discloses an inventory deduction processing method, system, storage medium, and electronic device. Due to the atomicity, consistency, isolation, and persistence of transaction characteristics in databases, the reliability of the inventory deduction method is guaranteed under low concurrency scenarios. Under high concurrency scenarios, a pre-defined memory queue is used to perform batch database input / output operations to modify the specified inventory quantity in the database, improving database performance and thus improving the performance of the inventory deduction method. The specific implementation is described in the following embodiments.
[0048] refer to Figure 1 The diagram shown is a flowchart illustrating an inventory deduction method disclosed in an embodiment of this application. The inventory deduction method mainly includes the following steps:
[0049] S101: Dynamically monitor the concurrent requests for inventory deduction; the concurrent requests for inventory deduction are the same as the concurrent requests for inventory changes of the current product.
[0050] When an inventory operation request is received, the server engine and preset algorithm calculate the number of requests for inventory changes for the current product to obtain the current query rate per second (QPS). The current query rate per second represents the size of the concurrent requests for inventory deduction. The current query rate per second is used to determine whether to enable the merging function of the preset memory queue.
[0051] The preset algorithm can be a sliding window algorithm or other algorithms. The specific preset algorithm shall be determined by the technical personnel according to the actual situation, and this application does not make any specific restrictions.
[0052] S102: When the concurrency of inventory deduction requests represents low concurrency, the inventory deduction operation is performed through the database; low concurrency refers to the current query rate per second which is less than a preset threshold.
[0053] In S102, when the concurrency of inventory deduction requests represents a low concurrency level, the database is directly manipulated to deduct the inventory. This ensures the high reliability of inventory deduction while preventing the database performance from becoming a bottleneck.
[0054] The preset threshold is determined by technical personnel based on the actual situation, and this application does not impose specific limitations on it.
[0055] Database-based inventory deduction leverages the transactional properties of data to ensure the reliability of inventory deduction and prevent overselling or underselling. Due to the atomicity, consistency, isolation, and persistence of database transactions, the reliability of the inventory deduction method is guaranteed even under low concurrency request scenarios.
[0056] Databases exhibit ACID transaction properties. ACID includes four transaction characteristics: Atomicity, Consistency, Isolation, and Durability.
[0057] Therefore, the high reliability of inventory deduction is ensured by relying on the ACID transaction characteristics of the database. At the same time, the database performance will not become a bottleneck.
[0058] Inventory is a shared resource for all users, and the following three scenarios are commonly encountered during the deduction process:
[0059] Overselling refers to a situation where the number of products sold during the sales period exceeds the number of products available for sale.
[0060] "Selling less" refers to a situation where, from the customer's perspective, the quantity of a product is sold out and unavailable for purchase, but the actual number of products sold is less than the number of products available for sale on the shelves.
[0061] Performance is crucial in inventory deduction scenarios, which involve changes to shared resources like inventory quantity. Therefore, controlling the order of deductions necessitates a serial approach. To ensure security, locking mechanisms are implemented, inevitably leading to a significant performance degradation. This solution utilizes a pre-defined memory queue to perform batch database input / output operations to modify specified inventory quantities, improving database performance and consequently enhancing the performance of the inventory deduction method.
[0062] Specifically, when the concurrency of inventory deduction requests represents a low level of concurrency, the process of performing inventory deduction operations through the database is shown in A1-A2:
[0063] A1: When the current query rate per second is less than the preset threshold, the concurrency of inventory deduction requests represents the low concurrency of requests.
[0064] A2: When the concurrency of inventory deduction requests represents a low level of concurrency, the inventory deduction operation is performed through the database.
[0065] S103: When the concurrency of inventory deduction requests represents high concurrency, merge all inventory change counts in the preset memory queue, and batch modify the specified inventory quantity in the database using the merged inventory change count; high concurrency refers to the request concurrency when the current query rate per second is greater than or equal to the preset threshold; the preset memory queue represents a blocking queue with a circular array structure.
[0066] Among them, the blocking queue with a circular array structure is a high-performance blocking queue with a circular array structure.
[0067] High performance: Based on a preset memory queue, batch database I / O operations are implemented, which weakens the limitation of data I / O performance bottleneck, greatly improves the performance of inventory deduction, and at the same time ensures high reliability.
[0068] Circular array structure: To avoid garbage collection, an array is used instead of a linked list. At the same time, arrays are more friendly to the processor's caching mechanism.
[0069] Disruptor, a high-performance memory queue framework based on the CAS concept and eliminating false sharing, was introduced to replace the traditional ArrayBlockingQueue queue based on heavyweight Lock. Experiments showed that the performance of the blocking queue was improved by about 30%.
[0070] False sharing: When multiple threads modify independent variables, if these variables share the same cache line, they will unintentionally affect each other's performance. This is called false sharing.
[0071] Specifically, when the concurrency of inventory deduction requests represents a high level of concurrency, the process of merging all inventory change counts in the preset memory queue and batch modifying the specified inventory quantity in the database using the merged inventory change count is shown in B1-B6.
[0072] B1: When the current query rate per second is greater than or equal to the preset threshold, the concurrency of inventory deduction requests represents the high concurrency of requests.
[0073] B2: When the concurrency of inventory deduction requests represents a high level of concurrency, obtain the current request thread corresponding to the inventory operation request. Encapsulate the request context (Request object and Response object) of the current request thread into a merge object (mergeWaiter) and store it in a preset memory queue (a high-performance circular array structure blocking queue) to wait for the trigger operation.
[0074] If the current query rate per second is greater than or equal to the preset threshold (the threshold for enabling memory merging), the current request thread will be blocked.
[0075] B3: Get the request context of the current request thread.
[0076] B4: Encapsulate the request context into a merged object and store it in a preset memory queue.
[0077] B5: When the number of objects in the preset memory queue is equal to the preset memory queue length, or the queue waiting time of the preset memory queue is equal to the preset waiting time, all inventory changes in the preset memory queue are merged through the server engine.
[0078] The preset waiting time can be 30ms, 50ms, etc., and the specific preset waiting time shall be set by the technical personnel according to the actual situation. This application does not impose a specific limitation. The preferred preset waiting time in this application is 50ms.
[0079] B6: Modify the specified inventory quantity in the database in batches using the merged inventory change data.
[0080] When the remaining inventory in the database exceeds the total deducted inventory in the merged preset memory queue, the server engine splits the merged preset memory queue to obtain the inventory deduction quantity for each different inventory operation request.
[0081] For each different inventory operation request, a separate inventory deduction operation is performed to obtain the deduction result for each different inventory operation request. The deduction result for each different inventory operation request is stored in the request context of the request thread corresponding to each different inventory operation request, so as to wake up the blocked request thread and return the deduction result of each different inventory operation request to the user.
[0082] To facilitate understanding of the inventory deduction process in this scheme, we will combine it with... Figure 2 To explain, Figure 2 A schematic diagram of the core steps in the inventory deduction operation is shown.
[0083] Figure 2 In the middle, 1, when concurrent inventory operation requests arrive on the server, the server engine (Enginecompute) calculates the number of requests for inventory changes for the current product, and determines whether to enable the memory queue merging function based on the current query rate per second. If the current query rate per second is less than the preset threshold for enabling memory merging, the database is directly operated to perform the inventory deduction operation.
[0084] 2. "Block" means that if the current query rate per second is greater than or equal to the preset threshold for enabling memory merging, the current request thread will be blocked. The request context (request object and response object) of the current request thread is encapsulated into a mergeWaiter object and placed in a high-performance circular array structure blocking queue to wait for the trigger operation.
[0085] 3. When the number of objects in the preset memory queue is equal to the preset memory queue length, or the queue waiting time of the preset memory queue is equal to the preset waiting time (e.g., 50ms), the server engine will merge all inventory changes in the preset memory queue and perform a batch updateBatch modification of the specified inventory quantity in the database. This is equivalent to performing a single database IO operation, which improves performance over the limitations of database IO bottlenecks.
[0086] For example, when the number of objects in the preset memory queue reaches the set queue length or a fixed waiting time, 10 requests in the memory queue are merged into one inventory change number. The inventory quantity specified in the database is then modified using the merged inventory change number to obtain the modification result.
[0087] 4. Send the modified results to the database.
[0088] 5. Return the modified results after querying the database to the server engine.
[0089] 6. When the remaining inventory in the database is greater than the total deductible inventory in the merged preset memory queue, the merged preset memory queue is split by the server engine to obtain the inventory deduction quantity for each different inventory operation request. The database is then deducted separately based on the inventory deduction quantity for each different inventory operation request to obtain the deduction result for each request.
[0090] Specifically, separate inventory deduction operations are performed on the inventory deduction quantities for each different inventory operation request to obtain the deduction results for each different inventory operation request.
[0091] For example, if the database has 5 units of remaining inventory, the total inventory to be deducted after merging 10 requests into 1 means deducting 10 units of the database's remaining inventory. If this is insufficient, the engine will degenerate and split the pre-defined memory queue after merging, performing individual inventory deduction operations one by one. That is, it will split the 10 requests into 10 requests, and perform individual inventory deduction operations on each of the 10 requests to obtain the deduction results for different requests.
[0092] 7. Update the deduction results of different requests in the context and database of each thread, wake up the blocked thread and then synchronously return the deduction results to the user.
[0093] The deduction results of each different inventory operation request are stored in the request context of the request thread corresponding to each different inventory operation request, so as to wake up the blocked request thread and return the deduction results of each different inventory operation request to the user.
[0094] In this embodiment, due to the atomicity, consistency, isolation, and persistence of database transactions, the reliability of the inventory deduction method is guaranteed under low concurrency conditions. Under high concurrency conditions, a preset memory queue is used to perform batch database input / output operations to modify the specified inventory quantity in the database, improving database performance and thus improving the performance of the inventory deduction method.
[0095] Based on the above embodiments Figure 1 The present application discloses an inventory deduction processing method and a corresponding inventory deduction processing system. Figure 3 As shown, the inventory deduction processing system includes a monitoring unit 301, a first operation unit 302, and a modification unit 303.
[0096] The monitoring unit 301 is used to dynamically monitor the concurrent requests for inventory deduction; the concurrent requests for inventory deduction are the concurrent requests for changes in the current product's inventory.
[0097] The first operation unit 302 is used to perform inventory deduction operations through the database when the concurrency of inventory deduction requests represents low concurrency; low concurrency is the current query rate per second which is less than a preset threshold.
[0098] Modification unit 303 is used to merge all inventory change counts in the preset memory queue when the concurrency of inventory deduction requests represents a high concurrency of requests, and to batch modify the inventory quantity specified in the database using the merged inventory change counts; the high concurrency of requests refers to the request concurrency of the current query rate per second that is greater than or equal to a preset threshold; the preset memory queue represents a blocking queue with a ring array structure.
[0099] Furthermore, the inventory deduction processing system also includes a calculation unit.
[0100] The calculation unit is used to calculate the number of requests for inventory changes of the current product when an inventory operation request is received, through the server engine and preset algorithms, to obtain the current query rate per second; the current query rate per second represents the size of the concurrent requests for inventory deduction; the current query rate per second is used to determine whether to enable the merging function of the preset memory queue.
[0101] Furthermore, the first operation unit 302 includes a first determining module and an operation module.
[0102] The first determining module is used to determine the concurrency of inventory deduction requests when the current query rate per second is less than a preset threshold, representing the low concurrency of requests.
[0103] The operation module is used to perform inventory deduction operations through the database when the concurrency of inventory deduction requests is low.
[0104] Furthermore, the modification unit 303 includes a second determination module, a first acquisition module, a second acquisition module, a storage module, a merging module, and a batch modification module.
[0105] The second determining module is used to determine the concurrency of inventory deduction requests when the current query rate per second is greater than or equal to a preset threshold, representing the high concurrency of requests.
[0106] The first acquisition module is used to acquire the current request thread corresponding to the inventory operation request when the concurrency of inventory deduction requests represents a high level of concurrency.
[0107] The second acquisition module is used to acquire the request context of the current request thread.
[0108] The storage module is used to encapsulate the request context into a merged object and store it in a preset memory queue.
[0109] The merge module is used to merge all inventory changes in the preset memory queue through the server engine when the number of objects in the preset memory queue is equal to the preset memory queue length, or the queue waiting time of the preset memory queue is equal to the preset waiting time.
[0110] The batch modification module is used to modify the specified inventory quantity in the database in batches based on the merged inventory change data.
[0111] Furthermore, the inventory deduction processing system also includes a splitting unit and a second operation unit.
[0112] The splitting unit is used when the remaining inventory in the database is greater than the total deductible inventory in the merged preset memory queue. The server engine splits the merged preset memory queue to obtain the inventory deduction quantity for each different inventory operation request.
[0113] The second operation unit is used to perform separate inventory deduction operations on the inventory deduction quantities of each different inventory operation request, and obtain the deduction results of each different inventory operation request. The deduction results of each different inventory operation request are stored in the request context of the request thread corresponding to each different inventory operation request, so as to wake up the blocked request thread and return the deduction results of each different inventory operation request to the user.
[0114] In this embodiment, due to the atomicity, consistency, isolation, and persistence of database transactions, the reliability of the inventory deduction method is guaranteed under low concurrency conditions. Under high concurrency conditions, a preset memory queue is used to perform batch database input / output operations to modify the specified inventory quantity in the database, improving database performance and thus improving the performance of the inventory deduction method.
[0115] This application embodiment also provides a storage medium, which includes stored instructions, wherein, when the instructions are executed, the device where the storage medium is located is controlled to perform the above-described inventory deduction processing method.
[0116] This application also provides an electronic device, the structural schematic diagram of which is shown below. Figure 4 As shown, it specifically includes a memory 401 and one or more instructions 402, wherein one or more instructions 402 are stored in the memory 401 and are configured to be executed by one or more processors 403 to perform the above-mentioned inventory deduction processing method.
[0117] The specific implementation processes and derivative methods of the above embodiments are all within the protection scope of this application.
[0118] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and relevant parts can be referred to the descriptions in the method embodiments. The systems and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0119] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0120] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
[0121] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. An inventory deduction processing method, characterized in that, The method includes: Dynamically monitor the concurrent requests for inventory deduction; the concurrent requests for inventory deduction are the concurrent requests for inventory changes of the current product. When the concurrency of the inventory deduction request represents a low concurrency of requests, the inventory deduction operation is performed through the database; the low concurrency of requests is the request concurrency where the current query rate per second is less than a preset threshold. When the concurrency of the inventory deduction request represents a high concurrency of requests, the request context of the current request thread is encapsulated into a merge object and stored in a preset memory queue. When the preset memory queue meets the merging strategy, all inventory change counts in the preset memory queue are merged, and the inventory quantity specified in the database is modified in batches using the merged inventory change counts; the high concurrency request concurrency is the request concurrency at which the current query rate per second is greater than or equal to a preset threshold; the preset memory queue represents a blocking queue with a circular array structure; the merging strategy is determined by the number of objects in the preset memory queue or the queue waiting time.
2. The method according to claim 1, characterized in that, Also includes: When an inventory operation request is received, the server engine and preset algorithm are used to calculate the number of requests for inventory changes for the current product, and obtain the current query rate per second. The current query rate per second represents the magnitude of the concurrent requests for inventory deduction; The current query rate per second is used to determine whether to enable the merging function of the preset memory queue.
3. The method according to claim 2, characterized in that, When the concurrency of the inventory deduction request represents a low concurrency level, the inventory deduction operation is performed through the database, including: When the current query rate per second is less than a preset threshold, the concurrency of the inventory deduction request is determined to represent the low concurrency of the request. When the concurrency of the inventory deduction request represents a low concurrency level, the inventory deduction operation is performed through the database.
4. The method according to claim 2, characterized in that, When the concurrency of the inventory deduction request represents a high concurrency of requests, all inventory change counts in the preset memory queue are merged, and the specified inventory quantity in the database is modified in batches using the merged inventory change counts, including: When the current query rate per second is greater than or equal to a preset threshold, the concurrency of the inventory deduction request is determined to represent the high concurrency of the request. When the concurrency of the inventory deduction request represents a high level of concurrency, obtain the current request thread corresponding to the inventory operation request; Obtain the request context of the currently requesting thread; The request context is encapsulated into a merge object and stored in the preset memory queue; When the number of objects in the preset memory queue is equal to the preset memory queue length, or the queue waiting time of the preset memory queue is equal to the preset waiting time, all inventory change counts in the preset memory queue are merged through the server engine. The database can be modified in batches using the merged inventory change data.
5. The method according to claim 4, characterized in that, Also includes: When the remaining inventory in the database is greater than the total deducted inventory in the merged preset memory queue, the server engine splits the merged preset memory queue to obtain the inventory deduction quantity for each different inventory operation request. For each different inventory operation request, a separate inventory deduction operation is performed to obtain the deduction result for each different inventory operation request. The deduction result for each different inventory operation request is stored in the request context of the request thread corresponding to each different inventory operation request, so as to wake up the blocked request thread and return the deduction result of each different inventory operation request to the user.
6. An inventory deduction processing system, characterized in that, The system includes: The monitoring unit is used to dynamically monitor the concurrent requests for inventory deduction; the concurrent requests for inventory deduction are the concurrent requests for inventory changes of the current product. The first operation unit is used to perform an inventory deduction operation through the database when the concurrency of the inventory deduction request represents a low concurrency of requests; the low concurrency of requests is the request concurrency where the current query rate per second is less than a preset threshold. The modification unit is used to encapsulate the request context of the current request thread into a merge object and store it in a preset memory queue when the concurrency of the inventory deduction request represents a high concurrency of requests; when the preset memory queue meets the merging strategy, it merges all inventory change counts in the preset memory queue and modifies the specified inventory quantity in the database in batches using the merged inventory change counts; the high concurrency of requests is the request concurrency of the current query rate per second being greater than or equal to a preset threshold; the preset memory queue represents a blocking queue with a circular array structure; the merging strategy is determined by the number of objects in the preset memory queue or the queue waiting time.
7. The system according to claim 6, characterized in that, Also includes: The calculation unit is used to calculate the number of requests for inventory changes of the current product when an inventory operation request is received, through the server engine and preset algorithms, to obtain the current query rate per second. The current query rate per second represents the magnitude of the concurrent requests for inventory deduction; The current query rate per second is used to determine whether to enable the merging function of the preset memory queue.
8. The system according to claim 7, characterized in that, The first operation unit includes: The first determining module is used to determine the low concurrency of the inventory deduction request when the current query rate per second is less than a preset threshold. The operation module is used to perform inventory deduction operations through the database when the concurrency of the inventory deduction request represents a low concurrency of requests.
9. A storage medium, characterized in that, The storage medium includes stored instructions, wherein, when the instructions are executed, the device containing the storage medium is controlled to perform the inventory deduction processing method as described in any one of claims 1 to 5.
10. An electronic device, characterized in that, It includes a memory, and one or more instructions, wherein one or more instructions are stored in the memory and configured to be executed by one or more processors as described in any one of claims 1 to 5.