CN108133399B - High-concurrency quick-response method, device and system for accurately deducting second-killing inventory - Google Patents

High-concurrency quick-response method, device and system for accurately deducting second-killing inventory Download PDF

Info

Publication number
CN108133399B
CN108133399B CN201611085964.6A CN201611085964A CN108133399B CN 108133399 B CN108133399 B CN 108133399B CN 201611085964 A CN201611085964 A CN 201611085964A CN 108133399 B CN108133399 B CN 108133399B
Authority
CN
China
Prior art keywords
token
user
inventory
cache queue
redis cache
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201611085964.6A
Other languages
Chinese (zh)
Other versions
CN108133399A (en
Inventor
兰华勇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201611085964.6A priority Critical patent/CN108133399B/en
Publication of CN108133399A publication Critical patent/CN108133399A/en
Application granted granted Critical
Publication of CN108133399B publication Critical patent/CN108133399B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q30/00Commerce
    • G06Q30/06Buying, selling or leasing transactions
    • G06Q30/0601Electronic shopping [e-shopping]
    • G06Q30/0605Supply or demand aggregation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/0802Addressing of a memory level in which the access to the desired data or data block requires associative addressing means, e.g. caches
    • G06F12/0866Addressing of a memory level in which the access to the desired data or data block requires associative addressing means, e.g. caches for peripheral storage systems, e.g. disk cache
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2255Hash tables

Abstract

The invention provides a high-concurrency quick-response method, device and system for accurately deducting stock in seconds, which can solve the problem of less or more deductions of stock in a high-concurrency large-flow user shopping scene. The method comprises the following steps: initializing and generating a corresponding number of tokens with unique indication values according to the inventory number of second killing activities, and storing the tokens in a Redis cache queue; if a token is obtained from a Redis cache queue according to a user purchase request, inserting user information into an order database, and if the insertion is successful, successfully deducting inventory, wherein the user information comprises user identification information and user ordering information; and if the insertion fails, the stock deduction fails, and the acquired token is returned to the Redis cache queue.

Description

High-concurrency quick-response method, device and system for accurately deducting second-killing inventory
Technical Field
The invention relates to the field of computer technology and software, in particular to a method, a device and a system for accurately deducting second killing inventory with high concurrency and quick response.
Background
The second-killing and first-buying promotion activities increasingly become important means for attracting user registration and improving user liveness of e-commerce companies. Whether the second killing stock is accurately deducted is a key index for judging whether the second killing system is reliably operated. Before the second killing activity starts, a second killing promotion activity (one second killing promotion activity corresponds to one promotion ID, which is hereinafter referred to as "PromoID") is usually created according to the commodity ID (hereinafter referred to as "SKUID"), and information such as the second killing start ending time, the second killing price, the second killing stock and the like is set.
In the prior art, the initial storage and deduction modes of second killing stock (hereinafter referred to as "stock") are mainly divided into the following modes:
mode 1: and initializing the second killing inventory and storing the second killing inventory in an inventory database before the second killing activity starts. When the killing activity of the second starts, the stock deduction step: firstly, inquiring inventory stock corresponding to ProMoID; secondly, when the stock is greater than 0, update stock is equal to stock-1, otherwise, the shopping fails; and thirdly, inserting the order database to generate user order information, if the insertion fails, returning to stock update stock as stock +1, otherwise, successfully purchasing. The specific flow is shown in figure 1.
Mode 2: initializing the second killing inventory and storing the second killing inventory into an inventory buffer queue before the second killing activity starts, and deducting the inventory when the second killing activity starts: firstly, acquiring inventory stock corresponding to ProMoID; secondly, when the stock is greater than 0, setting stock to stock-1, otherwise, the robbery fails; and thirdly, when the stock is less than 0, the robbery is failed, otherwise, the fourth step is carried out, the order database is inserted to generate the user order information, if the insertion fails, the returned stock set stock is stock +1, otherwise, the robbery is successful. The specific flow is shown in fig. 2.
However, the above-mentioned second killing stock storage and deduction mode has some disadvantages, especially under the condition of high concurrent large flow user's request for purchase, the stock will have less deduction or more deduction, resulting in over-selling or under-selling result of second killing activity. The method comprises the following specific steps:
in the mode 1: the second-killing inventory stock is stored in a relational database, and is limited by the number of connections and the database, so that the performance of the database is sharply reduced and even abnormal under high concurrency requests, and the query and the inventory updating are failed. In addition, the inventory deduction logic of mode 1 will cause the risk of inventory multi-deduction under high concurrency, and the reason for multi-deduction is shown in fig. 3: if between T1-T2, the inventory stock is found if the concurrent request A, B, C queries that the inventory stock is 1, then inventory deduction is performed respectively, and since inventory deduction operation needs to lock the row, that is, only one request obtains a row lock at the same time, then the request A, B, C deducts the inventory in a serial manner in sequence, and finally the inventory deduction is reduced to a negative number and the purchase is successful, and obviously, the phenomenon of over-selling occurs due to multiple deductions of the inventory.
In the mode 2: compared with the mode 1, the obvious benefit of storing the second killing in the key-value cache queue is as follows: under a high concurrency scene, the inquiry and deduction of the inventory hardly influences the cache performance, and further the normal operation of the second killing system can be effectively supported. Meanwhile, in order to solve the problem of stock deduction, on the basis of the mode 1, a judgment logic after stock deduction and updating is added, and then the phenomenon of over-selling is avoided, as shown in fig. 4. However, mode 2 also has significant disadvantages: if the user successfully deducts the stock reduction but fails to insert the user information into the order database, the stock will be returned, and the number of the stock after the stock +1 is still negative at the moment, if the number of the stock is judged to be less than 0 when the next request D comes in, the shopping is failed, and the phenomenon of selling is reduced. As shown in fig. 5.
Disclosure of Invention
In view of this, the invention provides a method, a device and a system for accurately deducting the second-kill inventory with high concurrency and quick response, which can solve the problem of less or more deductions of inventory in the scene of high-concurrency and large-flow user shopping.
To achieve the above objects, according to one aspect of the present invention, there is provided a method for highly concurrent fast response second kill inventory precision deduction.
The invention discloses a high-concurrency quick-response second-killing accurate inventory deduction method, which comprises the following steps of: initializing and generating a corresponding number of tokens with unique indication values according to the inventory number of second killing activities, and storing the tokens in a Redis cache queue; if a token is obtained from a Redis cache queue according to a user purchase request, inserting user information into an order database, and if the insertion is successful, successfully deducting inventory, wherein the user information comprises user identification information and user ordering information; and if the insertion fails, the stock deduction fails, and the acquired token is returned to the Redis cache queue.
Optionally, the method further comprises: and after the token is acquired from the Redis cache queue, storing a user acquisition record into a token distribution table, wherein the user acquisition record comprises user identification information and the acquired token.
Optionally, the method further comprises: if the insertion fails, besides returning the acquired token to the Redis cache queue, deleting the corresponding user acquisition record from the token distribution table.
Optionally, the method further comprises: before storing the user acquisition record into the token distribution table, checking user identification information, if the user identification information exists in the token distribution table, prompting deduction failure, not storing the user acquisition record, and returning the acquired token to a Redis cache queue.
Optionally, the token distribution table is a Redis hash table.
Optionally, the method further comprises: an optimistic locking mechanism is adopted, and only one operation of obtaining token from a Redis cache queue is processed at the same time; and when the acquired token is returned to the Redis cache queue, if a plurality of returning operation requests exist at the same time, blocking waiting to ensure that all the token returning is successful.
To achieve the above objects, according to another aspect of the present invention, there is provided a highly concurrent fast response second kill inventory precision deduction device.
The invention discloses a device for accurately deducting the second killing stock with high concurrency and quick response, which comprises: the inventory initialization module is used for initializing and generating tokens with corresponding number according to the inventory quantity of second killing activities and storing the tokens in a Redis cache queue; the stock deduction module is used for inserting user information into an order database if tokens are obtained from a Redis cache queue according to a user purchase request, and the stock deduction is successful if the tokens are inserted successfully, wherein the user information comprises user identification information and user order placing information; and the inventory rollback module is used for failing inventory deduction if the insertion fails, and backing the acquired token to a Redis cache queue.
Optionally, the inventory deduction module is further configured to: and after the token is acquired from the Redis cache queue, storing a user acquisition record into a token distribution table, wherein the user acquisition record comprises user identification information and the acquired token.
Optionally, the apparatus is further configured to: if the insertion fails, the inventory deduction module deletes the corresponding user acquisition record from the token distribution table except that the inventory rollback module backs the acquired token to the Redis cache queue.
Optionally, the apparatus further comprises: the system comprises a user purchase limiting module, an inventory deduction module and an inventory rollback module, wherein the user purchase limiting module is used for verifying user identification information before the inventory deduction module stores user acquisition records into a token distribution table, and prompting deduction failure if the user identification information exists in the token distribution table.
Optionally, the token distribution table is a Redis hash table.
Optionally, the apparatus is further configured to: the inventory deduction module adopts an optimistic lock mechanism, and only processes one operation of obtaining token from a Redis cache queue at the same time; and when the inventory rollback module backs the acquired token to a Redis cache queue, if a plurality of rollback operation requests exist at the same time, blocking and waiting to ensure that all tokens are successfully backed.
To achieve the above objects, according to yet another aspect of the present invention, there is provided a system for high-concurrency, fast-response, accurate deduction of second kill inventory.
The invention discloses a system for accurately deducting the second killing stock with high concurrency and quick response, which comprises: a memory and a processor, wherein the memory is to store instructions; the processor is configured to perform the following actions in accordance with the instructions: initializing and generating a corresponding number of tokens with unique indication values according to the inventory number of second killing activities, and storing the tokens in a Redis cache queue; if a token is obtained from a Redis cache queue according to a user purchase request, inserting user information into an order database, and if the insertion is successful, successfully deducting inventory, wherein the user information comprises user identification information and user ordering information; and if the insertion fails, the stock deduction fails, and the acquired token is returned to the Redis cache queue.
To achieve the above object, according to still another aspect of the present invention, an electronic apparatus is provided.
An electronic device of the present invention includes: one or more processors; the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors realize the method for accurately deducting the high-concurrency quick-response second-kill inventory.
To achieve the above object, according to still another aspect of the present invention, there is provided a computer-readable medium.
A computer-readable storage medium of the present invention has stored thereon a computer program which, when executed by a processor, implements the method for high-concurrency fast-response second-kill inventory-accurate deduction of an embodiment of the present invention.
According to the technical scheme of the invention, under the high-concurrency large-flow user shopping scene, the quick-response second-killing stock accurate deduction is realized by utilizing the cache queue and the token technology with the unique marking value, so that the problem of under-selling or over-selling can be effectively solved; the token is stored by utilizing the hash table, so that a user purchase limiting strategy can be realized, and the phenomenon that the same user purchases for multiple times is avoided; when the user information is failed to be inserted into the order database, the token is returned to the cache queue, so that the phenomenon of few sales can be effectively avoided; by utilizing an optimistic lock and a congestion waiting mechanism, the accuracy of token acquisition and token rollback can be ensured.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic inventory reduction of a prior art inventory reduction mode 1;
FIG. 2 is a schematic inventory reduction of a prior art inventory reduction mode 2;
FIG. 3 is a diagram of a prior art stock deduction mode 1 over-sell reason analysis;
FIG. 4 is a prior art over sell prevention analysis diagram of inventory deduction mode 2;
FIG. 5 is a prior art analysis of the shortcuts reason for inventory deduction mode 2;
FIG. 6 is a schematic diagram of the main steps of a method for high-concurrency fast-response second kill inventory precision deduction according to an embodiment of the present invention;
FIG. 7 is a block flow diagram of a method of high-concurrency, fast-response, second kill inventory precision deduction in accordance with an embodiment of the present invention;
FIG. 8 is a schematic diagram of stock token creation of a method for high-concurrency fast-response second-kill stock precision deduction according to an embodiment of the present invention;
FIG. 9 is a schematic inventory deduction diagram of a method for high-concurrency quick-response second-kill inventory precision deduction according to an embodiment of the present invention;
FIG. 10 is a schematic diagram of inventory rollback for a method of high-concurrency fast-response second-kill inventory deduction according to an embodiment of the present invention;
FIG. 11 is a schematic diagram of a user purchase limit of a method for a high-concurrency quick-response second-kill inventory-accurate deduction according to an embodiment of the present invention;
FIG. 12 is a schematic diagram of the major modules of a high-concurrency, fast-response, second kill inventory precision deduction apparatus, in accordance with an embodiment of the present invention;
fig. 13 is a schematic diagram of the main parts of a system for high-concurrency quick-response second kill inventory precision deduction according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
The technical scheme of the embodiment of the invention mainly solves the problem of less inventory or more inventory in the high-concurrency large-flow user shopping scene.
Fig. 6 is a schematic diagram of the main steps of a method for highly concurrent fast response second kill inventory precision deduction according to an embodiment of the present invention.
As shown in fig. 6, the method for accurately deducting the second inventory killing with high concurrency and quick response in the embodiment of the present invention mainly includes the following steps:
step S61: according to the inventory quantity of second killing activities, a corresponding number of tokens (tokens, a type of evidence, having a unique marking function) with unique marking values are generated through initialization, and the tokens are stored in a Redis cache queue. The purpose of this step is to complete the initialization of the inventory.
After the stock initialization of step S61 is completed, the deduction is performed from step S62.
Step S62: and if the token is acquired from the Redis cache queue according to the purchase request of the user, inserting the user information into an order database, and if the insertion is successful, successfully deducting the stock, wherein the user information comprises user identification information and user ordering information. The step is to realize real-time accurate deduction of the inventory according to the purchase request of the user. After the token is acquired from the Redis cache queue, a user acquisition record can be stored in a token distribution table, wherein the user acquisition record comprises user identification information and the acquired token so as to record the inventory deduction condition in real time.
According to the general user purchase restriction specificity of the second killing activity, the method for accurately deducting the second killing inventory with high concurrency and quick response of the embodiment of the invention can further comprise the steps of verifying user identification information before storing the user acquisition record in the token distribution table, prompting deduction failure if the user identification information exists in the token distribution table, not storing the user acquisition record, and returning the acquired token to a Redis cache queue.
Step S63: if the order database insertion in the step S62 fails, the stock deduction fails, and the obtained token is returned to the Redis cache queue.
In addition, if the insertion fails, besides returning the acquired token to the Redis cache queue, the corresponding user acquisition record is deleted from the token distribution table.
In the above description, the token distribution table may be a Redis hash table.
In the above description, when a token needs to be obtained from a cache queue, an optimistic lock mechanism may be generally adopted, and only one operation of obtaining the token from a Redis cache queue is processed at the same time, so as to ensure accuracy of token deduction and avoid occurrence of a commodity over-sale phenomenon; and when the acquired token needs to be backed to a Redis cache queue, if a plurality of backing operation requests exist at the same time, blocking and waiting to ensure that all tokens are successfully backed, so as to avoid the phenomenon of commodity burn-in.
In the embodiment of the invention, the method for accurately deducting the second-killing inventory with high concurrency and quick response is mainly carried out by using a device for accurately deducting the second-killing inventory with high concurrency and quick response. The device for accurately deducting the second killing stock with high concurrency and quick response mainly comprises three modules: the system comprises an inventory initialization module, an inventory deduction module and an inventory rollback module, and further comprises a user purchase limiting module.
Firstly, generating tokens with corresponding number according to stock quantity stock, and storing the tokens in a Redis cache queue so as to finish the initialization of the stock. At the beginning of the second kill, the deduction of the stock quantity stock is converted into the deduction of the token. If the token is not acquired, the emergency purchase fails; if the token is successfully acquired to represent that the robbery qualification is obtained, inserting the user information into an order database, if the storage is successful, representing that the robbery is successful, if the storage is failed, the robbery is failed, and simultaneously returning the acquired token to a Redis cache queue. However, the second killing action generally has the characteristic of limiting the number of pins to buy 1 piece according to the identity of the user, such as a pin (personal identification number), after the token is obtained, the limited-buying verification processing is generally carried out on the same promoID (proxy identity) of the robbery user, and if the user has purchased the robbery, the token is returned and the user is prompted to fail in the robbery. The general block diagram is shown in fig. 7.
The main flow of the method for accurately deducting the stock in the second killing mode with high concurrency and quick response according to the embodiment of the invention is described in detail below by combining the functions of the modules of the device for accurately deducting the stock in the second killing mode with high concurrency and quick response.
An inventory initialization module: recording the stock quantity of second killing set by an operator, circularly calling Unique marking value generation algorithms such as universal Unique identification code UUID (universal Unique identifier) and the like, generating token (token is convenient for log analysis) with a universal Unique marking value, and storing the token into a Redis cache queue. Meanwhile, the token is written into the log file token _ log, so that the second killing activity can be checked conveniently when the second killing activity is finished. Thus, the one-to-one mapping of stock quantity to tokens is completed, so that the quantity of tokens and the stock are kept consistent. As shown in fig. 8.
An inventory deduction module: the underlying data structure employed by the Redis cache queue supports high concurrency fetch operations on tokens. According to a high concurrency request of a user, taking out the token from the queue by adopting an LPOP (Left POP (removing an element from the Left side of the queue, also called removing and returning the first element in the queue) instruction, wherein the LPOP adopts an optimistic lock to ensure the thread safety, namely only one thread is allowed to obtain the token at the same time, other threads are queued for waiting, the condition that a plurality of threads obtain the same token at the same time is avoided, and the problem of over-selling is effectively avoided. The detailed subtraction procedure is as follows: when the killing activity of the second starts, an LPOP mechanism is adopted to take out the token from the Redis cache queue, if the token is NIL (no value and empty), the robbery fails, otherwise, a logic for judging whether the second is purchased is carried out, if the token passes the logic, the user information is inserted into an order database, for example, the user information can be stored into an order information table userInfo _ table, and if the insertion of the userInfo _ table is successful, the robbery succeeds. As shown in fig. 9.
An inventory rollback module: if the user succeeds in obtaining the token but fails to insert the userInfo _ table into the order information table, deleting the corresponding user token getting record in the token distribution table, and returning the token to the Redis cache queue. And (2) backing the token by using an RPUSH (Right PUSH, namely inserting an element from the Right side of the queue, also called inserting an element from the tail of the queue), wherein the RPUSH instruction adopts a blocking access mode, and when a plurality of threads simultaneously back the token to the Redis cache queue, the token is blocked and waits until the token is successfully inserted and then returns. The method completely simulates the stock rollback mode of a real scene, can solve the problem of stock rollback failure in the mode 2 in the prior art by adopting the stock quantity deduction mode, and effectively avoids the phenomenon of selling less. The process is shown in figure 10.
A user purchase limit module: since the second killing action usually needs to be limited in purchasing, namely, only one user can purchase the same second killing action. In the embodiment of the invention, the Redis hash table can be used as the token distribution table, namely, a promoID-pin-token-value data structure is adopted for the limited-pin purchase processing. The method is characterized in that the promoID-pin is used as a hash key, a record can be generated and stored in a token distribution table after a user obtains the token, when the same user tries to insert the table for the second time, because a value token _ value corresponding to the promoID-pin hash key already exists, the token distribution table is inserted unsuccessfully once, and the problem that the same pin is purchased for many times is effectively avoided. The process is shown in figure 11.
According to the method for accurately deducting the second killing stock with high concurrency and quick response, disclosed by the embodiment of the invention, the quickly responded accurate deduction of the second killing stock is realized by utilizing the cache queue and the token technology with the unique mark value under the high concurrency and large flow user shopping scene, so that the problem of sale reduction or over-sale can be effectively solved; the token is stored by utilizing the hash table, so that a user purchase limiting strategy can be realized, and the phenomenon that the same user purchases for multiple times is avoided; when the user information is failed to be inserted into the order database, the token is returned to the cache queue, so that the phenomenon of few sales can be effectively avoided; by utilizing an optimistic lock and a congestion waiting mechanism, the accuracy of token acquisition and token rollback can be ensured.
Fig. 12 is a schematic diagram of the main modules of a high-concurrency quick-response second-kill inventory-accurate deduction device according to an embodiment of the present invention.
As shown in fig. 12, the apparatus 120 for high-concurrency quick-response second-kill inventory-accurate deduction according to the embodiment of the present invention mainly includes the following modules: the system comprises an inventory initialization module 121, an inventory deduction module 122 and an inventory rollback module 123, wherein the inventory initialization module 121 is used for initializing and generating tokens with corresponding numbers according to the quantity of the inventory killed in seconds, and storing the tokens in a Redis cache queue; the inventory deduction module 122 is configured to insert user information into the order database if a token is obtained from the Redis cache queue according to a user purchase request, and if the insertion is successful, the inventory deduction is successful, where the user information includes user identification information and user order placing information; the inventory rollback module 123 is configured to, if the insertion fails, fail to reduce the inventory, and rollback the acquired token to the Redis cache queue.
Wherein the inventory deduction module 122 is further operable to: and after the token is acquired from the Redis cache queue, storing a user acquisition record into a token distribution table, wherein the user acquisition record comprises user identification information and the acquired token. The token distribution table may be, but is not limited to, a Redis hash table.
The apparatus 120 may also be configured to: if the insertion fails, the inventory deduction module deletes the corresponding user acquisition record from the token distribution table except that the inventory rollback module backs the acquired token to the Redis cache queue.
Furthermore, the apparatus 120 may further comprise: a user purchase limiting module (not shown in the figure) configured to check user identification information before the inventory deduction module stores the user acquisition record in the token distribution table, and prompt deduction failure if the user identification information already exists in the token distribution table, where the inventory deduction module does not store the user acquisition record, and the inventory rollback module backs the acquired token to a Redis cache queue.
The apparatus 120 may also be configured to: the inventory deduction module adopts an optimistic lock mechanism, and only processes one operation of obtaining token from a Redis cache queue at the same time; and when the inventory rollback module backs the acquired token to a Redis cache queue, if a plurality of rollback operation requests exist at the same time, blocking and waiting to ensure that all tokens are successfully backed.
Fig. 13 is a schematic diagram of the main parts of a system for high-concurrency quick-response second kill inventory precision deduction according to an embodiment of the present invention.
As shown in fig. 13, the system 130 for high-concurrency quick-response second-kill inventory-accurate deduction mainly includes: a memory 131 and a processor 132, wherein the memory 131 is used for storing instructions; the processor 132 is configured to perform the following actions in accordance with the instructions: initializing and generating a corresponding number of tokens with unique indication values according to the inventory number of second killing activities, and storing the tokens in a Redis cache queue; if a token is obtained from a Redis cache queue according to a user purchase request, inserting user information into an order database, and if the insertion is successful, successfully deducting inventory, wherein the user information comprises user identification information and user ordering information; and if the insertion fails, the stock deduction fails, and the acquired token is returned to the Redis cache queue.
From the above description, it can be seen that the quick response second killing inventory is accurately deducted by using the cache queue and the token technology with the unique indication value in the high-concurrency large-flow user shopping scene, so that the problem of under-selling or over-selling can be effectively solved; the token is stored by utilizing the hash table, so that a user purchase limiting strategy can be realized, and the phenomenon that the same user purchases for multiple times is avoided; when the user information is failed to be inserted into the order database, the token is returned to the cache queue, so that the phenomenon of few sales can be effectively avoided; by utilizing an optimistic lock and a congestion waiting mechanism, the accuracy of token acquisition and token rollback can be ensured.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (13)

1. A method for accurately deducting stock killing time-of-second with high concurrency and quick response is characterized by comprising the following steps:
initializing and generating a corresponding number of tokens with unique indication values according to the inventory number of second killing activities, and storing the tokens in a Redis cache queue;
if a token is obtained from a Redis cache queue according to a user purchase request, inserting user information into an order database, and if the insertion is successful, successfully deducting inventory, wherein the user information comprises user identification information and user ordering information; wherein, an optimistic locking mechanism is adopted, and only one operation of obtaining token from a Redis cache queue is processed at the same time;
if the insertion fails, the stock deduction fails, and the obtained token is returned to a Redis cache queue; when the acquired token is returned to the Redis cache queue, if a plurality of returning operation requests exist at the same time, the waiting is blocked, so that all the tokens are ensured to be returned successfully.
2. The method of claim 1, further comprising: and after the token is acquired from the Redis cache queue, storing a user acquisition record into a token distribution table, wherein the user acquisition record comprises user identification information and the acquired token.
3. The method of claim 2, further comprising: if the insertion fails, besides returning the acquired token to the Redis cache queue, deleting the corresponding user acquisition record from the token distribution table.
4. The method of claim 2, further comprising: before storing the user acquisition record into the token distribution table, checking user identification information, if the user identification information exists in the token distribution table, prompting deduction failure, not storing the user acquisition record, and returning the acquired token to a Redis cache queue.
5. The method of claim 2, wherein the token distribution table is a Redis hash table.
6. A device that accurate deduction of stock is killed to second of high concurrency quick response, its characterized in that includes:
the inventory initialization module is used for initializing and generating tokens with corresponding number according to the inventory quantity of second killing activities and storing the tokens in a Redis cache queue;
the stock deduction module is used for inserting user information into an order database if tokens are obtained from a Redis cache queue according to a user purchase request, and the stock deduction is successful if the tokens are inserted successfully, wherein the user information comprises user identification information and user order placing information; wherein, an optimistic locking mechanism is adopted, and only one operation of obtaining token from a Redis cache queue is processed at the same time;
the inventory rollback module is used for failing inventory deduction if the insertion fails, and backing the acquired token to a Redis cache queue; when the acquired token is returned to the Redis cache queue, if a plurality of returning operation requests exist at the same time, the waiting is blocked, so that all the tokens are ensured to be returned successfully.
7. The apparatus of claim 6, wherein the inventory deduction module is further to: and after the token is acquired from the Redis cache queue, storing a user acquisition record into a token distribution table, wherein the user acquisition record comprises user identification information and the acquired token.
8. The apparatus of claim 7, wherein the apparatus is further configured to:
if the insertion fails, the inventory deduction module deletes the corresponding user acquisition record from the token distribution table except that the inventory rollback module backs the acquired token to the Redis cache queue.
9. The apparatus of claim 7, further comprising: the system comprises a user purchase limiting module, an inventory deduction module and an inventory rollback module, wherein the user purchase limiting module is used for verifying user identification information before the inventory deduction module stores user acquisition records into a token distribution table, and prompting deduction failure if the user identification information exists in the token distribution table.
10. The apparatus of claim 7, wherein the token distribution table is a Redis hash table.
11. A system for accurate deduction of second-killing stock with high concurrency and quick response is characterized by comprising: a memory and a processor, wherein,
the memory is to store instructions;
the processor is configured to perform the following actions in accordance with the instructions:
initializing and generating a corresponding number of tokens with unique indication values according to the inventory number of second killing activities, and storing the tokens in a Redis cache queue;
if a token is obtained from a Redis cache queue according to a user purchase request, inserting user information into an order database, and if the insertion is successful, successfully deducting inventory, wherein the user information comprises user identification information and user ordering information; wherein, an optimistic locking mechanism is adopted, and only one operation of obtaining token from a Redis cache queue is processed at the same time;
if the insertion fails, the stock deduction fails, and the obtained token is returned to a Redis cache queue; when the acquired token is returned to the Redis cache queue, if a plurality of returning operation requests exist at the same time, the waiting is blocked, so that all the tokens are ensured to be returned successfully.
12. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-5.
13. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-5.
CN201611085964.6A 2016-11-30 2016-11-30 High-concurrency quick-response method, device and system for accurately deducting second-killing inventory Active CN108133399B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201611085964.6A CN108133399B (en) 2016-11-30 2016-11-30 High-concurrency quick-response method, device and system for accurately deducting second-killing inventory

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201611085964.6A CN108133399B (en) 2016-11-30 2016-11-30 High-concurrency quick-response method, device and system for accurately deducting second-killing inventory

Publications (2)

Publication Number Publication Date
CN108133399A CN108133399A (en) 2018-06-08
CN108133399B true CN108133399B (en) 2021-01-26

Family

ID=62387935

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201611085964.6A Active CN108133399B (en) 2016-11-30 2016-11-30 High-concurrency quick-response method, device and system for accurately deducting second-killing inventory

Country Status (1)

Country Link
CN (1) CN108133399B (en)

Families Citing this family (28)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110599277A (en) * 2018-06-12 2019-12-20 北京京东尚科信息技术有限公司 Inventory deduction method and device
CN110738507A (en) * 2018-07-18 2020-01-31 北京京东金融科技控股有限公司 exchange code acquisition method and device
CN109191233B (en) * 2018-07-31 2022-09-02 上海幻电信息科技有限公司 Second order-killing request processing method and device and storage medium
CN110796401A (en) * 2018-08-03 2020-02-14 京东数字科技控股有限公司 Inventory deduction method, system and server
CN111178998A (en) * 2018-11-09 2020-05-19 商派软件有限公司 Second killing platform and method for high access volume
CN111177233A (en) * 2018-11-09 2020-05-19 商派软件有限公司 CAS inventory control method
CN111176824B (en) * 2018-11-12 2021-04-20 商派软件有限公司 Method for processing high-concurrency activity registration
CN110189158A (en) * 2019-04-16 2019-08-30 德邦物流股份有限公司 A kind of logistics billing method and system based on charging regulation engine
CN110347692B (en) * 2019-06-03 2023-05-26 创新先进技术有限公司 Inventory management method and device based on cache
CN110333951B (en) * 2019-07-09 2023-08-01 北京首汽智行科技有限公司 Commodity purchase request distribution method
CN110489694A (en) * 2019-07-30 2019-11-22 阿里巴巴集团控股有限公司 For handling the method and system of high concurrent request
CN112416314A (en) * 2020-01-21 2021-02-26 上海哔哩哔哩科技有限公司 Dynamic inventory management method and system
CN111309746A (en) * 2020-02-13 2020-06-19 贝壳技术有限公司 Asynchronous parallel data synchronization method and device
CN111324622A (en) * 2020-02-20 2020-06-23 中国建设银行股份有限公司 Resource first-aid-purchase processing method, device, equipment and storage medium
CN113537852A (en) * 2020-04-14 2021-10-22 成都鼎桥通信技术有限公司 Second killing processing method and system
CN111582780B (en) * 2020-04-20 2023-06-09 重庆锐云科技有限公司 Commodity purchase waiting channel construction method, device, server and storage medium
CN111506445A (en) * 2020-04-21 2020-08-07 北京思特奇信息技术股份有限公司 Method and system for preventing repeated malicious ordering of commodities based on REDIS cache
CN112134808B (en) * 2020-07-21 2024-02-02 上海寻梦信息技术有限公司 Method and device for issuing bin allocation service speed control, electronic equipment and storage medium
CN112132662B (en) * 2020-09-28 2023-06-20 广州立白企业集团有限公司 Commodity second killing method and device, computer equipment and storage medium
CN112184326A (en) * 2020-10-14 2021-01-05 深圳市欢太科技有限公司 Method for processing high-concurrency killing activity, high-concurrency system, terminal and computer-readable storage medium
CN112102044B (en) * 2020-11-10 2021-03-09 成都四方伟业软件股份有限公司 Method, system and device for processing high-concurrency second-killing commodities by message queue
CN113807760A (en) * 2021-01-07 2021-12-17 北京沃东天骏信息技术有限公司 Inventory information processing method and device, readable storage medium and electronic equipment
CN112860746B (en) * 2021-02-01 2023-04-07 上海万物新生环保科技集团有限公司 Cache reduction-based method, equipment and system
CN112988812B (en) * 2021-03-10 2024-02-06 京东科技控股股份有限公司 Inventory data processing method, device, equipment and storage medium
CN113077220A (en) * 2021-04-16 2021-07-06 北京京东拓先科技有限公司 User request processing method and device
CN113360570A (en) * 2021-05-31 2021-09-07 紫光云技术有限公司 High-concurrency system inventory module implementation method
CN113836158A (en) * 2021-09-22 2021-12-24 上海哔哩哔哩科技有限公司 Commodity inventory deduction method and device
CN114331576A (en) * 2021-12-30 2022-04-12 福建博思软件股份有限公司 Electronic ticket number rapid ticket taking method based on high concurrency scene and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103426072A (en) * 2013-07-16 2013-12-04 无限极(中国)有限公司 Order processing system of high concurrency competitive inventory and processing method thereof
CN105139191A (en) * 2015-09-15 2015-12-09 联动优势电子商务有限公司 Method and device for obtaining order information
CN105303431A (en) * 2015-11-17 2016-02-03 张斌 Panic buying method of online shopping
CN106126673A (en) * 2016-06-29 2016-11-16 上海浦东发展银行股份有限公司信用卡中心 A kind of based on Redis and HBase point of locking method

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103426072A (en) * 2013-07-16 2013-12-04 无限极(中国)有限公司 Order processing system of high concurrency competitive inventory and processing method thereof
CN103426072B (en) * 2013-07-16 2016-02-17 无限极(中国)有限公司 The order processing system of a kind of high concurrent competition stock and disposal route thereof
CN105139191A (en) * 2015-09-15 2015-12-09 联动优势电子商务有限公司 Method and device for obtaining order information
CN105303431A (en) * 2015-11-17 2016-02-03 张斌 Panic buying method of online shopping
CN106126673A (en) * 2016-06-29 2016-11-16 上海浦东发展银行股份有限公司信用卡中心 A kind of based on Redis and HBase point of locking method

Also Published As

Publication number Publication date
CN108133399A (en) 2018-06-08

Similar Documents

Publication Publication Date Title
CN108133399B (en) High-concurrency quick-response method, device and system for accurately deducting second-killing inventory
US20190155795A1 (en) Distributed database system, transaction processing method, lock server and storage medium
US8954408B2 (en) Allowing writes to complete without obtaining a write lock to a file
US8151247B2 (en) Test data management
CN107633016B (en) Data processing method and device and electronic equipment
CN106030512B (en) Initialization tracking of computing devices
CN106575244B (en) Patching process to ensure high availability of cloud applications
CN109191233B (en) Second order-killing request processing method and device and storage medium
US8832022B2 (en) Transaction processing device, transaction processing method and transaction processing program
CN110795447A (en) Data processing method, data processing system, electronic device, and medium
US20190258618A1 (en) Immediately-consistent lock-free indexing for distributed applications
US20070100783A1 (en) Method, system, and program for determining discrepancies between database management systems
US10997158B2 (en) Techniques for updating big data tables using snapshot isolation
US20220019625A1 (en) Systems and methods for improved transactional mainframes
KR101737578B1 (en) Method and device for automatically tuning for sql sentences generated automatically
AU2015265599B2 (en) System and method for the production of job level pre-processed backup of critical data and/or datasets in a mainframe computing environment
US9348861B2 (en) Capturing change data of deferred updates
KR102025222B1 (en) System and method for preserving interdependent corporate data consistency in a globally distributed environment
US11182375B2 (en) Metadata validation tool
JP7243207B2 (en) Information processing system, information processing device and program
US20130268503A1 (en) Database navigation of changes at commit time
US8301609B1 (en) Collision detection and data corruption protection during an on-line database reorganization
US10489368B1 (en) Datapath graph with update detection using fingerprints
US11537387B1 (en) Lock database code for online patching
US20220382660A1 (en) Method and computing device for generating action history data of application and computer-readable non-transitory recording medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant