Method and system for improving throughput rate of lottery drawing function

By creating and asynchronously updating the evenly distributed prize list in the Redis cache database, the waiting problem of a large number of users participating in the lottery is solved, the throughput of the lottery function is improved, the lottery process is simplified, and the user waiting time is reduced.

CN119205207APending Publication Date: 2024-12-27SHANDONG INSPUR DIGITAL BUSINESS TECHNOLOGY CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411179829.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-27
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

When a large number of users participate in the lottery at the same time, the prior art uses the database transactions and write locks to increase users' waiting, reduce throughput, and untimely data updates may lead to incorrect calculation of the winning probability.

Method used

By creating and asynchronously updating a uniformly distributed prize list in the Redis cache database, users directly draw prizes from the list when participating in the lottery, and asynchronously update the prize list and record table, reducing dependence on write locks and waiting time.

Benefits of technology

The lottery process is simplified, the user's waiting time is reduced, and the throughput of the lottery function is improved. The test results show that the time consumption is reduced by 35% and the throughput rate is increased by 35%.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119205207A_ABST
    Figure CN119205207A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of software engineering, in particular to a method and system for improving the throughput rate of a lottery drawing function. The method for improving the throughput rate of the lottery drawing function comprises the following steps: configuring a lottery drawing activity, and setting a list length and an empty prize quantity according to a winning probability, a total prize quantity, a prize type and a quantity of various prizes customized by a user; creating a prize list, taking the identity identification number ID of a prize as a list element, and defining the identity identification number ID of an empty prize as 0; disorganizing an element sequence in the prize list to obtain a prize list in which various prizes and empty prizes are uniformly distributed, and storing the prize list into a Redis cache database; and when the user participates in lottery drawing, directly extracting a value from the prize list of the Redis cache database, inserting the extracted value into the lottery drawing record table, and ending the process. According to the method and system for improving the throughput rate of the lottery drawing function, the lottery drawing process is simplified, the lottery drawing waiting time of the user is shortened, and the throughput rate of the lottery drawing function is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software engineering, and in particular to a method and system for improving the throughput rate of a lottery function. Background Art

[0002] Lottery is a common activity. When users participate in the lottery, they randomly get a prize from the prize pool. Take a simple lottery activity as an example. The administrator configures the winning rate of the lottery and the number of prizes. When users participate in the lottery, if the winning rate of the current lottery has reached the configured winning rate, the user will get an empty prize; otherwise, they will randomly get a prize or an empty prize. To implement this function, three tables are needed to save data, namely the lottery table, the prize table, and the lottery record table. Among them, the lottery table and the prize table are used to configure the lottery activity, and the lottery record table is used to record the user's lottery record.

[0003] The lucky draw table manages the lucky draw activity ID (identity identification number), the probability of winning, the number of lucky draw participations and the number of prizes drawn. The prize table manages the prize ID (identity identification number), the lucky draw activity ID (identity identification number), the number of prizes and the number of prizes drawn. The prize record table manages the transaction ID (identity identification number), the lucky draw activity ID (identity identification number), the prize ID (identity identification number), the member ID (identity identification number) and the participation time.

[0004] When a user participates in a lottery, the current actual winning rate (i.e. the number of prizes drawn / number of lottery participations) is generally calculated first, and then compared with the winning probability:

[0005] If it is greater than or equal to the probability of winning, then give a blank prize;

[0006] If it is less than the winning probability, the prizes whose number of prizes drawn is less than the number of prizes will be queried, and one of these prizes and the empty prize will be randomly selected and given to the user based on the remaining number of prizes and the winning probability; the prize probability is the probability of winning the prize, where the more prizes remaining, the greater the probability of being drawn.

[0007] Then, update the data: the number of lottery participations in the lottery table + 1, if you win, the number of prizes drawn + 1, the number of lottery prizes corresponding to the prize + 1, and insert the lottery record.

[0008] If one user participates in the lottery, the above process can be executed correctly. However, when a large number of users participate together, if one user wins the prize but has not updated the data in time, the current winning rate calculated by another user will be lower than the actual winning rate. The user who was supposed to win the prize can draw from the prize pool, and then the actual winning probability will be higher than the set winning probability.

[0009] To avoid this situation, the existing technology uses database transactions and write locks to force all users to queue up to participate in the lottery. The process is as follows: Figure 1 shown.

[0010] When a user participates in the lottery, the number of participations is increased by 1, the program starts a transaction, and a write lock is added to this record in the lottery table. Before the write lock is released, other users can only wait to participate in the lottery. After the lottery process of the current user is over, the write lock is released. After the transaction is submitted, a waiting user is selected to grab the write lock and start the lottery process. If an error occurs in the lottery process, all data updates will be rolled back to ensure the correctness of the data.

[0011] Although the above solution correctly implements the lottery, a single request holds the write lock for a long time. When a large number of users participate in the lottery, a large number of users will be waiting.

[0012] In order to reduce user waiting and improve the throughput of the function, the present invention proposes a method and system for improving the throughput of the lottery function. Summary of the invention

[0013] In order to make up for the defects of the prior art, the present invention provides a simple and efficient method and system for improving the throughput rate of a lottery function.

[0014] The present invention is achieved through the following technical solutions:

[0015] A method for improving the throughput rate of a lottery function, characterized in that it comprises the following steps:

[0016] Step S1: Configure the lottery event and create a prize list;

[0017] Step S1.1: Set the list length and the number of empty prizes according to the user-defined winning probability, total number of prizes, prize types, and number of each type of prize;

[0018] The list length is the ratio between the total number of prizes and the probability of winning, and the number of airdrops is the difference between the list length and the total number of prizes;

[0019] Step S1.2: Create an empty list as the prize list, and use the prize identification number ID as the list element. The empty prize identification number ID is defined as 0;

[0020] Step S1.3: loop through all kinds of prizes, insert n prize identification numbers and m zeros into the prize list, where n is the number of prizes of the corresponding kind, and m is the number of empty prizes;

[0021] Step S1.4: shuffle the order of elements in the prize list to obtain a prize list with even distribution of various prizes and empty prizes;

[0022] Step S1.5: storing the prize list with the elements in a shuffled order into the Redis cache database;

[0023] In step S1.4, according to the length of the prize list, several unit lists are created to ensure that the prizes are evenly distributed, and the number of each type of prize is proportionally allocated in each unit list;

[0024] In the unit list, the number of prizes is the product of the unit list length and the probability of winning, and the number of empty prizes is the difference between the unit list length and the total number of prizes;

[0025] If the calculated number of empty prizes and the number of prizes are decimals, round down to the integer;

[0026] Take the modulus of the length of the prize list and the length of the unit list to get the remaining tail list, where the length of the tail list is less than the length of the unit list; insert all the remaining prizes into the tail list, and fill the empty spaces with empty prizes;

[0027] Finally, shuffle the order of elements in all unit lists and tail lists and combine them into a large list to get a uniformly distributed prize list.

[0028] Step S2: When a user participates in a lottery, the prize list is updated asynchronously;

[0029] Step S2.1: When the user starts the lottery, a value is directly extracted from the prize list in the Redis cache database. The extracted value is the identity ID of the prize;

[0030] Step S2.2: Insert the extracted value into the lottery record table, and the process ends.

[0031] In step S2.2, the number of prizes drawn in the prize list, as well as the number of lottery participations and the number of prizes drawn in the lottery record table are asynchronously updated, and the inventory of prizes is controlled by the list of the Redis cache database.

[0032] A system for improving the throughput rate of a lottery function, comprising: a lottery activity configuration module and an asynchronous management module;

[0033] The lottery configuration module is responsible for configuring the list length and the number of empty prizes according to the user-defined winning probability, total number of prizes, prize types, and number of each type of prize; creating an empty list as the prize list, and taking the prize's identity ID as the list element, and defining the empty prize's identity ID as 0; looping through various prizes, inserting n prizes' identity IDs and m 0s into the prize list, where n is the number of prizes of the corresponding type, and m is the number of empty prizes; shuffling the order of elements in the prize list to obtain a prize list with even distribution of various prizes and empty prizes; and storing the shuffled element list in the Redis cache database;

[0034] The list length is the ratio between the total number of prizes and the probability of winning, and the number of airdrops is the difference between the list length and the total number of prizes;

[0035] The asynchronous management module is responsible for asynchronously updating the prize list when a user participates in a lottery.

[0036] When the lottery configuration module disrupts the order of elements in the prize list, it creates several unit lists according to the length of the prize list to ensure that the prizes are evenly distributed, and distributes the number of each type of prize in each unit list in proportion;

[0037] In the unit list, the number of prizes is the product of the unit list length and the probability of winning, and the number of empty prizes is the difference between the unit list length and the total number of prizes;

[0038] If the calculated number of empty prizes and the number of prizes are decimals, round down to the integer;

[0039] Take the modulus of the length of the prize list and the length of the unit list to get the remaining tail list, where the length of the tail list is less than the length of the unit list; insert all the remaining prizes into the tail list, and fill the empty spaces with empty prizes;

[0040] Finally, shuffle the order of elements in all unit lists and tail lists and combine them into a large list to get a uniformly distributed prize list.

[0041] When the user starts the lottery, the asynchronous management module directly extracts a value from the prize list in the Redis cache database, and the extracted value is the identity identification number ID of the prize; then, the extracted value is inserted into the lottery record table, and the number of prizes drawn in the prize list, as well as the number of lottery participations and the number of prizes drawn in the lottery record table are asynchronously updated. The inventory of prizes is controlled by the list in the Redis cache database.

[0042] A device for improving the throughput rate of a lottery function, characterized in that it comprises a memory and a processor; the memory is used to store a computer program, and the processor is used to implement the method steps described above when executing the computer program.

[0043] A readable storage medium, characterized in that: a computer program is stored on the readable storage medium, and when the computer program is executed by a processor, the method steps described above are implemented.

[0044] The beneficial effects of the present invention are as follows: the method and system for improving the throughput rate of a lottery function simplifies the lottery process, reduces the waiting time for users to draw a lottery, and improves the throughput rate of the lottery function. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0046] Attached Figure 1 The diagram is a schematic diagram of a lottery method implemented by using database transactions and write locks in the prior art.

[0047] Attached Figure 2 Schematic diagram of the prize list creation and configuration method of the present invention.

[0048] Attached Figure 3 The figure is a schematic diagram of the user lottery process of the present invention. DETAILED DESCRIPTION

[0049] In order to enable those skilled in the art to better understand the technical solutions in the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0050] Redis cache database is a key-value storage system, commonly used for high-speed caching. List is a data structure supported by Redis cache database. List operation instruction LPOP is used to read the leftmost element of the list. After Redis cache database reads the list operation instruction LPOP, the corresponding element will be deleted. And the list operation instruction LPOP is atomic, and there will be no situation where multiple requests read the same element.

[0051] In order to verify the performance of the list operation instruction LPOP, a test machine with 16G memory and E5-2640 v4@2.40GHz CPU was used to deploy the Redis cache database and build a test environment for verification. The test found that the list operation instruction LPOP can be executed more than 30,000 times per second.

[0052] The performance of reading elements from the list in the Redis cache database is very high, so the list in the Redis cache database can be a way to optimize the lottery function.

[0053] The method for improving the throughput rate of the lottery function comprises the following steps:

[0054] Step S1: Configure the lottery event and create a prize list (such as the attached Figure 2 shown);

[0055] Step S1.1: Set the list length and the number of empty prizes according to the user-defined winning probability, total number of prizes, prize types, and number of each type of prize;

[0056] The list length is the ratio between the total number of prizes and the probability of winning, and the number of airdrops is the difference between the list length and the total number of prizes;

[0057] Step S1.2: Create an empty list as the prize list, and use the prize identification number ID as the list element. The empty prize identification number ID is defined as 0;

[0058] Step S1.3: loop through all kinds of prizes, insert n prize identification numbers and m zeros into the prize list, where n is the number of prizes of the corresponding kind, and m is the number of empty prizes;

[0059] Step S1.4: shuffle the order of elements in the prize list to obtain a prize list with even distribution of various prizes and empty prizes;

[0060] Step S1.5: storing the prize list with the elements in a shuffled order into the Redis cache database;

[0061] In step S1.4, according to the length of the prize list, several unit lists are created to ensure that the prizes are evenly distributed, and the number of each type of prize is proportionally allocated in each unit list;

[0062] In the unit list, the number of prizes is the product of the unit list length and the probability of winning, and the number of empty prizes is the difference between the unit list length and the total number of prizes;

[0063] If the calculated number of empty prizes and the number of prizes are decimals, round down to the integer;

[0064] Take the modulus of the length of the prize list and the length of the unit list to get the remaining tail list, where the length of the tail list is less than the length of the unit list; insert all the remaining prizes into the tail list, and fill the empty spaces with empty prizes;

[0065] Finally, shuffle the order of elements in all unit lists and tail lists and combine them into a large list to get a uniformly distributed prize list.

[0066] For example, the prize list length is 136800, the probability of winning is 6.5% (total number of prizes = 136800*6.5% = 8892), 136 unit lists are created, the length of each unit list is 1000, the number of prizes = 1000*6.5% = 65, the number of empty prizes = 1000*(1-6.5%) = 935, the number of prizes of a certain type = 1000*6.5%*the number of prizes of this type / the total number of prizes. The length of the prize list is modulo the length of the unit list to obtain the remaining tail list, the length of which is 800; the remaining prizes (8892-65*136=52) are all inserted into the tail list, and the empty positions (800-52=748) are filled with empty prizes.

[0067] Finally, the elements in the 136 unit lists and the tail list of length 800 are randomly sorted respectively so that the identity identification numbers ID of the prizes are evenly distributed in the lists, and then formed into a large list to obtain a uniformly distributed prize list.

[0068] Step S2: When a user participates in a lottery, the prize list is updated asynchronously (such as the attached Figure 3 shown);

[0069] Step S2.1: When the user starts the lottery, a value is directly extracted from the prize list in the Redis cache database. The extracted value is the identity ID of the prize;

[0070] Step S2.2: Insert the extracted value into the lottery record table, and the process ends. In the main process, there is only one insertion operation on the Redis cache database, and the interface takes a short time.

[0071] In step S2.2, the number of prizes drawn in the prize list, as well as the number of lottery participations and the number of prizes drawn in the lottery record table are asynchronously updated, and the inventory of prizes is controlled by the list of the Redis cache database.

[0072] The test machine and office computer are still used as the test environment, and the Redis cache database and MySQL database are deployed on the test machine. 200 threads are started on the office computer to execute the lottery program simultaneously, and the time taken for 3000 draws is calculated.

[0073] The test found that the existing algorithm took 347 seconds, while the method of improving the throughput of the lottery function took 223 seconds, which is 35% less time than the original, and the throughput was increased from 8.6 / s to 13.4 / s.

[0074] The system for improving the throughput rate of lottery function includes: a lottery activity configuration module and an asynchronous management module;

[0075] The lottery configuration module is responsible for configuring the list length and the number of empty prizes according to the user-defined winning probability, total number of prizes, prize types, and number of each type of prize; creating an empty list as the prize list, and taking the prize's identity ID as the list element, and defining the empty prize's identity ID as 0; looping through various prizes, inserting n prizes' identity IDs and m 0s into the prize list, where n is the number of prizes of the corresponding type, and m is the number of empty prizes; shuffling the order of elements in the prize list to obtain a prize list with even distribution of various prizes and empty prizes; and storing the shuffled element list in the Redis cache database;

[0076] The list length is the ratio between the total number of prizes and the probability of winning, and the number of airdrops is the difference between the list length and the total number of prizes;

[0077] The asynchronous management module is responsible for asynchronously updating the prize list when a user participates in a lottery.

[0078] When the lottery configuration module disrupts the order of elements in the prize list, it creates several unit lists according to the length of the prize list to ensure that the prizes are evenly distributed, and distributes the number of each type of prize in each unit list in proportion;

[0079] In the unit list, the number of prizes is the product of the unit list length and the probability of winning, and the number of empty prizes is the difference between the unit list length and the total number of prizes;

[0080] If the calculated number of empty prizes and the number of prizes are decimals, round down to the integer;

[0081] Take the modulus of the length of the prize list and the length of the unit list to get the remaining tail list, where the length of the tail list is less than the length of the unit list; insert all the remaining prizes into the tail list, and fill the empty spaces with empty prizes;

[0082] Finally, shuffle the order of elements in all unit lists and tail lists and combine them into a large list to get a uniformly distributed prize list.

[0083] When the user starts the lottery, the asynchronous management module directly extracts a value from the prize list in the Redis cache database, and the extracted value is the identity identification number ID of the prize; then, the extracted value is inserted into the lottery record table, and the number of prizes drawn in the prize list, as well as the number of lottery participations and the number of prizes drawn in the lottery record table are asynchronously updated. The inventory of prizes is controlled by the list in the Redis cache database.

[0084] The device for improving the throughput rate of a lottery function comprises a memory and a processor; the memory is used to store a computer program, and the processor is used to implement the above-mentioned method steps when executing the computer program.

[0085] The readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described above are implemented.

[0086] The embodiment described above is only one specific implementation of the present invention. Common changes and substitutions made by those skilled in the art within the scope of the technical solution of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for improving the throughput rate of a lottery function, characterized in that: The following steps are involved: Step S1: Configure the lottery event and create a prize list; Step S1.1: Set the list length and the number of empty prizes according to the user-defined winning probability, total number of prizes, prize types, and number of each type of prize; The list length is the ratio between the total number of prizes and the probability of winning, and the number of airdrops is the difference between the list length and the total number of prizes; Step S1.2: Create an empty list as the prize list, and use the prize identification number ID as the list element. The empty prize identification number ID is defined as 0; Step S1.3: loop through all kinds of prizes, insert n prize identification numbers and m zeros into the prize list, where n is the number of prizes of the corresponding kind, and m is the number of empty prizes; Step S1.4: shuffle the order of elements in the prize list to obtain a prize list with even distribution of various prizes and empty prizes; Step S1.5: storing the prize list with the elements in a shuffled order into the Redis cache database; Step S2: When a user participates in a lottery, the prize list is updated asynchronously; Step S2.1: When the user starts the lottery, a value is directly extracted from the prize list in the Redis cache database. The extracted value is the identity ID of the prize; Step S2.2: Insert the extracted value into the lottery record table, and the process ends.

2. The method for improving the throughput rate of a lottery function according to claim 1, characterized in that: In step S1.4, according to the length of the prize list, several unit lists are created to ensure that the prizes are evenly distributed, and the number of each type of prize is proportionally allocated in each unit list; In the unit list, the number of prizes is the product of the unit list length and the probability of winning, and the number of empty prizes is the difference between the unit list length and the total number of prizes; If the calculated number of empty prizes and the number of prizes are decimals, round down to the integer; Take the modulus of the length of the prize list and the length of the unit list to get the remaining tail list, where the length of the tail list is less than the length of the unit list; insert all the remaining prizes into the tail list, and fill the empty spaces with empty prizes; Finally, shuffle the order of elements in all unit lists and tail lists and combine them into a large list to get a uniformly distributed prize list.

3. The method for improving the throughput rate of a lottery function according to claim 1, characterized in that: In step S2.2, the number of prizes drawn in the prize list, as well as the number of lottery participations and the number of prizes drawn in the lottery record table are asynchronously updated, and the inventory of prizes is controlled by the list of the Redis cache database.

4. A system for improving the throughput rate of a lottery function, characterized in that: Includes lottery configuration module and asynchronous management module; The lottery configuration module is responsible for configuring the list length and the number of empty prizes according to the user-defined winning probability, total number of prizes, prize types, and number of each type of prize; creating an empty list as the prize list, and taking the prize's identity ID as the list element, and defining the empty prize's identity ID as 0; looping through various prizes, inserting n prizes' identity IDs and m 0s into the prize list, where n is the number of prizes of the corresponding type, and m is the number of empty prizes; shuffling the order of elements in the prize list to obtain a prize list with even distribution of various prizes and empty prizes; and storing the shuffled element list in the Redis cache database; The list length is the ratio between the total number of prizes and the probability of winning, and the number of airdrops is the difference between the list length and the total number of prizes; The asynchronous management module is responsible for asynchronously updating the prize list when a user participates in a lottery.

5. The system for improving the throughput rate of lottery function according to claim 4, characterized in that: When the lottery configuration module disrupts the order of elements in the prize list, it creates several unit lists according to the length of the prize list to ensure that the prizes are evenly distributed, and distributes the number of each type of prize in each unit list in proportion; In the unit list, the number of prizes is the product of the unit list length and the probability of winning, and the number of empty prizes is the difference between the unit list length and the total number of prizes; If the calculated number of empty prizes and the number of prizes are decimals, round down to the integer; Take the modulus of the length of the prize list and the length of the unit list to get the remaining tail list, where the length of the tail list is less than the length of the unit list; insert all the remaining prizes into the tail list, and fill the empty spaces with empty prizes; Finally, shuffle the order of elements in all unit lists and tail lists and combine them into a large list to get a uniformly distributed prize list.

6. The system for improving the throughput rate of lottery function according to claim 4, characterized in that: When the user starts the lottery, the asynchronous management module directly extracts a value from the prize list in the Redis cache database, and the extracted value is the identity identification number ID of the prize; then, the extracted value is inserted into the lottery record table, and the number of prizes drawn in the prize list, as well as the number of lottery participations and the number of prizes drawn in the lottery record table are asynchronously updated. The inventory of prizes is controlled by the list in the Redis cache database.

7. A device for improving the throughput rate of a lottery function, characterized in that: The method comprises a memory and a processor; the memory is used to store a computer program, and the processor is used to implement the method according to any one of claims 1 to 3 when executing the computer program.

8. A readable storage medium, characterized in that: The readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 3 is implemented.

Citation Information

Cited By

  • Lottery drawing method and device, electronic equipment and storage medium

    CN119991202A