Data statistics cycle switching method, device, equipment and storage medium
By monitoring the cycle switching instructions in real time and performing thread switching during the data statistics process, combined with the status monitoring of the global counter, the problem of omissions in data warehousing caused by the data statistics cycle switching is solved and the integrity and accuracy of the data are ensured.
Patent Information
- Application Number
- CN202210584801.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-27
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2042-05-27
AI Technical Summary
Existing data statistics cycle switching methods can easily lead to omissions in data warehousing under high concurrency conditions. Existing technologies are difficult to effectively process and allocate request time, resulting in the omission of some data.
By monitoring the cycle switching instructions sent by the terminal, thread switching is performed, and global counters are used to monitor the status of data processing requests to determine whether the switching conditions are met, and the switching time stamp is stored in the database to avoid data omissions.
Real-time switching during the data statistics process is realized, ensuring that the data within the current statistical period is completely entered into the database, and avoiding the omission of data into the database.
Smart Images

Figure CN115080577B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of big data, and in particular to a data statistical period switching method, device, equipment and storage medium. Background Art
[0002] In some statistical scenarios, it is necessary to switch at a time point T controlled by a business person without interrupting business requests. Requests received before time point T are divided into the current statistical period, and requests after time point T are divided into a new statistical period, and data for the current statistical period is generated.
[0003] The industry generally uses the request time stored in the database to divide. When the concurrency is large, some request times may belong to the data in the current statistical period that have not been processed and stored in the database. The next statistical period will also ignore it, resulting in missing some data. That is, the existing data statistical period switching is prone to data omissions. Summary of the invention
[0004] The main purpose of the present invention is to solve the technical problem that the switching of existing data statistical cycles easily leads to data omission in the database.
[0005] The first aspect of the present invention provides a data statistics cycle switching method, comprising: when a cycle switching instruction sent by a terminal is monitored, according to the cycle switching instruction, the thread switching of the processing of the data processing request in the preset request queue is performed; through the switched thread, the request data corresponding to the data processing request is sequentially stored in the warehouse, and the request status of the switched thread is monitored through a preset global counter; the monitoring result of the request status corresponding to the global counter is obtained, and according to the monitoring result, it is determined whether the global counter meets the preset cycle switching condition; if the global counter meets the cycle switching condition, the current time is set as the switching time of the current cycle, and the request data after storage is marked with the switching time.
[0006] Optionally, in a first implementation method of the first aspect of the present invention, when a periodic switching instruction sent by a terminal is monitored, after performing thread switching on the processing of a data processing request in a preset request queue according to the periodic switching instruction, it also includes: obtaining a new data processing request, and determining whether the new data processing request meets a preset preprocessing condition; if so, obtaining request data corresponding to the new data processing request by presetting a first thread, and storing the request data corresponding to the new data processing request in a preset temporary data table; if not, returning processing exception prompt information corresponding to the new data processing request.
[0007] Optionally, in a second implementation method of the first aspect of the present invention, when a cycle switching instruction sent by the terminal is monitored, according to the cycle switching instruction, thread switching is performed on the processing of data processing requests in the preset request queue, including: when a cycle switching instruction sent by the terminal is monitored, the cycle switching instruction is parsed to obtain a memory address corresponding to a second thread that processes the data processing request in the preset request queue; according to the memory address, the corresponding register is searched, and the thread pointer and register pointer in the register are updated to perform thread switching on the processing of the data processing request.
[0008] Optionally, in a third implementation method of the first aspect of the present invention, request status monitoring of the switched thread is performed by presetting a global counter, including: monitoring each state monitoring factor in the switched thread by presetting a global counter, and counting the counts corresponding to each state monitoring factor; generating a global variable corresponding to the switched thread by a global counter based on counting the counts corresponding to each state monitoring factor; and monitoring the request status of the switched thread using the global counter according to the global variable.
[0009] Optionally, in a fourth implementation of the first aspect of the present invention, different types of status monitoring factors include a first factor, a second factor and a third factor. By presetting a global counter, each status monitoring factor in the switched thread is monitored, and the count corresponding to each status monitoring factor is counted, including: by presetting a global counter, the number of data processing requests in the switched thread is monitored, and according to the number of data processing requests, the count corresponding to the first factor is determined; by monitoring, through a global counter, whether the request data corresponding to the data processing request in the switched thread is successfully stored; if the storage is successful, adjusting the count corresponding to the second factor; by monitoring, through a global counter, whether the data processing request in the switched thread is processed abnormally; if the processing is abnormal, adjusting the count corresponding to the third factor.
[0010] Optionally, in a fifth implementation of the first aspect of the present invention, judging whether the global counter satisfies a preset periodic switching condition according to the monitoring results includes: judging whether the global variable is greater than a preset variable threshold according to the monitoring results; if the global variable is greater than the variable threshold, re-judging whether the global variable is greater than the variable threshold after a preset waiting time, until a preset number of judgments is reached, determining that the global counter does not satisfy the preset periodic switching condition; if the global variable is less than the variable threshold, determining that the global counter satisfies the periodic switching condition.
[0011] The second aspect of the present invention provides a data statistics cycle switching device, including: a switching module, which is used to switch the thread of processing the data processing request in the preset request queue according to the cycle switching instruction when monitoring the cycle switching instruction sent by the terminal; a monitoring module, which is used to store the request data corresponding to the data processing request in sequence through the switched thread, and monitor the request status of the switched thread through a preset global counter; a judgment module, which is used to obtain the monitoring result of the request status corresponding to the global counter, and judge whether the global counter meets the preset cycle switching condition according to the monitoring result; a setting module, which is used to set the current time as the switching time of the current cycle if the global counter meets the cycle switching condition, and use the switching time to mark the request data after storage.
[0012] Optionally, in a first implementation method of the second aspect of the present invention, the data statistical period switching device also includes a temporary storage module, which is used to: obtain a new data processing request and determine whether the new data processing request meets the preset preprocessing conditions; if so, obtain the request data corresponding to the new data processing request through a preset first thread, and store the request data corresponding to the new data processing request in a preset temporary data table; if not, return the processing exception prompt information corresponding to the new data processing request.
[0013] Optionally, in a second implementation method of the second aspect of the present invention, the switching module includes: a parsing unit, which is used to parse the cycle switching instruction sent by the terminal when it monitors the cycle switching instruction, and obtain the memory address corresponding to the second thread that processes the data processing request in the preset request queue; an updating unit, which is used to search for the corresponding register according to the memory address, and update the thread pointer and register pointer in the register to perform thread switching for the processing of the data processing request.
[0014] Optionally, in a third implementation method of the second aspect of the present invention, the monitoring module includes: a statistical unit, which is used to monitor each state monitoring factor in the switched thread by presetting a global counter, and to count the counts corresponding to each state monitoring factor; a generation unit, which is used to generate a global counter based on the counts corresponding to each state monitoring factor to monitor the global variable corresponding to the switched thread; and a monitoring unit, which is used to perform request status monitoring on the switched thread using the global counter according to the global variable.
[0015] Optionally, in a fourth implementation manner of the second aspect of the present invention, different types of status monitoring factors include a first factor, a second factor and a third factor, and the statistical unit is also used to: monitor the number of data processing requests in the switched thread by presetting a global counter, and determine the count corresponding to the first factor based on the number of data processing requests; monitor whether the request data corresponding to the data processing request in the switched thread is successfully stored in the warehouse through the global counter; if the storage is successful, adjust the count corresponding to the second factor; monitor whether the data processing request in the switched thread is processed abnormally through the global counter; if the processing is abnormal, adjust the count corresponding to the third factor.
[0016] Optionally, in a fifth implementation of the second aspect of the present invention, the judgment module includes: a judgment unit, used to judge whether the global variable is greater than a preset variable threshold based on the monitoring results; a loop unit, used to re-judge whether the global variable is greater than the variable threshold after a preset waiting time if the global variable is greater than the variable threshold, until a preset number of judgments is reached, and then determine that the global counter does not meet the preset cycle switching condition; a determination unit, used to determine that the global counter meets the cycle switching condition if the global variable is less than the variable threshold.
[0017] The third aspect of the present invention provides a data statistical cycle switching device, comprising: a memory and at least one processor, wherein instructions are stored in the memory; at least one processor calls the instructions in the memory so that the data statistical cycle switching device executes the above-mentioned data statistical cycle switching method.
[0018] A fourth aspect of the present invention provides a computer-readable storage medium, in which instructions are stored, and when the computer-readable storage medium is run on a computer, the computer executes the above-mentioned data statistics period switching method.
[0019] In the technical solution provided by the present invention, the cycle switching instruction sent by the terminal is monitored in real time. When it is monitored, the thread of the data processing request is switched, and the conventional thread of the data processing request is replaced by another thread after the cycle switching to store the requested data and monitor the request status at the same time to determine whether the global counter meets the cycle switching condition, and is used to mark the actual cycle switching time of the requested data after the switching cycle, distinguish the cycle switched data, and avoid missing the data in the current statistical cycle after the statistical cycle is switched. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 This is a schematic diagram of a first embodiment of a method for switching a data statistical cycle in an embodiment of the present invention;
[0021] Figure 2 Schematic diagram of a second embodiment of the data statistics cycle switching method in an embodiment of the present invention;
[0022] Figure 3 Schematic diagram of a third embodiment of the data statistics cycle switching method in an embodiment of the present invention;
[0023] Figure 4 A schematic diagram of an embodiment of a data statistics cycle switching device in an embodiment of the present invention;
[0024] Figure 5 A schematic diagram of another embodiment of a data statistics cycle switching device in an embodiment of the present invention;
[0025] Figure 6 Schematic diagram of an embodiment of a data statistics period switching device in an embodiment of the present invention. DETAILED DESCRIPTION
[0026] The embodiment of the present invention provides a data statistics cycle switching method, device, equipment and storage medium. When a cycle switching instruction sent by a terminal is monitored, according to the cycle switching instruction, the processing of the data processing request in the preset request queue is thread-switched; through the switched thread, the request data corresponding to the data processing request is sequentially stored, and the request status of the switched thread is monitored by a preset global counter; the monitoring result of the request status corresponding to the global counter is obtained, and according to the monitoring result, it is determined whether the global counter meets the preset cycle switching condition; if the global counter meets the cycle switching condition, the current time is set as the switching time of the current cycle, and the request data after storage is marked with the switching time. The present invention realizes the real-time switching of the statistical cycle in the data statistics process, and avoids the data in the current statistical cycle from being omitted from storage.
[0027] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0028] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 , a first embodiment of the data statistics cycle switching method in an embodiment of the present invention includes:
[0029] 101. When a cycle switching instruction sent by the terminal is monitored, a thread switching is performed on the processing of the data processing request in the preset request queue according to the cycle switching instruction;
[0030] It is understandable that the execution subject of the present invention may be a data statistics period switching device, or a terminal or a server, which is not limited here. The embodiment of the present invention is described by taking a server as the execution subject as an example.
[0031] In this embodiment, the periodic switching instructions sent by the terminal are monitored in real time, wherein the periodic switching instructions are triggered by the periodic switching switch, and the switch is set to open when the periodic switching switch is triggered, otherwise it is closed. However, under high-concurrency data processing requests, due to computer computing power issues, it is impossible to process all uploaded data processing requests in real time, so it is necessary to write the data processing requests into the request queue in the order before and after they are sent, and then read and process them in the order written in the queue, and store the corresponding request data.
[0032] When the cycle switching instruction is detected to be triggered, in order to prevent the data processing requests in the request queue from being missed and forgotten to be processed, the unprocessed data processing requests in the request queue can be switched to a new thread for processing; and the new data processing requests received after the cycle switching instruction is triggered are processed by the original thread. The two are processed in parallel and do not affect each other.
[0033] 102. In the switched thread, request data corresponding to the data processing request is sequentially stored in the database, and the request status of the switched thread is monitored by a preset global counter;
[0034] In this embodiment, after the cycle switching instruction is triggered, the corresponding request data is stored in the warehouse for the data processing request that needs to be processed in the current cycle, and the request database is saved in the preset database for subsequent calls. At this time, the global counter is used to count the data processing requests being processed, the data processing requests that have been completed, and the data processing requests that have abnormalities, so as to monitor the processing status of the data processing requests in the second thread of the current cycle, that is, request status monitoring. Among them, the total number of data processing requests is counted and classified into the request status of the corresponding type. When the data processing request enters the storage process, the count is classified into the request status of the corresponding type. When the data processing request is completed, the count is classified into the request status of the corresponding type. When the data processing request is abnormal, the count is classified into the request status of the corresponding type, and multiple types of request status monitoring are completed.
[0035] 103. Obtain monitoring results of the request state corresponding to the global counter, and determine whether the global counter meets a preset period switching condition according to the monitoring results;
[0036] In this embodiment, the monitoring result of the request state corresponding to the global counter is obtained, that is, in order to obtain the above-mentioned global variable, the monitoring result is measured by the global variable to determine whether the current global counter meets the preset cycle switching condition, wherein the cycle switching condition is used to determine whether the data processing request of the current cycle is processed, including the completion of the storage of the requested data and the request exception of the data processing request, which are all regarded as the completion of the data processing request. Then the cycle switching condition is that the global variable is 0, and all data processing requests are processed.
[0037] 104. If the global counter meets the period switching condition, the current time is set as the switching time of the current period, and the request data after storage is marked with the switching time.
[0038] In this embodiment, until the global counter meets the cycle switching condition, it is determined that all data processing requests have been processed. At this time, the current time of processing completion can be set as the switching time of the current cycle and saved in the database. The request data obtained in each process is marked to distinguish the request data obtained in each cycle for subsequent business needs. Among them, the switching switch and the global counter can introduce middleware such as Redis and ZooKeeper that can be used to save global variables.
[0039] In an embodiment of the present invention, the cycle switching instruction sent by the terminal is monitored in real time. When it is monitored, the thread of the data processing request is switched, and the conventional thread of the data processing request is replaced by another thread after the cycle switching to store the requested data and monitor the request status at the same time to determine whether the global counter meets the cycle switching condition, which is used to mark the actual cycle switching time of the requested data after the switching cycle, distinguish the cycle switched data, and avoid missing the data in the current statistical cycle after the statistical cycle is switched.
[0040] See also Figure 2 , a second embodiment of the data statistical cycle switching method in an embodiment of the present invention includes:
[0041] 201. When a cycle switching instruction sent by a terminal is monitored, the cycle switching instruction is parsed to obtain a memory address corresponding to a second thread for processing data processing requests in a preset request queue;
[0042] 202. According to the memory address, find the corresponding register, and update the thread pointer and register pointer in the register to perform thread switching for processing the data processing request;
[0043] In this embodiment, by using a process cache framework such as RegCache to simultaneously set multiple thread execution sites inside the CPU (Central Processing Unit), and by adding RegCache line switching instructions (i.e., cycle switching instructions), switching between different threads can be achieved, and the original thread of the data processing request can be switched to a new second thread.
[0044] In this embodiment, the cycle switching instruction may be a ctx_sw ra instruction, where ctx_sw is an operation code, ra is an operand, and ra is a memory address corresponding to the second thread pointing to the data processing request in the request queue. For the original processing thread, its thread pointer is Cur_ctx_ptr. When executing the cycle switching instruction, it is necessary to first point to the register rx used by the second thread after the conversion, and its position is RegCache[Cur_ctx_ptr].Reg[rx]. In the register where the second thread is located, there is X, so that RegCache[X].tag==ra, so as to directly switch to the register where it is located, and thus fast switching between different threads can be achieved.
[0045] Specifically, Cur_ctx_ptr=X may be executed to update the initial thread pointer Cur_ctx_ptr in the register; PC=RegCache[X].Pc_ptr+1 may be executed to update the register pointer.
[0046] 203. Obtain a new data processing request, and determine whether the new data processing request satisfies a preset preprocessing condition;
[0047] 204. If satisfied, obtain request data corresponding to the new data processing request by presetting the first thread, and store the request data corresponding to the new data processing request in a preset temporary data table;
[0048] 205. If not satisfied, return the processing exception prompt information corresponding to the new data processing request;
[0049] In this embodiment, after the cycle switching instruction is triggered, the data processing requests previously stored in the request queue will be processed by the second thread, and the new data processing requests are pre-stored in the temporary table and processed normally by the original first thread. When obtaining a new data processing request, it is also necessary to screen the pre-processing conditions. For example, when a new data processing request is sent, it is determined whether the current sending speed exceeds the preset speed threshold. If it exceeds, it will be treated as an abnormal data processing request and the processing exception prompt information will be returned. Preferably, the speed threshold can be a total of 200 requests per second to prevent network attacks or order brushing.
[0050] 206. Monitor the request status of the switched thread by presetting a global counter;
[0051] 207. Obtain monitoring results of the request state corresponding to the global counter, and determine whether the global counter meets a preset period switching condition according to the monitoring results;
[0052] 208. If the global counter meets the period switching condition, the current time is set as the switching time of the current period, and the request data after storage is marked with the switching time.
[0053] In an embodiment of the present invention, after the statistical cycle is switched, for new data processing requests received after the current statistical cycle, the original first thread is still used to store the request data, wherein a temporary data table can be used to temporarily store the request data, and after the request data of the current statistical cycle is subsequently stored in the database, the request data in the temporary data table is stored again, thereby realizing the distinction between request data of different statistical cycles.
[0054] See also Figure 3 , a third embodiment of the data statistical cycle switching method in the embodiment of the present invention includes:
[0055] 301. When a cycle switching instruction sent by a terminal is monitored, a thread switching is performed on the processing of the data processing request in the preset request queue according to the cycle switching instruction;
[0056] 302. In the switched thread, request data corresponding to the data processing request is stored in sequence, and each state monitoring factor in the switched thread is monitored by presetting a global counter, and the count corresponding to each state monitoring factor is counted;
[0057] 303. Generate a global counter based on the counts corresponding to each state monitoring factor to monitor the global variable corresponding to the switched thread;
[0058] 304. According to the global variable, the request status of the switched thread is monitored using the global counter;
[0059] In this embodiment, multiple different types of status monitoring factors are pre-set to monitor each processing node in the entire logical thread processing process for data processing requests. The processing status of the data processing request in the second thread is measured according to the count quantity of each status monitoring factor, and the request status of the second thread is measured by a global variable based on each count quantity.
[0060] Specifically, the total number of the aforementioned data processing requests is included in the first factor, the count of the requested data corresponding to the data processing requests being stored in the database is included in the second factor, and the count of the abnormal data processing requests is included in the third factor, wherein the formula: first factor count - second factor count - third factor count is used as a global counter to monitor the global variable corresponding to the thread after the switch. The monitoring and counting process of each type of status monitoring factor may include the following steps:
[0061] 1) monitoring the number of data processing requests in the switched thread by presetting a global counter, and determining the count corresponding to the first factor according to the number of data processing requests;
[0062] 2) Monitor whether the request data corresponding to the data processing request in the switched thread is successfully stored through a global counter;
[0063] 3) If the storage is successful, adjust the count corresponding to the status monitoring factor of the second factor;
[0064] 4) Monitor whether data processing requests in the switched thread are handled abnormally through a global counter;
[0065] 5) If the processing is abnormal, adjust the count corresponding to the status monitoring factor of the third factor.
[0066] 305. Obtain the monitoring result of the request state corresponding to the global counter, and determine whether the global variable is greater than the preset variable threshold according to the monitoring result;
[0067] 306. If the global variable is greater than the variable threshold, then after a preset waiting time, re-judgment is made as to whether the global variable is greater than the variable threshold until a preset number of judgments is reached, and it is determined that the global counter does not meet the preset period switching condition;
[0068] 307. If the global variable is less than the variable threshold, it is determined that the global counter meets the cycle switching condition;
[0069] In this embodiment, the global variables in the monitoring results are extracted, and then it is determined whether they are greater than a preset variable threshold. The variable threshold is set according to business needs, and is preferably set to 0, which means that all data processing requests have been processed. In order to ensure that the global variable is 0 when the data processing request is not processed due to an exception, a preset number of judgment cycles are performed, that is, a cycle is performed multiple times to determine whether the global variable is greater than the variable threshold. The interval between each judgment is preset to the waiting time. Preferably, the waiting time can be set to 3 seconds, and the number of judgments can be set to 3 times.
[0070] 308. If the global counter meets the period switching condition, the current time is set as the switching time of the current period, and the request data after storage is marked with the switching time.
[0071] In an embodiment of the present invention, a global counter is used to monitor the request status of a data processing request in a statistical period and is quantified by a state monitoring factor. Meanwhile, a global variable is used to measure whether the global counter satisfies a period switching condition. That is, a global counter is used to realize accurate switching of the statistical period of the data processing request.
[0072] The above describes the data statistical cycle switching method in the embodiment of the present invention. The following describes the data statistical cycle switching device in the embodiment of the present invention. Figure 4 , an embodiment of the data statistics cycle switching device in the embodiment of the present invention includes:
[0073] The switching module 401 is used for performing thread switching on the processing of the data processing request in the preset request queue according to the cycle switching instruction when monitoring the cycle switching instruction sent by the terminal;
[0074] The monitoring module 402 is used to sequentially store the request data corresponding to the data processing request in the switched thread, and monitor the request status of the switched thread through a preset global counter;
[0075] The determination module 403 is used to obtain the monitoring result of the request state corresponding to the global counter, and determine whether the global counter meets the preset period switching condition according to the monitoring result;
[0076] The setting module 404 is used to set the current time as the switching time of the current cycle if the global counter meets the cycle switching condition, and use the switching time to mark the request data after storage.
[0077] In an embodiment of the present invention, the cycle switching instruction sent by the terminal is monitored in real time. When it is monitored, the thread of the data processing request is switched, and the conventional thread of the data processing request is replaced by another thread after the cycle switching to store the requested data and monitor the request status at the same time to determine whether the global counter meets the cycle switching condition, which is used to mark the actual cycle switching time of the requested data after the switching cycle, distinguish the cycle switched data, and avoid missing the data in the current statistical cycle after the statistical cycle is switched.
[0078] See also Figure 5 Another embodiment of the data statistics cycle switching device in the embodiment of the present invention includes:
[0079] The switching module 401 is used for performing thread switching on the processing of the data processing request in the preset request queue according to the cycle switching instruction when monitoring the cycle switching instruction sent by the terminal;
[0080] The monitoring module 402 is used to sequentially store the request data corresponding to the data processing request in the switched thread, and monitor the request status of the switched thread through a preset global counter;
[0081] The determination module 403 is used to obtain the monitoring result of the request state corresponding to the global counter, and determine whether the global counter meets the preset period switching condition according to the monitoring result;
[0082] The setting module 404 is used to set the current time as the switching time of the current cycle if the global counter meets the cycle switching condition, and use the switching time to mark the request data after storage.
[0083] Specifically, the data statistics cycle switching device further includes a temporary storage module 405, which is used to:
[0084] Obtain a new data processing request, and determine whether the new data processing request meets the preset preprocessing conditions;
[0085] If satisfied, obtain request data corresponding to the new data processing request by presetting the first thread, and store the request data corresponding to the new data processing request in a preset temporary data table;
[0086] If not satisfied, the processing exception prompt information corresponding to the new data processing request is returned.
[0087] Specifically, the switching module 401 includes:
[0088] The parsing unit 4011 is used to parse the cycle switching instruction sent by the terminal when monitoring the cycle switching instruction, and obtain the memory address corresponding to the second thread that processes the data processing request in the preset request queue;
[0089] The updating unit 4012 is used to search for the corresponding register according to the memory address, and update the thread pointer and the register pointer in the register to perform thread switching for processing the data processing request.
[0090] Specifically, the monitoring module 402 includes:
[0091] The statistical unit 4021 is used to monitor each state monitoring factor in the switched thread by presetting a global counter, and to count the count corresponding to each state monitoring factor;
[0092] A generating unit 4022 is used to generate a global variable corresponding to the thread after the global counter monitoring switch based on the counts corresponding to each state monitoring factor;
[0093] The monitoring unit 4023 is used to monitor the request status of the switched thread using a global counter according to the global variable.
[0094] Specifically, different types of status monitoring factors include a first factor, a second factor, and a third factor. The statistical unit 4021 is further used for:
[0095] By presetting a global counter, the number of data processing requests in the switched thread is monitored, and according to the number of data processing requests, a count corresponding to the first factor is determined;
[0096] Through the global counter, monitor whether the request data corresponding to the data processing request in the switched thread is successfully stored in the database;
[0097] If the storage is successful, adjust the count corresponding to the second factor;
[0098] Use the global counter to monitor whether the data processing request in the switched thread is abnormal.
[0099] If the processing is abnormal, the count corresponding to the third factor is adjusted.
[0100] Specifically, the determination module 403 includes:
[0101] The determination unit 4031 is used to determine whether the global variable is greater than a preset variable threshold value according to the monitoring result;
[0102] The loop unit 4032 is used to re-determine whether the global variable is greater than the variable threshold after a preset waiting time if the global variable is greater than the variable threshold, until a preset number of determinations is reached, and then determine that the global counter does not meet the preset cycle switching condition;
[0103] The determining unit 4033 is configured to determine whether the global counter meets the periodic switching condition if the global variable is less than the variable threshold.
[0104] In an embodiment of the present invention, after the statistical cycle is switched, for new data processing requests received after the current statistical cycle, the original first thread is still used to store the request data, wherein a temporary data table can be used to temporarily store the request data, and after the request data of the current statistical cycle is subsequently stored, the request data in the temporary data table is stored again, so as to distinguish the request data of different statistical cycles; in addition, a global counter is used to monitor the request status of the data processing request in the statistical cycle, and quantified by a status monitoring factor, and a global variable is used to measure whether the global counter meets the cycle switching condition, that is, the global counter is used to realize accurate switching of the statistical cycle of the data processing request.
[0105] above Figure 4 and Figure 5The data statistical cycle switching device in the embodiment of the present invention is described in detail from the perspective of modular functional entities. The data statistical cycle switching device in the embodiment of the present invention is described in detail from the perspective of hardware processing.
[0106] Figure 6 1 is a schematic diagram of the structure of a data statistics cycle switching device provided by an embodiment of the present invention. The data statistics cycle switching device 600 may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 610 (for example, one or more processors) and a memory 620, and one or more storage media 630 (for example, one or more mass storage devices) storing application programs 633 or data 632. Among them, the memory 620 and the storage medium 630 can be short-term storage or permanent storage. The program stored in the storage medium 630 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the data statistics cycle switching device 600. Furthermore, the processor 610 can be configured to communicate with the storage medium 630 to execute a series of instruction operations in the storage medium 630 on the data statistics cycle switching device 600.
[0107] The data statistics cycle switching device 600 may also include one or more power supplies 640, one or more wired or wireless network interfaces 650, one or more input and output interfaces 660, and / or one or more operating systems 631, such as Windows Serve, Mac OS X, Unix, Linux, FreeBSD, etc. It will be understood by those skilled in the art that Figure 6 The data statistical cycle switching device structure shown does not constitute a limitation on the data statistical cycle switching device, and may include more or fewer components than shown in the figure, or a combination of certain components, or a different arrangement of components.
[0108] The present invention also provides a data statistics cycle switching device, the computer device includes a memory and a processor, the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the processor executes the steps of the data statistics cycle switching method in the above-mentioned embodiments.
[0109] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the data statistical cycle switching method.
[0110] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0111] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program codes.
[0112] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A data statistics cycle switching method, characterized in that: The data statistics cycle switching method comprises: When a cycle switching instruction sent by the terminal is monitored, according to the cycle switching instruction, thread switching is performed on the processing of the data processing request in the preset request queue; In the switched thread, request data corresponding to the data processing request are stored in sequence; each state monitoring factor in the switched thread is monitored by presetting a global counter, and the counts corresponding to each state monitoring factor are counted; based on the counts corresponding to each state monitoring factor, the global variable corresponding to the switched thread is generated by the global counter to monitor the global variable; according to the global variable, the request state of the switched thread is monitored by using the global counter; wherein each state monitoring factor includes a first factor, a second factor and a third factor; Obtaining a monitoring result of the request state corresponding to the global counter; judging whether the global variable is greater than a preset variable threshold value according to the monitoring result; if the global variable is greater than the variable threshold value, re-judging whether the global variable is greater than the variable threshold value after a preset waiting time, until a preset number of judgments is reached, determining that the global counter does not meet a preset period switching condition; if the global variable is less than the variable threshold value, determining that the global counter meets the period switching condition; If the global counter meets the period switching condition, the current time is set as the switching time of the current period, and the request data after storage is marked with the switching time; Among them, the presetting of the global counter to monitor each state monitoring factor in the switched thread and counting the counts corresponding to each state monitoring factor includes: monitoring the number of data processing requests in the switched thread by presetting the global counter, and determining the count corresponding to the first factor according to the number of data processing requests; monitoring whether the request data corresponding to the data processing request in the switched thread is successfully stored in the database by the global counter; if the storage is successful, adjusting the count corresponding to the second factor; monitoring whether the data processing request in the switched thread is processed abnormally by the global counter; if the processing is abnormal, adjusting the count corresponding to the third factor.
2. The data statistics cycle switching method according to claim 1, characterized in that: After performing thread switching on the processing of the data processing request in the preset request queue according to the cycle switching instruction when the cycle switching instruction sent by the terminal is monitored, the method further includes: Obtaining a new data processing request, and determining whether the new data processing request satisfies a preset preprocessing condition; If satisfied, obtaining request data corresponding to the new data processing request by presetting a first thread, and storing the request data corresponding to the new data processing request in a preset temporary data table; If not satisfied, the processing exception prompt information corresponding to the new data processing request is returned.
3. The data statistics cycle switching method according to claim 1, characterized in that: When a cycle switching instruction sent by the terminal is monitored, switching threads for processing the data processing request in the preset request queue according to the cycle switching instruction includes: When a cycle switching instruction sent by the terminal is monitored, the cycle switching instruction is parsed to obtain a memory address corresponding to a second thread that processes a data processing request in a preset request queue; According to the memory address, the corresponding register is searched, and the thread pointer and the register pointer in the register are updated to perform thread switching for processing the data processing request.
4. A data statistics cycle switching device, characterized in that: The data statistics cycle switching device comprises: A switching module, for performing thread switching on the processing of data processing requests in a preset request queue according to the cycle switching instruction when monitoring the cycle switching instruction sent by the terminal; A monitoring module, used to sequentially store the request data corresponding to the data processing request in the switched thread; monitor each state monitoring factor in the switched thread by presetting a global counter, and count the counts corresponding to each state monitoring factor; generate a global variable corresponding to the switched thread by the global counter based on the counts corresponding to each state monitoring factor; and monitor the request state of the switched thread using the global counter according to the global variable; wherein each state monitoring factor includes a first factor, a second factor and a third factor; A determination module, used for obtaining a monitoring result of a request state corresponding to the global counter; judging whether the global variable is greater than a preset variable threshold value according to the monitoring result; if the global variable is greater than the variable threshold value, re-judging whether the global variable is greater than the variable threshold value after a preset waiting time, until a preset number of judgments is reached, determining that the global counter does not meet a preset period switching condition; if the global variable is less than the variable threshold value, determining that the global counter meets the period switching condition; A setting module, configured to set the current time as the switching time of the current cycle if the global counter meets the cycle switching condition, and use the switching time to mark the request data after storage; Among them, the presetting of the global counter to monitor each state monitoring factor in the switched thread and counting the counts corresponding to each state monitoring factor includes: monitoring the number of data processing requests in the switched thread by presetting the global counter, and determining the count corresponding to the first factor according to the number of data processing requests; monitoring whether the request data corresponding to the data processing request in the switched thread is successfully stored in the database by the global counter; if the storage is successful, adjusting the count corresponding to the second factor; monitoring whether the data processing request in the switched thread is processed abnormally by the global counter; if the processing is abnormal, adjusting the count corresponding to the third factor.
5. The data statistics cycle switching device according to claim 4, characterized in that: The data statistics cycle switching device also includes a temporary storage module, which is used to: Obtaining a new data processing request, and determining whether the new data processing request satisfies a preset preprocessing condition; If satisfied, obtaining request data corresponding to the new data processing request by presetting a first thread, and storing the request data corresponding to the new data processing request in a preset temporary data table; If not satisfied, the processing exception prompt information corresponding to the new data processing request is returned.
6. A data statistics cycle switching device, characterized in that: The data statistics cycle switching device comprises: a memory and at least one processor, wherein instructions are stored in the memory; The at least one processor calls the instruction in the memory to enable the data statistical cycle switching device to perform the steps of the data statistical cycle switching method as described in any one of claims 1-3.
7. A computer-readable storage medium having instructions stored thereon, characterized in that: When the instruction is executed by the processor, the steps of the data statistics cycle switching method as described in any one of claims 1-3 are implemented.
Citation Information
Patent Citations
Database performance monitoring method and apparatus, storage medium and computer device
CN107908518A
Forwarding table state switching method and device, and communication device
CN109194500A
Thread monitoring method and system, equipment and medium
CN112631858A
Method and apparatus for altering thread priorities in a multithreaded processor
WO1999021089A1
