Method, device and electronic device for solving payment hotspot account problem
Through concurrent processing of thread pools and dynamically adjusting the number of threads, the accounting timeout problem caused by hot accounts in the payment system is solved, and the success rate and consistency of accounting processing are improved.
Patent Information
- Application Number
- CN202111638738.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-29
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2041-12-29
AI Technical Summary
In the payment system, when multiple concurrent threads perform accounting operations on the same account, only one thread can hold an exclusive lock, and other threads must wait for the lock to be released, resulting in frequent locking and unlocking of the account, becoming a hot account, causing the accounting operation to time out, affecting accounting consistency and database performance.
The pending payment packets are obtained through the main thread, the task object is generated and processed concurrently by multiple threads in the thread pool, the accounting operation results are monitored in real time, the timeout indicators are counted according to the time segment, the number of concurrent threads in the thread pool is adjusted according to the comprehensive timeout indicators, and the number of concurrent processing for the same account is reduced.
It effectively reduces the pressure on the database, improves the success rate of accounting processing, avoids hot account problems, and ensures the timeliness and consistency of accounting processing.
Smart Images

Figure CN114283007B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data analysis technology, and in particular to a method and device for solving payment hotspot account problems, and an electronic device. Background Art
[0002] In recent years, with economic growth and the improvement of payment infrastructure, payment volume has rapidly increased. To meet high throughput and timeliness requirements, payment systems must process multiple payment transactions concurrently. Each payment transaction involves transferring funds from or to an account, which involves a bookkeeping process. During bookkeeping, to ensure accounting consistency, the system first applies an exclusive lock to the account's resources and releases the lock after the bookkeeping process is complete. However, at any given moment, multiple concurrent transactions may be performing bookkeeping operations on the same account. In this case, only one of the corresponding concurrent threads can hold the resource lock for the current account. The other threads must wait for the lock to be released before performing bookkeeping operations one by one. This leads to frequent locking and unlocking of the account, making it a hotspot account. This can cause bookkeeping operations to timeout for multiple transactions, disrupting accounting consistency and severely impacting database performance. Summary of the Invention
[0003] The purpose of this application is to provide a method, device, and electronic device for solving the problem of payment hotspot accounts. This method is used to solve the problem that multiple concurrent thread processing instructions may perform accounting operations on the same account. In this case, only one thread among all corresponding concurrent threads can hold the exclusive lock of the current account. The other threads must wait for the lock to be released before performing accounting operations one by one. In this way, the account will be frequently locked and released, becoming a hotspot account, causing the system accounting operation to time out.
[0004] In a first aspect, an embodiment of the present application provides a method for solving the problem of payment hotspot accounts, the method comprising:
[0005] In response to the message capture instruction, the payment message to be processed is obtained through the main thread;
[0006] Generate a task object including an accounting operation according to the payment message to be processed, and concurrently process the currently unprocessed task objects through multiple threads in a thread pool;
[0007] Determine the result of the accounting operation during the processing of the task object, and count the timeout indicators corresponding to each time segment according to the preset time segments, wherein the accounting operation result includes whether the accounting operation is completed within the preset time threshold;
[0008] In response to the thread quantity adjustment instruction, obtaining timeout indicators of a plurality of time segments adjacent to the current time, and performing weighted processing on the obtained timeout indicators to determine a comprehensive timeout indicator;
[0009] The number of concurrent threads in the thread pool is adjusted according to the comprehensive timeout indicator.
[0010] In some possible embodiments, after determining the result of the accounting operation in the process of processing the task object, the method further includes:
[0011] After determining that the accounting operation in any thread processing the current task object has timed out, initiate a reversal process for the timed-out accounting operation. After the reversal is successful, mark the payment message corresponding to the timed-out accounting operation with a special status;
[0012] The designated thread periodically obtains the payment message in the special status and re-processes the payment message including initiating the accounting operation in a serial processing manner.
[0013] In some possible embodiments, after generating a task object including an accounting operation according to the payment message to be processed, the method further includes:
[0014] When it is determined that the number of task objects in the task queue does not exceed the set value and there are task objects that have not been put into the task queue, the task objects that have not been put into the task queue are put into the task queue in sequence until the set number is reached;
[0015] If the number of task objects in the task queue exceeds the set value, the task objects not in the queue will be destroyed, and the payment messages corresponding to the task objects will be retrieved;
[0016] Determine whether there is an idle thread in the thread pool, obtain a task object from the task queue and hand it over to the idle thread for processing, and remove the obtained task object from the task queue.
[0017] In some possible embodiments, determining the accounting operation results during the processing of the task object and calculating the timeout indicators corresponding to the preset time segments respectively include:
[0018] In response to the time slice object initialization instruction, a preset number of time slice objects in the memory are initialized, where the time slice objects are numbered and correspond to the time slices of natural time in a cyclic manner, and multiple time slice objects to be used are batch initialized at fixed intervals;
[0019] Obtain timeout indicators for multiple time segments immediately before the current time, and perform weighted processing on the obtained timeout indicators to determine a comprehensive timeout indicator, including:
[0020] Calculate the position of the time segment object corresponding to the current time in memory according to the current time, obtain several time segment objects before the time segment object, calculate the timeout index of the time segment object, and perform weighted processing on the timeout index to determine the comprehensive timeout index.
[0021] In some possible embodiments, counting the timeout indicators corresponding to each time segment according to the preset time segments includes:
[0022] Count the total number of accounting operations in each time segment according to the preset time segment;
[0023] Count the number of accounting operation timeouts in each time segment according to the preset time segments;
[0024] The timeout rate corresponding to each time segment is obtained based on the ratio of the number of accounting operation timeouts corresponding to each time segment to the total number of accounting operations.
[0025] In some possible embodiments, obtaining timeout indicators of multiple time segments adjacent to the current time and weighting the obtained timeout indicators to determine a comprehensive timeout indicator may include:
[0026] Obtain the timeout indicators of multiple time segments adjacent to the current time, and determine the weight of each time segment based on the principle that the closer the time is to the current time, the greater the corresponding weight;
[0027] The obtained timeout indicators are weighted according to the determined weights to determine a comprehensive timeout indicator.
[0028] In some possible embodiments, adjusting the number of concurrent threads in the thread pool according to the comprehensive timeout indicator includes:
[0029] Determining the expected number of concurrent threads of the thread pool according to the comprehensive timeout indicator, wherein the expected number of concurrent threads is an integer greater than 1, and the higher the timeout degree corresponding to the comprehensive timeout indicator, the smaller the corresponding expected number of concurrent threads;
[0030] Determine that the number of concurrent threads in the current thread pool exceeds the expected number of concurrent threads, and destroy the corresponding thread after the thread completes processing the current task object until the number of concurrent threads in the thread pool reaches the expected number of concurrent threads;
[0031] Determine that the number of concurrent threads in the current thread pool is less than the expected number of concurrent threads, and create a new thread until the number of concurrent threads in the thread pool reaches the expected number of concurrent threads.
[0032] In some possible embodiments, the comprehensive timeout index is a comprehensive timeout rate obtained by weighting the timeout rates of multiple time segments, and determining the expected number of concurrent threads of the concurrent threads based on the comprehensive timeout index includes:
[0033] Expected number of concurrent threads = max{Floor(preset normal value*(1-comprehensive timeout rate)),1}.
[0034] In a second aspect, an embodiment of the present application provides a device for solving the problem of payment hotspot accounts, the device comprising:
[0035] An acquisition module, configured to respond to a message capture instruction and acquire a payment message to be processed through a main thread;
[0036] a processing module, configured to generate a task object including an accounting operation according to the payment message to be processed, and concurrently process currently unprocessed task objects through multiple threads in a thread pool;
[0037] A statistics module is used to determine the results of accounting operations during the processing of task objects, and to count the timeout indicators corresponding to each time segment according to preset time segments, wherein the accounting operation results include whether the accounting operation is completed within a preset time threshold;
[0038] A weighting module is used to obtain timeout indicators of multiple time segments adjacent to the current time in response to the thread quantity adjustment instruction, and perform weighted processing on the obtained timeout indicators to determine a comprehensive timeout indicator;
[0039] The adjustment module is used to adjust the number of concurrent threads in the thread pool according to the comprehensive timeout indicator.
[0040] In a third aspect, an embodiment of the present application provides an electronic device comprising at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method for solving the payment hotspot account problem provided in the first aspect above.
[0041] In a fourth aspect, an embodiment of the present application provides a computer program product, comprising computer program instructions, which, when executed by a processor, implement the method described in the first aspect of the claim.
[0042] In a fifth aspect, an embodiment of the present application provides a computer storage medium, wherein the computer storage medium stores a computer program, and the computer program is used to enable a computer to execute the method provided in the first aspect above.
[0043] In an embodiment of the present application, in order to solve the problem that multiple concurrent thread processing instructions may perform accounting operations on the same account, at this time, only one thread among all corresponding concurrent threads can hold the exclusive lock of the current account, and the other threads must wait for the lock to be released before performing accounting processing one by one. In this way, the account will be frequently locked and released, becoming a hot account, resulting in the problem of system accounting operation timeout. In order to avoid the stacking backlog of messages processed by concurrent threads in the database, the embodiment of the present application reduces the number of concurrent threads. This can effectively reduce the number of processed messages entering the database, reduce the pressure on the database, and improve the success rate of accounting processing.
[0044] Other features and advantages of the present application will be described in the following description, and in part will become apparent from the description, or will be understood by practicing the present application. The purposes and other advantages of the present application can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. Obviously, the drawings introduced below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0046] Figure 1 A flowchart of a method for solving a payment hotspot account problem according to one embodiment of the present application is shown;
[0047] Figure 2 A schematic diagram of a HashMap of time segment objects of a method for solving a payment hotspot account problem according to an embodiment of the present application;
[0048] Figure 3 A schematic diagram of a fallback thread processing method for solving a payment hotspot account problem according to an embodiment of the present application;
[0049] Figure 4 A schematic diagram of concurrent thread processing of a method for solving a payment hotspot account problem according to one embodiment of the present application;
[0050] Figure 5 A schematic diagram of the structure of a device for solving the payment hotspot account problem according to one embodiment of the present application;
[0051] Figure 6 The figure is a schematic diagram of the structure of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0052] The following will clearly and thoroughly describe the technical solutions in the embodiments of the present application in conjunction with the accompanying drawings. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in the text is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.
[0053] In the description of the embodiments of the present application, unless otherwise specified, the term "multiple" refers to two or more, and other quantifiers should be understood similarly. The preferred embodiments described herein are only used to illustrate and explain the present application and are not used to limit the present application. In addition, the embodiments of the present application and the features in the embodiments may be combined with each other if there is no conflict.
[0054] To further illustrate the technical solutions provided by the embodiments of the present application, this is described in detail below in conjunction with the accompanying drawings and specific implementation methods. Although the embodiments of the present application provide the method operation steps as shown in the following embodiments or drawings, more or fewer operation steps may be included in the method based on routine or no creative labor. In the steps where there is no necessary causal relationship logically, the execution order of these steps is not limited to the execution order provided by the embodiments of the present application. In the actual processing process or when the control device is executed, the method can be executed in the order of the methods shown in the embodiments or drawings or in parallel. The acquisition, storage, use, processing, etc. of data in the technical solution of this application comply with the relevant provisions of national laws and regulations.
[0055] Given that multiple concurrent thread-processed instructions in related technologies may perform accounting operations on the same account, only one thread among all corresponding concurrent threads can hold the exclusive lock of the current account. The other threads must wait for the lock to be released before performing accounting operations one by one. As a result, the account will be frequently locked and released, becoming a hot account, resulting in a large number of transaction accounting blockages and timeouts, seriously affecting accounting consistency. This application proposes a method, device, and electronic device for solving the problem of payment hot accounts. The method can monitor the results of accounting processing in real time and intelligently adjust the number of concurrent payment transactions to solve the problem of hot accounts in the payment process.
[0056] In view of this, the inventive concept of this application is as follows: the system first stores the message in the database, and then the main thread periodically captures the message to be processed and puts it into the queue, which is processed concurrently by the threads in the thread pool, and records the results of the accounting operations in the process of each concurrent thread processing the task object, and counts the timeout indicators corresponding to each time segment according to the preset time segment; in response to the thread number adjustment instruction, the timeout indicators of multiple adjacent time segments before the current time are obtained, and the obtained timeout indicators are weighted to determine the comprehensive timeout indicator; the number of concurrent threads in the thread pool is adjusted according to the comprehensive timeout indicator.
[0057] Other features and advantages of the present application will be described in the following description, and in part will become apparent from the description, or will be understood by practicing the present application. The purposes and other advantages of the present application can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings.
[0058] The following describes in detail the method for solving the payment hotspot account problem in the embodiment of the present application with reference to the accompanying drawings.
[0059] See also Figure 1 The following is a flow chart of a method for solving a payment hotspot account problem provided by one embodiment of the present application, including:
[0060] Step 101: In response to a message capture instruction, a payment message to be processed is obtained through the main thread.
[0061] The pending message includes payment business related information, such as payment account number, payer name, paying bank number, payee account number, payee name, receiving bank number, amount, etc.
[0062] In order to prevent the payment system from suddenly receiving a large number of pending messages, which may cause system performance problems, the system will first store the pending messages in the database. In response to the message capture instruction, the main thread will obtain the pending messages from the database at a preset time.
[0063] Step 102: Generate a task object including an accounting operation according to the payment message to be processed, and concurrently process the currently unprocessed task objects through multiple threads in a thread pool.
[0064] Multiple concurrent threads are placed in a thread pool. Each concurrent thread in the thread pool is responsible for processing a specific task object. The processing steps include bookkeeping operations. The results of the bookkeeping operations are accumulated and stored in the shared memory area.
[0065] That is, the shared memory area records the cumulative value of the results of the accounting operations of the threads in the thread pool when processing specific task objects.
[0066] After the main thread obtains the payment message to be processed from the database, it generates a task object including the accounting operation according to the message. When multiple threads in the thread pool process these task objects concurrently, they follow the above-mentioned exclusive lock usage rules.
[0067] Step 103: Determine the result of the accounting operation during the processing of the task object, and count the timeout indicators corresponding to each time segment according to the preset time segments. The accounting operation result includes whether the accounting operation is completed within the preset time threshold.
[0068] The preset time segment refers to a time period formed by dividing natural time into a certain length. In the embodiment of the present application, the preset time segment length is 5s, that is, every 5 seconds is a time segment.
[0069] In the embodiment of the present application, the memory is used to cache the corresponding data so that the data can be read from the memory in real time for data processing. The timeout indicators corresponding to each time segment are counted according to the preset time segments, including:
[0070] In response to the time slice object initialization instruction, a preset number of time slice objects in the memory are initialized. The time slice objects are numbered and correspond to the time slice cycles of natural time. At fixed intervals, multiple time slice objects to be used are batch initialized.
[0071] The system has a number of preset time segment objects (80 in this embodiment). Each time segment of natural time corresponds to a time segment object. As time passes, these objects are cyclically assigned. That is, after the last time segment object is assigned, the next time segment of natural time will be assigned to the first time segment object as time passes.
[0072] At regular intervals, the system batch-initializes multiple time-slice objects that are about to be used. This initialization operation includes clearing the accumulated results of accounting operations.
[0073] As an optional implementation, counting the timeout indicators corresponding to each time segment according to the preset time segments includes:
[0074] Count the total number of accounting operations in each time segment according to the preset time segment;
[0075] Count the number of accounting operation timeouts in each time segment according to the preset time segments;
[0076] The timeout rate corresponding to each time segment is obtained based on the ratio of the number of accounting operation timeouts corresponding to each time segment to the total number of accounting operations.
[0077] Specifically, the system uses time slice objects to correspond to natural time slices. The class (Class) of the time slice object in the system has two properties: the total number of accounting operations and the number of accounting operation timeouts. The timeout can be determined based on the response code of the accounting operation. The system pre-sets a preset time. When a hot account problem occurs in the system (manifested by the accounting operation exceeding the preset time), the system will no longer wait for the result of the accounting operation after the accounting operation times out. At this time, the total number of accounting operations and the number of accounting operation timeouts for the time slice object corresponding to the current time point are both increased by 1. When the system does not have a hot account problem (manifested by the accounting operation being completed within the preset time), only the total number of accounting operations for the time slice object corresponding to the current time point is increased by 1.
[0078] The time segment object corresponding to the time segment corresponding to the current time point is represented by N. The timeout rate of the time segment object N is: TimeoutRate(N) = number of accounting timeouts ÷ total number of accounting records.
[0079] Step 104 : In response to the thread quantity adjustment instruction, obtain timeout indicators of multiple time segments adjacent to the current time, and perform weighted processing on the obtained timeout indicators to determine a comprehensive timeout indicator.
[0080] The time slice object initialization instruction is triggered once every fixed time interval. In this embodiment, the fixed time interval is 2 minutes. Therefore, for any time point, its corresponding time slice object can be determined. In this embodiment of the application, when the thread number adjustment is triggered, multiple adjacent time slice objects before the current time are obtained. Specifically, the time slice object of the time slice closest to the current time can be determined in the following way:
[0081] First, obtain the index value (i.e., key value) of the time segment object used for the current time.
[0082] When the system starts, a Hash Map of time slice objects is created in the memory, that is, in the above-mentioned shared memory area. The Hash Map size is set to 80 (can be adjusted according to the specific application scenario). Figure 2 Schematic diagram of the HashMap of time slice objects. The first column, Key, represents the index values from 0 to 79, and the object references in the second column correspond to the first time slice object 0 to the 80th time slice object 79. The following example illustrates the mapping rules between the current time point and the time slice object. Assuming that the time slice length is set to 5 seconds, there are 80 time slice objects in the HashMap, and the current time point is 9:24:59 am, then the mapping rules are as follows:
[0083] Step 1, the cumulative number of seconds for the day = 9*60*60+24*60+59=33899;
[0084] Step 2: The cumulative number of time segments for the day = Floor (current cumulative number of seconds ÷ 5) = 6779;
[0085] Note: Floor() means taking the integer part.
[0086] Step 3: The key of the time segment object of the most recent time segment before the current time = the current cumulative time segment number % 80 = 59, where % represents the remainder.
[0087] From this, we can see that through the above calculation, the time segment object of the time segment most recently before the current time corresponds to the time segment object with a key index value of 59.
[0088] Specifically, in order to solve the problem of hot accounts, in response to the thread number adjustment instruction, the system obtains the timeout indicators of multiple time segments adjacent to the current time, and assigns different weight values to the timeout indicators of different time segments according to the principle of "the closer to the current time, the greater the weight", and performs weighted processing on these timeout indicators to determine the comprehensive timeout indicator.
[0089] As an optional implementation, obtaining timeout indicators of multiple time segments adjacent to the current time and weighting the obtained timeout indicators to determine a comprehensive timeout indicator includes:
[0090] Calculate the position of the time segment object corresponding to the current time in memory according to the current time, obtain several time segment objects before the time segment object, calculate the timeout index of the time segment object, and perform weighted processing on the timeout index to determine the comprehensive timeout index.
[0091] The following table lists the weights for timeout metrics for objects in different time segments. These weights can be adjusted based on the specific application scenario, but they should be assigned based on the principle that the closer the time is to the current time, the greater the weight.
[0092]
[0093]
[0094] The obtained timeout indicators are weighted according to the determined weights to determine the comprehensive timeout indicator. For details, see the table above. The timeout rate after weighted processing is the comprehensive timeout indicator.
[0095] As an optional implementation, the comprehensive timeout index is a comprehensive timeout rate obtained by weighting the timeout rates of multiple time segments. The comprehensive timeout rate can be determined using the following formula:
[0096] Comprehensive timeout rate = TimeoutRate(N-1)*40%+TimeoutRate(N-2)*30%+
[0097] TimeoutRate(N-3)*20%+TimeoutRate(N-4)*10%.
[0098] Step 105: Adjust the number of concurrent threads in the thread pool according to the comprehensive timeout indicator.
[0099] As an optional implementation, the expected number of concurrent threads of the thread pool is determined based on the comprehensive timeout index, where the expected number of concurrent threads is an integer greater than 1, and the higher the timeout degree corresponding to the comprehensive timeout index, the smaller the corresponding expected number of concurrent threads.
[0100] As an optional implementation, the expected number of concurrent threads is calculated using the following formula:
[0101] Expected number of concurrent threads = max{Floor(preset normal value*(1-comprehensive timeout rate)),1}.
[0102] Note: max{} means taking the maximum value, and Floor() means taking the integer part.
[0103] Specifically, before adjusting the number of concurrent threads in the thread pool each time in this application, the expected number of concurrent threads in the thread pool is dynamically calculated based on several time segment objects before the current time segment object (marked as N-1, N-2, N-3, N-4, etc.).
[0104] During the calculation process, the principle is that the higher the comprehensive timeout index, the fewer the expected number of concurrent threads. For example, if the current number of concurrent threads in the concurrent thread pool is 10 and the expected number of concurrent threads is 6, the number of concurrent threads in the concurrent thread pool needs to be set to 6. If these 10 concurrent threads are all in the process of executing tasks, then 4 of them will be destroyed after completing the tasks.
[0105] As an optional implementation, after obtaining the expected number of concurrent threads, it is determined that the number of concurrent threads in the current thread pool exceeds the expected number of concurrent threads, and the corresponding thread is destroyed after the thread completes processing the current task object until the number of concurrent threads in the thread pool reaches the expected number of concurrent threads.
[0106] Determine that the number of concurrent threads in the current thread pool is less than the expected number of concurrent threads, and create a new thread until the number of concurrent threads in the thread pool reaches the expected number of concurrent threads.
[0107] Generally speaking, if the system receives many payment messages for the same account at a certain point in time, that is, a hot account problem occurs, then the timeout rate of multiple time segments close to the current time point will become higher. The system will reduce the number of concurrent threads in the thread pool through calculation, thereby reducing the number of concurrent accounting operations. The pressure on the accounting database will also be reduced, the phenomenon of accounting operation timeout will disappear, and the hot account problem will be solved.
[0108] When the accounting operation timeout phenomenon disappears, the timeout rate of multiple time segments close to the current time point will become lower. The system will restore the number of concurrent threads in the thread pool through calculation and process the payment messages to be processed according to the normal throughput.
[0109] In this application, when the comprehensive timeout index is higher, in order to avoid processing a large number of accounting operations for the same account at the same time, the number of concurrent threads in the thread pool is reduced. This can effectively reduce the number of concurrent accounting operations for the same account, reduce the pressure on the database, improve the success rate of accounting processing, and avoid the problem of hot accounts.
[0110] As an optional implementation, after determining the result of the accounting operation in the process of processing the task object, the method further includes:
[0111] After determining that the accounting operation in any thread processing the current task object has timed out, initiate a reversal process for the timed-out accounting operation. After the reversal is successful, mark the payment message corresponding to the timed-out accounting operation with a special status;
[0112] The designated thread periodically obtains the payment message in the special status and re-processes the payment message including initiating the accounting operation in a serial processing manner.
[0113] Specifically, from the time the hot account problem first occurs to the time the system adjusts the number of concurrent threads in the thread pool, the accounting operation steps of a very small number of task objects will time out. For these timed accounting operations, the system will initiate an accounting reversal. If the reversal is unsuccessful, multiple reversals will be initiated, with the interval between each reversal getting longer and longer until the reversal is successful.
[0114] The designated thread in this application refers to the backup thread. In order to avoid causing the hot account problem again, the number of backup threads is very small, and in this embodiment, there is only one. The backup thread grabs the message set to a special state from the database for processing, such as Figure 3 As shown in the figure, since the number of these messages is extremely small, the backup thread will process them serially to avoid causing hot account issues again.
[0115] As an optional implementation manner, after generating a task object including an accounting operation according to the payment message to be processed, the method further includes:
[0116] When it is determined that the number of task objects in the task queue does not exceed the set value and there are task objects that have not been put into the task queue, the task objects that have not been put into the task queue are put into the task queue in sequence until the set number is reached;
[0117] If the number of task objects in the task queue exceeds the set value, the task objects not in the queue will be destroyed, and the payment messages corresponding to the task objects will be retrieved;
[0118] Determine whether there is an idle thread in the thread pool, obtain a task object from the task queue and hand it over to the idle thread for processing, and remove the obtained task object from the task queue.
[0119] Specifically, in the present application, when responding to a message capture instruction, the payment message to be processed obtained includes the payment message corresponding to the task object that was previously destroyed.
[0120] The task queue is a queue for placing task objects generated by the to-be-processed messages obtained by the main thread. There is a set value for the number of task objects placed in the task queue, which is the maximum number of task objects that the task queue can accommodate.
[0121] The maximum setting value of the task queue (i.e., the queue length) can be set according to the specific business scenario. Specifically, the main thread puts the task object into the task queue, and the concurrent thread of the thread pool obtains the task object from the task queue, which is a dynamic "production and consumption" process. That is, the main thread acts as a producer and puts the task object into the task queue. If the queue is full, the main thread will destroy the task objects that are not put into the queue, and the corresponding messages will be re-acquired by the main thread when the message is captured at the next scheduled time. The concurrent threads of the thread pool act as consumers. Once they are idle, they obtain the task object from the queue for processing. At this time, the task object is removed from the queue. The enqueueing and dequeueing of task objects follow the "first in, first out" principle.
[0122] As an optional implementation, obtaining timeout indicators of multiple time segments adjacent to the current time and weighting the obtained timeout indicators to determine a comprehensive timeout indicator includes:
[0123] Obtain the timeout indicators of multiple time segments adjacent to the current time, and determine the weight of each time segment based on the principle that the closer the time is to the current time, the greater the corresponding weight;
[0124] The obtained timeout indicators are weighted according to the determined weights to determine a comprehensive timeout indicator.
[0125] In general, see Figure 4 The concurrent processing framework in this application's method for solving the payment hotspot account problem is specifically as follows:
[0126] First, the main thread periodically retrieves pending messages from the database. Based on these pending messages, it generates a task object containing an accounting operation and places it in a task queue. Once a thread in the thread pool becomes idle, it retrieves the task object from the task queue for processing. Multiple threads in the thread pool concurrently process unprocessed task objects. As threads process task objects, the results of the accounting operations are accumulated and stored in a shared memory area by time slice. The adjustment thread adjusts the number of thread pool threads based on the results of these accounting operations to control the number of concurrent accounting operations, thereby resolving the issue of hotspot accounts.
[0127] Example 2
[0128] Based on the same inventive concept, this application also provides a device for solving the problem of payment hotspot accounts, such as Figure 5 As shown, the device includes:
[0129] An acquisition module 501 is configured to respond to a message capture instruction and acquire a payment message to be processed through a main thread;
[0130] Processing module 502, configured to generate a task object including an accounting operation according to the payment message to be processed, and concurrently process currently unprocessed task objects through multiple threads in a thread pool;
[0131] A statistics module 503 is used to determine the results of the accounting operation during the processing of the task object, and to count the timeout indicators corresponding to each time segment according to the preset time segments. The accounting operation results include whether the accounting operation is completed within the preset time threshold.
[0132] The weighting module 504 is configured to obtain timeout indicators of multiple time segments adjacent to the current time in response to the thread quantity adjustment instruction, and perform weighted processing on the obtained timeout indicators to determine a comprehensive timeout indicator;
[0133] The adjustment module 505 is configured to adjust the number of concurrent threads in the thread pool according to the comprehensive timeout indicator.
[0134] Optionally, after determining the accounting operation result in the process of processing the task object, the statistics module 503 is further configured to:
[0135] After determining that the accounting operation in any thread processing the current task object has timed out, initiate a reversal process for the timed-out accounting operation. After the reversal is successful, mark the payment message corresponding to the timed-out accounting operation with a special status;
[0136] The designated thread periodically obtains the payment message in the special status and re-processes the payment message including initiating the accounting operation in a serial processing manner.
[0137] Optionally, after generating a task object including an accounting operation according to the payment message to be processed, the processing module 502 is further configured to:
[0138] When it is determined that the number of task objects in the task queue does not exceed the set value and there are task objects that have not been put into the task queue, the task objects that have not been put into the task queue are put into the task queue in sequence until the set number is reached;
[0139] If the number of task objects in the task queue exceeds the set value, the task objects not in the queue will be destroyed, and the payment messages corresponding to the task objects will be retrieved;
[0140] Determine whether there is an idle thread in the thread pool, obtain a task object from the task queue and hand it over to the idle thread for processing, and remove the obtained task object from the task queue.
[0141] Optionally, the statistics module 503 is specifically configured to:
[0142] In response to the time slice object initialization instruction, a preset number of time slice objects in the memory are initialized. The time slice objects are numbered and correspond to the time slice cycles of natural time. At fixed intervals, multiple time slice objects to be used are batch initialized.
[0143] Optionally, the weighting module 504 is specifically configured to:
[0144] Calculate the position of the time segment object corresponding to the current time in memory according to the current time, obtain several time segment objects before the time segment object, calculate the timeout index of the time segment object, and perform weighted processing on the timeout index to determine the comprehensive timeout index.
[0145] Optionally, the statistics module 503 is specifically configured to:
[0146] Count the total number of accounting operations in each time segment according to the preset time segment;
[0147] Count the number of accounting operation timeouts in each time segment according to the preset time segments;
[0148] The timeout rate corresponding to each time segment is obtained based on the ratio of the number of accounting operation timeouts corresponding to each time segment to the total number of accounting operations.
[0149] Optionally, the weighting module 504 is specifically configured to:
[0150] Obtain the timeout indicators of multiple time segments adjacent to the current time, and determine the weight of each time segment based on the principle that the closer the time is to the current time, the greater the corresponding weight;
[0151] The obtained timeout indicators are weighted according to the determined weights to determine a comprehensive timeout indicator.
[0152] Optionally, the adjustment module 505 is specifically configured to:
[0153] Determining the expected number of concurrent threads of the thread pool according to the comprehensive timeout indicator, wherein the expected number of concurrent threads is an integer greater than 1, and the higher the timeout degree corresponding to the comprehensive timeout indicator, the smaller the corresponding expected number of concurrent threads;
[0154] Determine that the number of concurrent threads in the current thread pool exceeds the expected number of concurrent threads, and destroy the corresponding thread after the thread completes processing the current task object until the number of concurrent threads in the thread pool reaches the expected number of concurrent threads;
[0155] Determine that the number of concurrent threads in the current thread pool is less than the expected number of concurrent threads, and create a new thread until the number of concurrent threads in the thread pool reaches the expected number of concurrent threads.
[0156] Optionally, the comprehensive timeout index is a comprehensive timeout rate obtained by weighting the timeout rates of multiple time segments, and the adjustment module 505 is specifically configured to:
[0157] Expected number of concurrent threads = max{Floor(preset normal value*(1-comprehensive timeout rate)),1}.
[0158] After introducing the method and apparatus for solving the payment hotspot account problem according to an exemplary embodiment of the present application, next, an electronic device according to another exemplary embodiment of the present application is introduced.
[0159] Those skilled in the art will appreciate that various aspects of the present application can be implemented as systems, methods, or program products. Therefore, various aspects of the present application can be specifically implemented in the following forms: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or an implementation that combines hardware and software aspects, which may be collectively referred to herein as a "circuit," "module," or "system."
[0160] In some possible implementations, an electronic device according to the present application may include at least one processor and at least one memory. The memory stores program code that, when executed by the processor, causes the processor to perform the steps of the method for resolving payment hotspot account issues according to various exemplary embodiments of the present application as described above in this specification.
[0161] Refer to the following Figure 6 To describe the electronic device 130 according to this embodiment of the present application, that is, the above-mentioned device for solving the payment hotspot account problem. Figure 6The electronic device 130 shown is merely an example and should not limit the functions and scope of use of the embodiments of the present application.
[0162] like Figure 6 As shown, the electronic device 130 is a general electronic device. Components of the electronic device 130 may include, but are not limited to, the at least one processor 131, the at least one memory 132, and a bus 133 connecting different system components (including the memory 132 and the processor 131).
[0163] Bus 133 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, and a processor or local bus using any of a variety of bus architectures.
[0164] The memory 132 may include a readable medium in the form of a volatile memory, such as a random access memory (RAM) 1321 and / or a cache memory 1322 , and may further include a read-only memory (ROM) 1323 .
[0165] The memory 132 may also include a program / utility 1325 having a set (at least one) of program modules 1324, such program modules 1324 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0166] The electronic device 130 may also communicate with one or more external devices 134 (e.g., a keyboard, pointing device, etc.), one or more devices that enable a user to interact with the electronic device 130, and / or any device that enables the electronic device 130 to communicate with one or more other electronic devices (e.g., a router, a modem, etc.). Such communication may occur via an input / output (I / O) interface 135. Furthermore, the electronic device 130 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network such as the Internet) via a network adapter 136. As shown, the network adapter 136 communicates with other modules of the electronic device 130 via a bus 133. It should be understood that, although not shown, other hardware and / or software modules may be used in conjunction with the electronic device 130, including but not limited to microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0167] In some possible implementations, various aspects of a method for solving payment hotspot account problems provided by the present application may also be implemented in the form of a program product, including computer program instructions, which are executed by a processor to perform the steps of a method for solving payment hotspot account problems according to various exemplary embodiments of the present application as described above in this specification.
[0168] The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The 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 thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable 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 foregoing.
[0169] In some possible implementations, the present application provides a computer storage medium storing a computer program, which is used to enable a computer to execute the steps of a method for solving payment hotspot account problems according to various exemplary implementations of the present application described above in this specification.
[0170] The program product for monitoring of the embodiment of the present application can be a portable compact disc read-only memory (CD-ROM) and include program code, and can be run on an electronic device. However, the program product of the present application is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0171] A readable signal medium may include a data signal transmitted in baseband or as part of a carrier wave, which carries readable program code. Such a transmitted data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable signal medium may also be any readable medium other than a readable storage medium that can transmit, propagate, or transfer a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0172] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0173] The program code for performing the operations of the present application can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user electronic device, partially on the user device, as a separate software package, partially on the user electronic device and partially on a remote electronic device, or entirely on the remote electronic device or server. In cases involving remote electronic devices, the remote electronic device can be connected to the user electronic device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external electronic device (for example, using an Internet service provider to connect through the Internet).
[0174] It should be noted that although several units or subunits of the device are mentioned in the detailed description above, this division is merely exemplary and not mandatory. In fact, depending on the embodiment of the application, the features and functions of two or more units described above can be embodied in a single unit. Conversely, the features and functions of a single unit described above can be further divided and embodied by multiple units.
[0175] Furthermore, although the operations of the method of the present application are described in a particular order in the accompanying drawings, this does not require or imply that the operations must be performed in this particular order, or that all illustrated operations must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.
[0176] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0177] The present application is described with reference to the flowcharts and block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowcharts and block diagrams, as well as the combination of processes and boxes in the flowcharts and block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts. Figure 1 A process or multiple processes and boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0178] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and boxes Figure 1 The function specified in one or more boxes.
[0179] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 A process or multiple processes and boxes Figure 1 A step that specifies a function in one or more boxes.
[0180] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present application.
[0181] Obviously, those skilled in the art may make various changes and modifications to this application without departing from the spirit and scope of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalents, this application is intended to include these modifications and variations.
Claims
1. A method for solving the problem of payment hotspot accounts, characterized in that: The method comprises: In response to the message capture instruction, the payment message to be processed is obtained through the main thread; Generate a task object including an accounting operation according to the payment message to be processed, and concurrently process the currently unprocessed task objects through multiple threads in a thread pool; Determine the result of the accounting operation during the processing of the task object, and count the timeout indicators corresponding to each time segment according to the preset time segments, wherein the accounting operation result includes whether the accounting operation is completed within the preset time threshold; In response to the thread quantity adjustment instruction, obtaining timeout indicators of a plurality of time segments adjacent to the current time, and performing weighted processing on the obtained timeout indicators to determine a comprehensive timeout indicator; Determine the expected number of concurrent threads in the thread pool based on the comprehensive timeout indicator, where the expected number of concurrent threads is an integer greater than 1, and the higher the timeout degree corresponding to the comprehensive timeout indicator, the smaller the corresponding expected number of concurrent threads; determine that the number of concurrent threads in the current thread pool exceeds the expected number of concurrent threads, and destroy the corresponding thread after the thread has processed the current task object until the number of concurrent threads in the thread pool reaches the expected number of concurrent threads; determine that the number of concurrent threads in the current thread pool is less than the expected number of concurrent threads, and create a new thread until the number of concurrent threads in the thread pool reaches the expected number of concurrent threads.
2. The method according to claim 1, characterized in that After determining the result of the accounting operation in the process of processing the task object, it also includes: After determining that the accounting operation in any thread processing the current task object has timed out, initiate a reversal process for the timed-out accounting operation. After the reversal is successful, mark the payment message corresponding to the timed-out accounting operation with a special status; The designated thread periodically obtains the payment message in the special status and re-processes the payment message including initiating the accounting operation in a serial processing manner.
3. The method according to claim 1, characterized in that After generating a task object including an accounting operation according to the payment message to be processed, the method further includes: When it is determined that the number of task objects in the task queue does not exceed the set value and there are task objects that have not been put into the task queue, the task objects that have not been put into the task queue are put into the task queue in sequence until the set number is reached; If the number of task objects in the task queue exceeds the set value, the task objects not in the queue will be destroyed, and the payment messages corresponding to the task objects will be retrieved; Determine whether there is an idle thread in the thread pool, obtain a task object from the task queue and hand it over to the idle thread for processing, and remove the obtained task object from the task queue.
4. The method according to claim 1, wherein Determine the accounting operation results during the processing of the task object, and count the timeout indicators corresponding to each time segment according to the preset time segments, including: In response to the time slice object initialization instruction, a preset number of time slice objects in the memory are initialized, where the time slice objects are numbered and correspond to the time slices of natural time in a cyclic manner, and multiple time slice objects to be used are batch initialized at fixed intervals; Obtain timeout indicators for multiple time segments immediately before the current time, and perform weighted processing on the obtained timeout indicators to determine a comprehensive timeout indicator, including: Calculate the position of the time segment object corresponding to the current time in memory according to the current time, obtain several time segment objects before the time segment object, calculate the timeout index of the time segment object, and perform weighted processing on the timeout index to determine the comprehensive timeout index.
5. The method according to claim 1, wherein The timeout indicators corresponding to each time segment are counted according to the preset time segments, including: Count the total number of accounting operations in each time segment according to the preset time segment; Count the number of accounting operation timeouts in each time segment according to the preset time segments; The timeout rate corresponding to each time segment is obtained based on the ratio of the number of accounting operation timeouts corresponding to each time segment to the total number of accounting operations.
6. The method according to any one of claims 1 to 5, characterized in that Obtain timeout indicators for multiple time segments immediately before the current time, and perform weighted processing on the obtained timeout indicators to determine a comprehensive timeout indicator, including: Obtain the timeout indicators of multiple time segments adjacent to the current time, and determine the weight of each time segment based on the principle that the closer the time is to the current time, the greater the corresponding weight; The obtained timeout indicators are weighted according to the determined weights to determine a comprehensive timeout indicator.
7. The method according to claim 1, characterized in that The comprehensive timeout index is a comprehensive timeout rate obtained by weighted processing of the timeout rates of multiple time segments. The expected number of concurrent threads of the concurrent threads is determined based on the comprehensive timeout index, including: Expected number of concurrent threads = max {Floor(preset normal value * (1 - comprehensive timeout rate)), 1}.
8. A device for solving the problem of payment hotspot accounts, characterized in that: The device comprises: An acquisition module, configured to respond to a message capture instruction and acquire a payment message to be processed through a main thread; a processing module, configured to generate a task object including an accounting operation according to the payment message to be processed, and concurrently process currently unprocessed task objects through multiple threads in a thread pool; A statistics module is used to determine the results of accounting operations during the processing of task objects, and to count the timeout indicators corresponding to each time segment according to preset time segments, wherein the accounting operation results include whether the accounting operation is completed within a preset time threshold; A weighting module is used to obtain timeout indicators of multiple time segments adjacent to the current time in response to the thread quantity adjustment instruction, and perform weighted processing on the obtained timeout indicators to determine a comprehensive timeout indicator; An adjustment module is configured to determine an expected number of concurrent threads in a thread pool according to the comprehensive timeout index, where the expected number of concurrent threads is an integer greater than 1, and a higher timeout degree corresponding to the comprehensive timeout index indicates a lower expected number of concurrent threads; determine that the number of concurrent threads in the current thread pool exceeds the expected number of concurrent threads, and destroy the corresponding thread after the thread has processed the current task object until the number of concurrent threads in the thread pool reaches the expected number of concurrent threads; determine that the number of concurrent threads in the current thread pool is less than the expected number of concurrent threads, and create a new thread until the number of concurrent threads in the thread pool reaches the expected number of concurrent threads.
9. An electronic device, characterized in that: The invention comprises at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the method according to any one of claims 1 to 7.
10. A computer program product, characterized in that The method comprises computer program instructions, wherein when the computer program instructions are executed by a processor, the method according to any one of claims 1 to 7 is implemented.
11. A computer storage medium, characterized in that The computer storage medium stores a computer program, and the computer program is used to enable a computer to execute the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Hotspot account concurrent data processing system and method
CN110298746A
Thread pool parameter adjusting method and device
CN113268330A