CN111090525B - Processing method for Redis to achieve high concurrency optimization of distributed lock - Google Patents

Processing method for Redis to achieve high concurrency optimization of distributed lock Download PDF

Info

Publication number
CN111090525B
CN111090525B CN201911310027.XA CN201911310027A CN111090525B CN 111090525 B CN111090525 B CN 111090525B CN 201911310027 A CN201911310027 A CN 201911310027A CN 111090525 B CN111090525 B CN 111090525B
Authority
CN
China
Prior art keywords
sub
database
customer
databases
redis
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
CN201911310027.XA
Other languages
Chinese (zh)
Other versions
CN111090525A (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.)
Unicloud Nanjing Digital Technology Co Ltd
Original Assignee
Unicloud Nanjing Digital 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 Unicloud Nanjing Digital Technology Co Ltd filed Critical Unicloud Nanjing Digital Technology Co Ltd
Priority to CN201911310027.XA priority Critical patent/CN111090525B/en
Publication of CN111090525A publication Critical patent/CN111090525A/en
Application granted granted Critical
Publication of CN111090525B publication Critical patent/CN111090525B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • 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/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Computing Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The invention discloses a processing method for Redis to realize high concurrency optimization of distributed locks, which comprises the following steps of: s1: dividing an original database into a plurality of sub databases; s2: distributing the purchase demand of the customer to each sub-database; s3, each sub-database adopts Redis distributed lock to process the purchase demand of several distributed clients; and S4, when the residual number of all sub-databases can not individually satisfy the number of customer service requirements, automatically transferring the customer to another sub-database. The method is suitable for processing the database with high concurrency and ordering at the same time.

Description

Processing method for Redis to realize high concurrency optimization of distributed lock
Technical Field
The invention relates to the field of database processing, in particular to a processing method for Redis to realize high concurrency optimization of distributed locks.
Background
The phenomenon of stock over-selling of the database is shown in fig. 2, when the database only has 12 products, and two clients propose to buy 10 products to the database within a short time, the 12 products in the database respond to the first client first, the quantity of the 12 products in the database is greater than the requirement (10 products) of the first client and the purchase is allowed, however, the first client does not order and confirms to submit an order for purchase, the 10 products purchased by the first client are not subtracted from the database first, and the database still displays that 12 products exist at this time. The second customer then places an order for 10 products, the 12 products in the database are still larger than the second customer's (10) requirements, and the second customer also submits an order later. When the first customer orders successfully, the second customer orders successfully, but although the second customer orders successfully, 10 products purchased by the first customer are subtracted from the database, only 2 products remain in the database, and the demand database of the actual 10 products of the second customer cannot be supplied, so that the phenomenon of over-sale with low stock occurs.
As shown in fig. 3, the principle of Redis implementing distributed lock to solve stock over-selling is that when a first client purchases 10 products, the database locks the products purchased by the first client, and a second client waits for the first client to submit an order, that is, after the first client unlocks, the second client can continue to make an order. If the time for unlocking a single client is 20ms, namely the second client can continue to issue the order after 20ms after the first client issues the order, only 50 clients can issue the order in sequence within 1s, and the method is not suitable for high-concurrence simultaneous second-time rush services (many clients issue orders at the same time).
Disclosure of Invention
In order to overcome the defects in the prior art, the invention provides a processing method for Redis to realize high concurrency optimization of a distributed lock, which is suitable for processing a database with high concurrency and ordering at the same time.
In order to achieve the above object, a processing method for Redis to implement high concurrency optimization of distributed locks, comprising the following steps: s1: dividing an original database into a plurality of sub databases; s2: distributing the purchase demand of the customer to each sub-database; s3, each sub database adopts Redis distributed lock to process the purchase demand of several distributed clients; and S4, automatically transferring the customer to another sub-database when the remaining number of the single sub-database can not meet the customer service requirement.
Further, S2 is assigned to each sub-database in a random manner.
Further, in S4, when the remaining number of all sub-databases cannot satisfy the customer 'S requirement alone and the sum of the remaining number of all sub-databases can satisfy the customer' S requirement, the customer is prompted to reduce the number of single purchases and then purchase again.
Further, the number of products in each sub-database in S1 is equal.
Further, when the remaining number of the single sub-database cannot satisfy the number of the customer service requirements, in S4, the sub-databases are sequentially switched to another database in a decreasing manner according to the names of the sub-databases.
Has the advantages that: the original database is divided into a plurality of sub-databases, each sub-database receives the customer purchase demand at the same time, the original database can only complete one customer purchase demand every 20ms, each sub-database in the plurality of sub-databases can complete one customer purchase demand every 20ms, and the processing speed of the order is dependent on the number of the divided sub-databases.
Drawings
The present invention will be further described and illustrated with reference to the following drawings.
FIG. 1 is a schematic diagram of the steps of an optimization of a distributed lock in the present application;
FIG. 2 is a schematic diagram illustrating a prior art stock over-selling phenomenon;
FIG. 3 is a schematic diagram illustrating the principles of Redis implementing a distributed lock to resolve stock oversell in the prior art.
Detailed Description
The technical scheme of the invention is more clearly and completely explained by the description of the preferred embodiment of the invention in combination with the attached drawings.
As shown in fig. 1, a processing method for Redis to implement high concurrency optimization of distributed locks includes the following steps:
s1: dividing an original database into a plurality of sub databases;
s2: distributing the purchase demand of the customer to each sub-database;
s3, each sub database adopts Redis distributed lock to process the purchase demand of several distributed clients;
and S4, automatically transferring the customer to another sub-database when the remaining number of the single sub-database can not meet the customer service requirement.
In step S1, the original database has a plurality of data sets, each data set is all information (brand, color, size, etc.) of a product, the plurality of data sets are divided into a plurality of data set sets according to a fixed number, each data set is a sub-database, and each sub-database is given a name.
In step S2, a random algorithm is implemented by the code, through which each customer' S purchase demand is randomly assigned to one of the plurality of sub-databases.
In step S3, after a plurality of customer requirements are randomly allocated to each sub-database, each sub-database can only process one customer requirement allocated to the sub-database every 20ms due to the Redis distributed lock, but within every 20ms, a plurality of sub-databases simultaneously process a different customer requirement, and compared with the original database processing, the processing speed of the customer is increased by a plurality of sub-databases, which is the number of sub-databases.
When the remaining number of the single sub-database of the client is not enough to satisfy the number of the customer service requirement in step S4, the client is transferred to another sub-database, and the sub-databases are sequentially forwarded according to the names of the sub-databases in step S1 until the customer requirement is satisfied.
In step S4, when the remaining number of all sub-databases alone cannot satisfy the customer requirement, but the sum of the remaining number of all sub-databases can satisfy the customer requirement, the customer is prompted to reduce the number of single purchases and then purchase again. And if the sum of the residual quantity of all the sub-databases cannot meet the customer requirement, prompting that the customer is insufficient in quantity and cannot purchase the sub-databases.
The above detailed description merely describes preferred embodiments of the present invention and does not limit the scope of the invention. Without departing from the spirit and scope of the present invention, it should be understood that various changes, substitutions and alterations can be made herein by those skilled in the art without departing from the spirit and scope of the invention as defined by the appended claims and their equivalents. The scope of the invention is defined by the claims.

Claims (5)

1. A processing method for Redis to realize high concurrency optimization of distributed locks is characterized by comprising the following steps:
s1: dividing an original database into a plurality of sub databases;
s2: distributing the purchase demand of the customer to each sub-database;
s3, each sub database adopts Redis distributed lock to process the purchase demand of several distributed clients;
and S4, when the residual number of the sub-database can not meet the customer service requirement number, automatically transferring the customer to another sub-database.
2. The method of claim 1, wherein the Redis is assigned to each sub-database in a random manner in S2.
3. The processing method of claim 1, wherein in S4, when the remaining number of all sub databases cannot individually satisfy the customer requirement and the sum of the remaining number of all sub databases can satisfy the customer requirement, the customer is prompted to reduce the number of single purchases and then purchase again.
4. The method of claim 1, wherein the number of products in each sub-database in the S1 is equal.
5. The method as claimed in claim 1, wherein when the remaining number of the single sub-database cannot satisfy the number of the customer service requirements, the step of S4 is performed by sequentially forwarding to another database in a descending manner according to the names of the sub-databases.
CN201911310027.XA 2019-12-18 2019-12-18 Processing method for Redis to achieve high concurrency optimization of distributed lock Active CN111090525B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911310027.XA CN111090525B (en) 2019-12-18 2019-12-18 Processing method for Redis to achieve high concurrency optimization of distributed lock

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911310027.XA CN111090525B (en) 2019-12-18 2019-12-18 Processing method for Redis to achieve high concurrency optimization of distributed lock

Publications (2)

Publication Number Publication Date
CN111090525A CN111090525A (en) 2020-05-01
CN111090525B true CN111090525B (en) 2022-09-23

Family

ID=70395700

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911310027.XA Active CN111090525B (en) 2019-12-18 2019-12-18 Processing method for Redis to achieve high concurrency optimization of distributed lock

Country Status (1)

Country Link
CN (1) CN111090525B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106372994A (en) * 2016-08-31 2017-02-01 北京炎黄新星网络科技有限公司 Method and system for processing orders
CN106649328A (en) * 2015-10-30 2017-05-10 宁波轩悦行电动汽车服务有限公司 Time-sharing lease system data access layer interface establishment method
CN106874094A (en) * 2017-02-17 2017-06-20 广州爱九游信息技术有限公司 timed task processing method, device and computing device

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109155021B (en) * 2016-03-18 2022-04-15 沃尔玛阿波罗有限责任公司 System and method for managing inventory of products purchased by a customer from a retailer

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106649328A (en) * 2015-10-30 2017-05-10 宁波轩悦行电动汽车服务有限公司 Time-sharing lease system data access layer interface establishment method
CN106372994A (en) * 2016-08-31 2017-02-01 北京炎黄新星网络科技有限公司 Method and system for processing orders
CN106874094A (en) * 2017-02-17 2017-06-20 广州爱九游信息技术有限公司 timed task processing method, device and computing device

Also Published As

Publication number Publication date
CN111090525A (en) 2020-05-01

Similar Documents

Publication Publication Date Title
CN109711778B (en) Inventory allocation method, device and storage medium of warehouse network
JP3526585B2 (en) Query Processing Optimization Method for Distributed Database
CN1858797A (en) Integrated operation platform system for city electronic business and logistics distribution
CN106485441A (en) A kind of take-away allocator and system
US9631938B2 (en) Route planning system and method
US7979324B2 (en) Virtual catalog
CN104008199B (en) A kind of data query method
CN110175795A (en) A kind of common carrier distribution method and system
CN110175862A (en) Commodity price calculation method and system are sold for electric business platform
CN106777311A (en) Flight freight space state cache method and system
CN111090525B (en) Processing method for Redis to achieve high concurrency optimization of distributed lock
CN207319283U (en) A kind of automobile matches system
CN107729460A (en) Data query method and device, storage medium, terminal
CN111985862A (en) Method and apparatus for locating inventory items
CN112148756A (en) Commodity reservation and first-purchase optimization method
CN105976228A (en) Group purchasing system and method based on storage cabinet
CN107657326A (en) A kind of matching system and matching process of On-line matching user and attendant
CN105827873B (en) A kind of solution strange land client traffic handles limited method and device
CN112631612A (en) Optimization method for kubernetes cloud platform configuration based on genetic algorithm
CN108053275A (en) A kind of online product screening method, system and storage medium
US20050120355A1 (en) Updating data in a multi-system network that utilizes asynchronous message transfer
CN106776698A (en) Ticket information method for refreshing and system based on optimization caching
US20050228704A1 (en) Method of distributing leads to a recipient
CN109949129A (en) A kind of order processing system and method for high concurrent
Zhang et al. [Retracted] Multiple‐Devices‐Process Integrated Scheduling Algorithm with Time‐Selective Strategy for Process Sequence

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