Data processing method, device and equipment and computer readable medium
By hashing storage in the database according to the coupon type and using multi-threaded coupon requests, the problem of reduced processing efficiency caused by centralized coupon collection is solved, and more efficient data processing and system stability is achieved.
Patent Information
- Application Number
- CN202411573185.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-06
- Publication Date
- 2025-02-14
AI Technical Summary
The centralized collection of coupons has led to a decrease in overall processing efficiency, the system response time is too long, the throughput is too low, and the system is unstable, affecting customer experience and rights.
By hashing the coupon data according to the coupon type, and then obtaining the competition lock of the storage partition using multiple threads, iterates over and obtains the coupon data in the storage partition, activates the coupon data of the message queue to collect the coupon data. Request until all request processing is completed.
Improves the efficiency of business data processing, avoids accumulation and queueing during single-thread processing, and can realize coupon activation earlier, improving system stability and throughput.
Smart Images

Figure CN119441241A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of big data technology, and in particular to a method, device, equipment and computer-readable medium for processing data. Background Art
[0002] With the rapid development of the Internet, e-commerce has also developed rapidly, and more and more consumers are starting to shop online. Coupons, as a common promotion method, are widely used on e-commerce platforms.
[0003] In order to improve consumer demand, the business needs to effectively promote and stimulate consumption. In the short term, it can activate popular traffic users and in the long term, it can stimulate the market's potential consumer demand.
[0004] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art: the centralized collection of coupons leads to a decrease in the overall processing efficiency. Summary of the invention
[0005] In view of this, embodiments of the present invention provide a method, apparatus, device and computer-readable medium for processing data, which can improve the efficiency of business data processing.
[0006] To achieve the above object, according to one aspect of an embodiment of the present invention, a method for processing data is provided, comprising:
[0007] storing the coupon data in a storage partition of a database by hashing according to the coupon type, and storing the coupon data of multiple coupon types in one storage partition of the database;
[0008] In response to a request for receiving coupon data, the request for receiving coupon data is sent to a message queue, and after using a thread to obtain a contention lock of a storage partition, the thread traverses the coupon data in the storage partition after obtaining the contention lock, and activates coupon data of a preset coupon type in the request for receiving coupon data of the message queue;
[0009] The thread obtains the contention lock of the next storage partition, and activates the coupon data of the preset coupon type in the coupon data request of the message queue in the next storage partition, until the thread activates the coupon data of the preset coupon type in all coupon data requests of the message queue, and the activated coupon data is used to identify the successful receipt of the coupon.
[0010] The storing of coupon data in a storage partition of a database by hash operation according to coupon type, and storing coupon data of multiple coupon types in one storage partition of the database, includes:
[0011] Determine the coupon type of the coupon data according to the coupon type identifier of the coupon data, and obtain the number of storage partitions of the database;
[0012] According to the coupon type and the number of storage partitions of the database, the coupon data is stored in the storage partitions of the database through hash operation, and coupon data of multiple coupon types are stored in one storage partition of the database.
[0013] In response to the coupon data collection request, the coupon data collection request is sent to the message queue, and after the thread obtains the contention lock of the storage partition, the thread traverses the coupon data in the storage partition after obtaining the contention lock, and activates the coupon data of the preset coupon type in the coupon data collection request of the message queue, including:
[0014] In response to a coupon collection data request, the coupon collection data request is sent to a message queue, wherein the coupon collection data request is a request triggered after a coupon collection code is successfully inserted into a user coupon table;
[0015] After starting multithreading, after using the multithreaded threads to obtain the contention lock of the storage partition, the threads traverse the coupon data in the storage partition after obtaining the contention lock, and activate the coupon data of the preset coupon type in the coupon data collection request of the message queue.
[0016] After starting the multithreading, after using the multithreading thread to obtain the contention lock of the storage partition, the thread traverses the coupon data in the storage partition after obtaining the contention lock, including:
[0017] After starting multithreading, threads using the multithreading attempt to acquire the contention lock of the storage partition in sequence according to the identifier of the storage partition, and after failing to acquire the contention lock of one storage partition, attempt to acquire the contention lock of the next storage partition;
[0018] After the multi-threaded thread successfully acquires the contention lock of the storage partition, the thread traverses the coupon data in the storage partition after acquiring the contention lock.
[0019] The thread traverses the coupon data in the storage partition after acquiring the contention lock, and activates the coupon data of the preset coupon type in the coupon data collection request of the message queue, including:
[0020] The thread obtains the coupon data in the storage partition behind the contention lock by cursor traversal according to the activation quantity threshold;
[0021] The coupon data of a preset coupon type in the coupon data collection request of the message queue is activated according to the submitted transaction quantity threshold.
[0022] The thread acquires a contention lock of the next storage partition, and activates the coupon data of the preset coupon type in the coupon data collection request of the message queue in the next storage partition, including:
[0023] After the thread activates the coupon data of the preset coupon type in the coupon data collection request of the message queue, the thread releases the contention lock of the current storage partition and acquires the contention lock of the next storage partition;
[0024] The coupon data of the preset coupon type in the coupon data request of the message queue is activated in the next storage partition, and the next storage partition is the last storage partition of the database. After the coupon data of the preset coupon type in the coupon data request of the message queue is activated in the next storage partition, the thread acquires the contention lock of the first storage partition.
[0025] The method further comprises:
[0026] If unprocessed coupon claiming data requests accumulate, the number of batch job machines and / or the number of threads started by the batch job machines are adjusted to update the number of the multi-threads.
[0027] According to a second aspect of an embodiment of the present invention, there is provided a device for processing data, including:
[0028] A storage module, used to store coupon data in a storage partition of a database by hash operation according to coupon type, and store coupon data of multiple coupon types in one storage partition of the database;
[0029] A first processing module, configured to respond to a request for receiving coupon data, send the request for receiving coupon data to a message queue, use a thread to obtain a contention lock of a storage partition, traverse the coupon data in the storage partition after obtaining the contention lock, and activate coupon data of a preset coupon type in the request for receiving coupon data in the message queue;
[0030] The second processing module is used for the thread to obtain the contention lock of the next storage partition, and activate the coupon data of the preset coupon type in the coupon data request of the message queue in the next storage partition, until the thread activates the coupon data of the preset coupon type in all coupon data requests of the message queue, and the activated coupon data is used to identify the successful receipt of the coupon.
[0031] According to a third aspect of an embodiment of the present invention, there is provided an electronic device for processing data, including:
[0032] one or more processors;
[0033] a storage device for storing one or more programs,
[0034] When the one or more programs are executed by the one or more processors, the one or more processors implement the above method.
[0035] According to a fourth aspect of an embodiment of the present invention, there is provided a computer-readable medium on which a computer program is stored, and when the program is executed by a processor, the method as described above is implemented.
[0036] According to a fifth aspect of an embodiment of the present invention, a computer program product is provided, including a computer program, and when the program is executed by a processor, the method as described above provided by an embodiment of the present invention is implemented.
[0037] One embodiment of the above invention has the following advantages or beneficial effects: storing coupon data in a storage partition of a database by hash operation according to the coupon type, storing coupon data of multiple coupon types in one storage partition of the database; in response to a request for collecting coupon data, sending the request for collecting coupon data to a message queue, using a thread to obtain a contention lock of the storage partition, the thread traverses the coupon data in the storage partition after obtaining the contention lock, and activates the coupon data of the preset coupon type in the request for collecting coupon data of the message queue; the thread obtains the contention lock of the next storage partition, and activates the coupon data of the preset coupon type in the request for collecting coupon data of the message queue in the next storage partition, until the thread activates the coupon data of the preset coupon type in all the requests for collecting coupon data of the message queue, and the activated coupon data is used to identify the successful collection of coupons. Coupon data of multiple coupon types are stored in each storage partition of the database, and the thread can be used to activate coupon data of multiple coupon types in the coupon data request in the same storage partition, thereby improving the efficiency of business data processing.
[0038] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0040] Figure 1 is a schematic diagram of the main flow of a method for processing data according to an embodiment of the present invention;
[0041] Figure 2 is a schematic diagram of a process of storing coupon data in a storage partition of a database according to an embodiment of the present invention;
[0042] Figure 3 is a schematic diagram of a process of traversing coupon data in a storage partition after a thread traverses and acquires a contention lock according to an embodiment of the present invention;
[0043] Figure 4 It is a schematic diagram of a process of acquiring a contention lock of a storage partition by using a multi-threaded thread according to an embodiment of the present invention;
[0044] Figure 5 is a schematic diagram of a process of activating coupon data in a request for receiving coupon data according to an embodiment of the present invention;
[0045] Figure 6 is a schematic diagram of a process of acquiring a contention lock for a next storage partition according to an embodiment of the present invention;
[0046] Figure 7 is a schematic diagram of the main structure of a device for processing data according to an embodiment of the present invention;
[0047] Figure 8 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0048] Fig. 9 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0049] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description. The acquisition, storage, use, and processing of data in the technical solution of this application comply with the relevant provisions of national laws and regulations.
[0050] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.
[0051] By maintaining and issuing coupons, certain rights and interests can be used to stimulate customer retention and promote merchant collection. For coupons with large preferential rights and interests, participating users will continue to collect coupons in a short period of time, causing the system to instantly enter a high-concurrency scenario. The system needs to ensure high data consistency and complete data reading and writing to ensure high availability. This will cause data locks, lock waits, and input and output delays, which will lead to a decrease in the overall processing efficiency of the system, too long response time, low system throughput, and system instability. At the same time, system fluctuations are also likely to affect customer experience and customer rights.
[0052] Method 1: Ensure that the transaction throughput of the front-end is within the carrying capacity through front-end flow control. When the transaction arrives at the back-end, the back-end executes the transaction data one by one according to the database transaction, completes the update and returns the corresponding result.
[0053] However, relying solely on database transactions can ensure serial updates and consistency of data. However, due to the high instantaneous concurrency, high data consistency, and high frequency of hotspot updates when scrambling for coupons, a large number of updates of the same field in the database, such as coupon inventory, are prone to lock waiting, resulting in a decrease in data throughput. For the operation of massive services, it will not be able to meet performance and business requirements, and the system performance loss will be large. In extreme cases, it is easy to cause an avalanche effect, and the user experience will also be greatly affected.
[0054] Method 2: Activate through step-by-step activation. First, during the user's front-end collection stage, the back-end receives the transaction and writes each coupon code, recipient, and collection time into the data table. The data is pre-buried and responds to the user's operation results. At the same time, another back-end thread is started to batch activate user coupons and update the corresponding coupon inventory, realizing the asynchronous activation of coupon closed-loop logic.
[0055] By asynchronously activating user coupons in batches and converting data record locks to cache locks, the database read-write lock problem is alleviated to a certain extent, reducing the pressure on the database. During the asynchronous operation process, the database is regularly written back to update, which also achieves the purpose of improving system performance.
[0056] However, in the single-threaded execution process of asynchronous operations, when the number of coupons collected increases sharply, batch processing is prone to accumulation, which makes the waiting time of the user poor. In order to ensure the serial consistency of data, it can only be executed through a single thread. The risk of abnormality in the thread is high, the monitoring cost and maintenance cost are high, and the scalability is low.
[0057] In summary, the centralized collection of coupons leads to a decrease in overall processing efficiency.
[0058] In order to solve the problem of reduced overall processing efficiency caused by centralized coupon collection, the following technical solutions in the embodiments of the present invention can be adopted.
[0059] See also Figure 1 , Figure 1 1 is a schematic diagram of the main flow of the method for processing data according to an embodiment of the present invention. Each storage partition stores coupon data of multiple coupon types. After acquiring the contention lock of the storage partition through a thread, the coupon data of the preset coupon type in the coupon data collection request is activated. Figure 1 As shown in 100, the following steps are specifically included:
[0060] S101. Store coupon data in a storage partition of a database through hash operation according to coupon type, and store coupon data of multiple coupon types in one storage partition of the database.
[0061] In an embodiment of the present invention, coupon data is stored in a database, and the database has multiple storage partitions. As an example, the database includes 16 storage partitions, and the storage partitions of the database are identified by numbers 1 to 16 respectively. In order to store coupon data of multiple coupon types in each storage partition of the database, the coupon data can be stored in the storage partition of the database by hash operation according to the coupon type. In this way, coupon data of multiple coupon types are stored in one storage partition of the database.
[0062] See also Figure 2 That is 200, Figure 2 This is a flow chart of storing coupon data in a storage partition of a database according to an embodiment of the present invention. Specifically, it includes the following steps:
[0063] S201. Determine the coupon type of the coupon data according to the coupon type identifier of the coupon data, and obtain the number of storage partitions of the database.
[0064] The coupon type of the coupon data is determined according to the coupon type identifier of the coupon data. The coupon data is identified by a coupon code. As an example, a user receives a coupon and generates a unique coupon code for the corresponding user. Different users generate different coupon codes after receiving the coupon; each coupon code is unique. The coupon type is a coupon including different rule attributes. Coupons of different coupon types can be obtained separately by the same user. As an example, user a obtains one coupon of coupon type A and two coupons of coupon type B.
[0065] In order to store the coupon data in the storage partition in the database, the number of the storage partitions of the database is obtained. As an example, the number of the storage partitions of the database is 64.
[0066] S202. Store the coupon data in the storage partitions of the database through hash operations according to the coupon type and the number of storage partitions of the database, and store coupon data of multiple coupon types in one storage partition of the database.
[0067] According to the coupon type and the number of storage partitions of the database, the coupon data is stored in the storage partitions of the database through hash operation. Coupon data of one coupon type is stored in multiple storage partitions. Then, coupon data of multiple coupon types are stored in one storage partition of the database.
[0068] As an example, the coupon types include A, B, C, D, E, F, and G. The storage partitions are numbered from 1 to 64. According to the coupon type and the number of storage partitions of the database, the coupon data is stored in the storage partition of the database through hash operation. In storage partition 1, the types of stored coupons include: A, B, C, D, E, F, and G.
[0069] exist Figure 2 In an embodiment, in each storage partition of the database, coupon data of multiple coupon types are stored, so that coupon data of multiple coupon types can be obtained in one storage partition.
[0070] S102. In response to a request for receiving coupon data, the request for receiving coupon data is sent to a message queue. After the thread acquires a contention lock of a storage partition, the thread traverses the coupon data in the storage partition after acquiring the contention lock, and activates coupon data of a preset coupon type in the request for receiving coupon data of the message queue.
[0071] In an embodiment of the present invention, the user sends a coupon data request to receive the coupon. Specifically, the user sends a coupon data request to receive the coupon and then activates the coupon data to receive the coupon.
[0072] In order to process the coupon data collection request in time, in response to the coupon data collection request, the coupon data collection request is sent to the message queue, and the coupon data collection request in the message queue is processed by the thread. After the thread obtains the contention lock of the storage partition, the thread traverses the coupon data in the storage partition after obtaining the contention lock, and activates the coupon data of the preset coupon type in the coupon data collection request of the message queue.
[0073] See also Figure 3 That is 300, Figure 3 This is a flow chart of traversing coupon data in a storage partition after a thread acquires a contention lock according to an embodiment of the present invention. Specifically, the following steps are included:
[0074] S301. In response to a request for receiving coupon data, the request for receiving coupon data is sent to a message queue. The request for receiving coupon data is a request triggered after the coupon code is successfully inserted into the user coupon table.
[0075] In an embodiment of the present invention, a request to collect coupon data is a request triggered after the coupon code is successfully inserted into the user coupon package table. Specifically, a coupon code is generated when a user collects a coupon. A global variable cache is performed for the number of coupons collected. By comparing the global variable cache with the inventory number, if the global variable cache is less than or equal to the inventory number, the collection is successful. Then, the coupon code is successfully inserted into the user coupon table. As an example, user Zhang San has coupons 001, 002, and 003. The coupons successfully inserted into the user coupon table include 001 and 003, which means that two coupons are collected.
[0076] S302: After starting the multithreading, after using the multithreading thread to obtain the contention lock of the storage partition, the thread traverses the coupon data in the storage partition after obtaining the contention lock, and activates the coupon data of the preset coupon type in the coupon data collection request of the message queue.
[0077] In one embodiment of the present invention, multiple threads are started to process a large number of coupon data collection requests. For each storage partition, the thread needs to obtain a contention lock before activating the coupon data. Specifically, after the multi-threaded thread obtains the contention lock of the storage partition, the thread traverses the coupon data in the storage partition after obtaining the contention lock, and activates the coupon data of the preset coupon type in the coupon data collection request of the message queue.
[0078] In one embodiment of the present invention, the number of multithreads is determined by the number of batch job machines and the number of threads enabled in the batch job machines. As an example, the number of batch job machines is M, the number of threads enabled in the batch job machines, and the number of multithreads is M*N.
[0079] When unprocessed requests for coupon redemption data accumulate, the number of batch job machines and / or the number of threads started in the batch job machines are adjusted to update the number of multi-threads.
[0080] As an example, if the number of unprocessed coupon collection data requests is greater than the accumulation threshold within a preset time period, it is determined that the unprocessed coupon collection data requests are accumulated. In addition, the operation log of the batch job machine can be used to know that the number of multi-threads has been successfully updated.
[0081] See also Figure 4 That is 400, Figure 4 The flowchart of using multi-threaded threads to obtain a contention lock of a storage partition according to an embodiment of the present invention is shown in FIG. The flowchart specifically includes the following steps:
[0082] S401: After starting multithreading, threads in the multithreading attempt to acquire contention locks of storage partitions in sequence according to identifiers of storage partitions. After failing to acquire contention locks of one storage partition, threads attempt to acquire contention locks of the next storage partition.
[0083] In an embodiment of the present invention, after multiple threads are started, each thread can sequentially attempt to obtain the contention lock of the storage partition according to the identifier of the storage partition. The order of attempting the storage partitions can be the order of the numbers of the storage partitions. For example, a thread attempts to obtain the contention lock of storage partition 1, and after the attempt fails, the thread attempts to obtain the contention lock of storage partition 2. This ensures that each storage partition can be accessed by the thread.
[0084] After failing to obtain a competing lock for a storage partition, try to obtain the competing lock for the next storage partition.
[0085] S402: After the multi-threaded thread successfully obtains the contention lock of the storage partition, the thread traverses the coupon data in the storage partition after obtaining the contention lock.
[0086] After the multi-threaded thread successfully obtains the contention lock of the storage partition, the thread that locks the storage partition can traverse the coupon data in the storage partition after obtaining the contention lock. At a point in time, only one thread in a storage partition executes the coupon data request of the message queue.
[0087] exist Figure 4 In an embodiment, threads among the multiple threads sequentially acquire contention locks of storage partitions according to identifiers of the storage partitions to ensure that each storage partition can be accessed by the thread.
[0088] See also Figure 5 That is 500, Figure 5 This is a flow chart of activating coupon data in a request for receiving coupon data according to an embodiment of the present invention. Specifically, it includes the following steps:
[0089] S501. The thread obtains the coupon data in the storage partition behind the contention lock by using a cursor traversal method according to the activation quantity threshold.
[0090] In an embodiment of the present invention, in order to ensure the stability of data processing, the thread uses a cursor traversal method to obtain the coupon data in the storage partition after the contention lock according to the activation quantity threshold. The activation quantity threshold can be preset. That is, the number of coupon data activated by the thread each time is less than the activation quantity threshold.
[0091] In the embodiment of the present invention, in order to finely control the acquisition of coupon data, a cursor traversal method may be used to acquire the coupon data in the storage partition behind the contention lock.
[0092] S502: Activate the coupon data of the preset coupon type in the coupon data collection request of the message queue according to the transaction submission quantity threshold.
[0093] In order to ensure the validity of the activated coupon data and avoid activation failure due to excessive amount of coupon data, coupon data of a preset coupon type in the coupon data collection request of the activation message queue can be activated according to the transaction number threshold. In other words, the number of coupon data of a preset coupon type in the coupon data collection request of the activation message queue is less than or equal to the transaction number threshold. As an example, the transaction number threshold is greater than the activation number threshold.
[0094] exist Figure 5 In the embodiment of the present invention, the activation quantity threshold, cursor traversal and submitted transaction quantity are used to activate the coupon data to ensure the validity of the activated coupon data.
[0095] S103, the thread obtains the contention lock of the next storage partition, and activates the coupon data of the preset coupon type in the coupon data request of the message queue in the next storage partition, until the thread activates the coupon data of the preset coupon type in all coupon data requests of the message queue, and the activated coupon data is used to identify the successful receipt of the coupon.
[0096] In one embodiment of the present invention, after the thread presets the coupon data of the coupon type in the coupon data request of the current storage partition activation message queue, the thread releases the contention lock of the current storage partition. The thread acquires the contention lock of the next storage partition and presets the coupon data of the coupon type in the coupon data request of the coupon queue activation message queue in the next storage partition.
[0097] By analogy, the thread releases the contention lock of the next storage partition, and then activates the coupon data in another storage partition until the thread activates the coupon data of the preset coupon type in all coupon data collection requests in the message queue. The activated coupon data is used to identify the successful collection of the coupon.
[0098] There are multiple threads, each of which loops through different storage partitions and tries to activate coupon data in batches. First, a storage partition is locked with a competition lock, and then the coupon data for the storage partition is activated in batches after the competition lock is acquired. Atomicity is used to ensure that each competition lock is exclusively occupied by only one thread at a time, and the coupon data activation for the current storage partition is completed before entering the acquisition process of the competition lock for the next storage partition.
[0099] See also Figure 6 That is 600, Figure 6 The flowchart of acquiring the contention lock of the next storage partition according to an embodiment of the present invention is shown in FIG. The flowchart specifically includes the following steps:
[0100] S601: After the thread activates the coupon data of the preset coupon type in the coupon data collection request of the message queue, it releases the contention lock of the current storage partition and obtains the contention lock of the next storage partition.
[0101] After the thread activates the coupon data of the preset coupon type in the coupon data request of the message queue, it releases the contention lock of the current storage partition. If there is still coupon data of the preset coupon type in the coupon data request in the message queue that has not been activated, it needs to obtain the contention lock of the next storage partition.
[0102] S602: Activate coupon data of a preset coupon type in a coupon data request of a message queue in a next storage partition. If the next storage partition is the last storage partition in the sorting of the database, then after activating coupon data of a preset coupon type in a coupon data request of a message queue in the next storage partition, the thread acquires a contention lock of the first-sorted storage partition.
[0103] After successfully acquiring the contention lock of the next storage partition, the thread activates the coupon data of the preset coupon type in the coupon data request of the message queue in the next storage partition. If the next storage partition is the last storage partition in the sorting of the database, after activating the coupon data of the preset coupon type in the coupon data request of the message queue in the next storage partition, there are still coupon data of the preset coupon type in the coupon data request in the message queue that have not been activated, and the thread acquires the contention lock of the first storage partition in the sorting. That is, the thread traverses the storage partitions again starting from the first storage partition until the thread activates the coupon data of the preset coupon type in all coupon data requests of the message queue.
[0104] exist Figure 6 In an embodiment of the present invention, after the coupon data is activated in the last storage partition, if there is still unactivated coupon data of the preset coupon type in the coupon data request in the message queue, the storage partitions will be traversed again starting from the first storage partition, thereby ensuring the activation of the coupon data of the preset coupon type in the coupon data request of the message queue.
[0105] In the above-mentioned embodiment of the present invention, the coupon data is stored in the storage partition of the database by hash operation according to the coupon type, and the coupon data of multiple coupon types are stored in one storage partition of the database; in response to the request for receiving coupon data, the request for receiving coupon data is sent to the message queue, and after the thread obtains the contention lock of the storage partition, the thread traverses the coupon data in the storage partition after obtaining the contention lock, and activates the coupon data of the preset coupon type in the request for receiving coupon data of the message queue; the thread obtains the contention lock of the next storage partition, and activates the coupon data of the preset coupon type in the request for receiving coupon data of the message queue in the next storage partition, until the thread activates the coupon data of the preset coupon type in all the requests for receiving coupon data of the message queue, and the activated coupon data is used to identify the successful receipt of the coupon. Coupon data of multiple coupon types are stored in each storage partition of the database, and the thread can be used to activate coupon data of multiple coupon types in the coupon data request in the same storage partition, thereby improving the efficiency of business data processing.
[0106] The coupon type stores coupon data in the storage partition of the database through hash operations, which greatly avoids single-thread "pile-up" and "queueing". Users who obtain multiple coupons can activate coupons as soon as possible.
[0107] See also Figure 7 , Figure 7 is a schematic diagram of the main structure of a device for processing data according to an embodiment of the present invention. The device for processing data can implement a method for processing data, such as Figure 7 As shown in 700, the device for processing data specifically includes:
[0108] Storage module 701, used to store coupon data in a storage partition of a database by hash operation according to coupon type, and store coupon data of multiple coupon types in one storage partition of the database;
[0109] The first processing module 702 is used to respond to the coupon data collection request, send the coupon data collection request to the message queue, use the thread to obtain the contention lock of the storage partition, traverse the coupon data in the storage partition after obtaining the contention lock, and activate the coupon data of the preset coupon type in the coupon data collection request of the message queue;
[0110] The second processing module 703 is used for the thread to obtain the contention lock of the next storage partition, and activate the coupon data of the preset coupon type in the coupon data request of the message queue in the next storage partition, until the thread activates the coupon data of the preset coupon type in all coupon data requests of the message queue, and the activated coupon data is used to identify the successful receipt of the coupon.
[0111] In one embodiment of the present invention, the storage module 701 is specifically configured to determine the coupon type of the coupon data according to the coupon type identifier of the coupon data, and obtain the number of storage partitions of the database;
[0112] According to the coupon type and the number of storage partitions of the database, the coupon data is stored in the storage partitions of the database through hash operation, and coupon data of multiple coupon types are stored in one storage partition of the database.
[0113] In one embodiment of the present invention, the first processing module 702 is specifically configured to respond to a coupon collection data request and send the coupon collection data request to a message queue, wherein the coupon collection data request is a request triggered after a coupon collection code is successfully inserted into a user coupon table;
[0114] After starting multithreading, after using the multithreaded threads to obtain the contention lock of the storage partition, the threads traverse the coupon data in the storage partition after obtaining the contention lock, and activate the coupon data of the preset coupon type in the coupon data collection request of the message queue.
[0115] In one embodiment of the present invention, the first processing module 702 is specifically used to start multi-threading, use the threads of the multi-threading to try to acquire the contention lock of the storage partition in sequence according to the identifier of the storage partition, and after failing to acquire the contention lock of one storage partition, try to acquire the contention lock of the next storage partition;
[0116] After the multi-threaded thread successfully acquires the contention lock of the storage partition, the thread traverses the coupon data in the storage partition after acquiring the contention lock.
[0117] In one embodiment of the present invention, the first processing module 702 is specifically used for the thread to obtain the coupon data in the storage partition behind the contention lock by using a cursor traversal method according to the activation quantity threshold;
[0118] The coupon data of a preset coupon type in the coupon data collection request of the message queue is activated according to the submitted transaction quantity threshold.
[0119] In one embodiment of the present invention, the second processing module 703 is specifically used for releasing the contention lock of the current storage partition and acquiring the contention lock of the next storage partition after the thread activates the coupon data of the preset coupon type in the coupon data collection request of the message queue;
[0120] The coupon data of the preset coupon type in the coupon data request of the message queue is activated in the next storage partition, and the next storage partition is the last storage partition of the database. After the coupon data of the preset coupon type in the coupon data request of the message queue is activated in the next storage partition, the thread acquires the contention lock of the first storage partition.
[0121] In one embodiment of the present invention, the first processing module 702 is specifically used to adjust the number of batch job machines and / or the number of threads started in the batch job machines to update the number of multi-threads when unprocessed coupon collection data requests are accumulated.
[0122] Figure 8 An exemplary system architecture 800 is shown to which the method for processing data or the apparatus for processing data according to the embodiments of the present invention can be applied.
[0123] like Figure 8 As shown, system architecture 800 may include terminal devices 801, 802, 803, a network 804, and a server 805. Network 804 is used to provide a medium for communication links between terminal devices 801, 802, 803 and server 805. Network 804 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0124] Users can use terminal devices 801, 802, and 803 to interact with server 805 through network 804 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 801, 802, and 803, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).
[0125] The terminal devices 801 , 802 , and 803 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0126] The server 805 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 801, 802, and 803. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only an example) to the terminal device.
[0127] It should be noted that the method for processing data provided in the embodiment of the present invention is generally executed by the server 805 , and accordingly, the device for processing data is generally set in the server 805 .
[0128] It should be understood that Figure 8 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to the implementation requirements.
[0129] A computer program product according to an embodiment of the present invention includes a computer program, and when the program is executed by a processor, the method for processing data provided by the embodiment of the present invention is implemented.
[0130] Reference below Fig. 9 , which shows a schematic diagram of the structure of a computer system 900 of a terminal device suitable for implementing an embodiment of the present invention. Fig. 9 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0131] like Fig. 9 As shown, the computer system 900 includes a central processing unit (CPU) 901, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage part 908 into a random access memory (RAM) 903. In the RAM 903, various programs and data required for the operation of the system 900 are also stored. The CPU 901, the ROM 902, and the RAM 903 are connected to each other through a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0132] The following components are connected to the I / O interface 905: an input section 906 including a keyboard, a mouse, etc.; an output section 907 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a LAN card, a modem, etc. The communication section 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to the I / O interface 905 as needed. A removable medium 911, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 910 as needed, so that a computer program read therefrom is installed into the storage section 908 as needed.
[0133] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 909, and / or installed from the removable medium 911. When the computer program is executed by the central processing unit (CPU) 901, the above-mentioned functions defined in the system of the present invention are executed.
[0134] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0135] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0136] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes a storage module, a first processing module, and a second processing module. The names of these modules do not constitute a limitation on the modules themselves in some cases. For example, the storage module may also be described as "specifically used to determine the coupon type of the coupon data according to the coupon type identifier of the coupon data, and obtain the number of storage partitions of the database".
[0137] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes:
[0138] storing the coupon data in a storage partition of a database by hashing according to the coupon type, and storing the coupon data of multiple coupon types in one storage partition of the database;
[0139] In response to a request for receiving coupon data, the request for receiving coupon data is sent to a message queue, and after using a thread to obtain a contention lock of a storage partition, the thread traverses the coupon data in the storage partition after obtaining the contention lock, and activates coupon data of a preset coupon type in the request for receiving coupon data of the message queue;
[0140] The thread obtains the contention lock of the next storage partition, and activates the coupon data of the preset coupon type in the coupon data request of the message queue in the next storage partition, until the thread activates the coupon data of the preset coupon type in all coupon data requests of the message queue, and the activated coupon data is used to identify the successful receipt of the coupon.
[0141] According to the technical solution of the embodiment of the present invention, the coupon data is stored in the storage partition of the database by hash operation according to the coupon type, and the coupon data of multiple coupon types are stored in one storage partition of the database; in response to the request for receiving coupon data, the request for receiving coupon data is sent to the message queue, and after the thread obtains the contention lock of the storage partition, the thread traverses the coupon data in the storage partition after obtaining the contention lock, and activates the coupon data of the preset coupon type in the request for receiving coupon data of the message queue; the thread obtains the contention lock of the next storage partition, and activates the coupon data of the preset coupon type in the request for receiving coupon data of the message queue in the next storage partition, until the thread activates the coupon data of the preset coupon type in all the requests for receiving coupon data of the message queue, and the activated coupon data is used to identify the successful receipt of the coupon. Coupon data of multiple coupon types are stored in each storage partition of the database, and the thread can be used to activate coupon data of multiple coupon types in the coupon data request in the same storage partition, thereby improving the efficiency of business data processing.
[0142] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
[0143] It should be noted that in the technical solution of the present invention, the collection, analysis, use, transmission, storage and other aspects of user personal information involved are in compliance with the provisions of relevant laws and regulations, are used for legal and reasonable purposes, are not shared, leaked or sold outside of these legal uses, and are subject to supervision and management by regulatory authorities. Necessary measures should be taken for user personal information to prevent illegal access to such personal information data, ensure that persons who have access to personal information data comply with the provisions of relevant laws and regulations, and ensure the security of user personal information. Once these user personal information data are no longer needed, the risks should be minimized by limiting or even prohibiting data collection and / or deleting data.
[0144] When applicable, including in certain relevant applications, protect user privacy by de-identifying data, such as by removing specific identifiers (e.g., date of birth, etc.) when applicable, controlling the amount or specificity of data stored (e.g., collecting location data at a city level rather than at a specific address level), controlling how data is stored, and / or other de-identification methods.
Claims
1. A method for processing data, characterized in that: include: storing the coupon data in a storage partition of a database by hashing according to the coupon type, and storing the coupon data of multiple coupon types in one storage partition of the database; In response to a request for receiving coupon data, the request for receiving coupon data is sent to a message queue, and after using a thread to obtain a contention lock of a storage partition, the thread traverses the coupon data in the storage partition after obtaining the contention lock, and activates coupon data of a preset coupon type in the request for receiving coupon data of the message queue; The thread obtains the contention lock of the next storage partition, and activates the coupon data of the preset coupon type in the coupon data request of the message queue in the next storage partition, until the thread activates the coupon data of the preset coupon type in all coupon data requests of the message queue, and the activated coupon data is used to identify the successful receipt of the coupon.
2. The method for processing data according to claim 1, characterized in that: The storing of coupon data in a storage partition of a database by hash operation according to coupon type, and storing coupon data of multiple coupon types in one storage partition of the database, includes: Determine the coupon type of the coupon data according to the coupon type identifier of the coupon data, and obtain the number of storage partitions of the database; According to the coupon type and the number of storage partitions of the database, the coupon data is stored in the storage partitions of the database through hash operation, and coupon data of multiple coupon types are stored in one storage partition of the database.
3. The method for processing data according to claim 1, characterized in that: In response to the coupon data collection request, the coupon data collection request is sent to the message queue, and after the thread obtains the contention lock of the storage partition, the thread traverses the coupon data in the storage partition after obtaining the contention lock, and activates the coupon data of the preset coupon type in the coupon data collection request of the message queue, including: In response to a coupon collection data request, the coupon collection data request is sent to a message queue, wherein the coupon collection data request is a request triggered after a coupon collection code is successfully inserted into a user coupon table; After starting multithreading, after using the multithreaded threads to obtain the contention lock of the storage partition, the threads traverse the coupon data in the storage partition after obtaining the contention lock, and activate the coupon data of the preset coupon type in the coupon data collection request of the message queue.
4. The method for processing data according to claim 3, characterized in that: After starting the multithreading, after using the multithreading thread to obtain the contention lock of the storage partition, the thread traverses the coupon data in the storage partition after obtaining the contention lock, including: After starting multithreading, threads using the multithreading attempt to acquire the contention lock of the storage partition in sequence according to the identifier of the storage partition, and after failing to acquire the contention lock of one storage partition, attempt to acquire the contention lock of the next storage partition; After the multi-threaded thread successfully acquires the contention lock of the storage partition, the thread traverses the coupon data in the storage partition after acquiring the contention lock.
5. The method for processing data according to claim 3, characterized in that: The thread traverses the coupon data in the storage partition after acquiring the contention lock, and activates the coupon data of the preset coupon type in the coupon data collection request of the message queue, including: The thread obtains the coupon data in the storage partition behind the contention lock by cursor traversal according to the activation quantity threshold; The coupon data of a preset coupon type in the coupon data collection request of the message queue is activated according to the submitted transaction quantity threshold.
6. The method for processing data according to claim 1, characterized in that: The thread acquires a contention lock of the next storage partition, and activates the coupon data of the preset coupon type in the coupon data collection request of the message queue in the next storage partition, including: After the thread activates the coupon data of the preset coupon type in the coupon data collection request of the message queue, the thread releases the contention lock of the current storage partition and acquires the contention lock of the next storage partition; The coupon data of the preset coupon type in the coupon data request of the message queue is activated in the next storage partition, and the next storage partition is the last storage partition of the database. After the coupon data of the preset coupon type in the coupon data request of the message queue is activated in the next storage partition, the thread acquires the contention lock of the first storage partition.
7. The method for processing data according to claim 3, characterized in that: The method further comprises: If unprocessed requests for claiming coupon data accumulate, the number of batch job machines and / or the number of threads started by the batch job machines are adjusted to update the number of the multi-threads.
8. A device for processing data, characterized in that: include: A storage module, used to store coupon data in a storage partition of a database by hash operation according to coupon type, and store coupon data of multiple coupon types in one storage partition of the database; A first processing module, configured to respond to a request for receiving coupon data, send the request for receiving coupon data to a message queue, use a thread to obtain a contention lock of a storage partition, traverse the coupon data in the storage partition after obtaining the contention lock, and activate coupon data of a preset coupon type in the request for receiving coupon data in the message queue; The second processing module is used for the thread to obtain the contention lock of the next storage partition, and activate the coupon data of the preset coupon type in the coupon data request of the message queue in the next storage partition, until the thread activates the coupon data of the preset coupon type in all coupon data requests of the message queue, and the activated coupon data is used to identify the successful receipt of the coupon.
9. An electronic device for processing data, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.
10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.