QPS statistical method and device for distributed system, computer device and medium
The statistical method of dividing the query time period into K query sub-time periods solves the problem in the existing technology, which divides the query time period into K query sub-time periods, uses mapping rules to determine the key name and key value corresponding to the request timestamp, reads the maximum key value within the query sub-time period, and calculates the mean or weighted mean of the K query sub-time periods to determine the QPS value, thus improving the statistical accuracy and efficiency of QPS.
Patent Information
- Application Number
- CN202210920976.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-02
- Publication Date
- 2025-12-19
- Estimated Expiration
- 2042-08-02
AI Technical Summary
In high-concurrency distributed systems, existing technologies struggle to improve statistical accuracy while maintaining QPS statistical efficiency, especially when the query time period is short, resulting in low QPS statistical accuracy.
By dividing the query time period into K query sub-time periods, using mapping rules to determine the key name and key value corresponding to the request timestamp, reading the maximum key value within the query sub-time period, and calculating the average or weighted average of the K query sub-time periods to determine the QPS value, direct query and calculation operations are avoided.
In high-concurrency distributed systems, the statistical efficiency and accuracy of QPS are improved, simultaneous statistics are achieved for multiple target server interfaces, and the load representation problem caused by uneven distribution of request timestamps during the query period is solved.
Smart Images

Figure CN115237984B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer and network, and particularly relates to a QPS statistical method and device for a distributed system, a computer device and a medium. BACKGROUND
[0002] Queries Per Second (QPS) is a measurement standard for the request flow of a target server interface within a specified time. At present, the QPS is usually obtained by a query method, that is, a query time period is determined by a preset time stamp, the number of requests within the query time period is accumulated, and the ratio of the accumulated result to the length of the query time period is the QPS.
[0003] However, the query method needs to query and calculate all the request records within the query time period. In a high-concurrency and distributed system, the query and calculation method will consume a large amount of time, resulting in low QPS statistical efficiency. In order to solve the above problem, the query time period needs to be shortened, thereby reducing the query consumption. However, in the case of a short query time period, the query and calculation method is difficult to effectively represent the load condition of the interface, and the statistical accuracy of the QPS is low. Therefore, how to improve the statistical accuracy of the QPS while ensuring the statistical efficiency of the QPS has become a problem to be solved. SUMMARY
[0004] Therefore, the embodiments of the present application provide a QPS statistical method and device for a distributed system, a computer device and a medium, so as to solve the problem of low QPS statistical accuracy while ensuring the statistical efficiency of the QPS.
[0005] In a first aspect, the embodiments of the present application provide a QPS statistical method for a distributed system, which comprises the following steps:
[0006] determining a server interface to be counted in a distributed system as a target server interface, obtaining a query time stamp of the target server interface, determining a query time period according to the query time stamp, and dividing the query time period into K query sub-time periods with a preset sub-time period length, K being an integer greater than zero;
[0007] determining a time stamp corresponding to a request received by the target server interface as a request time stamp, mapping a key name according to the request time stamp by using a preset mapping rule, and determining a key value corresponding to the key name according to the receiving time order of the request within the query time period to which the request time stamp belongs;
[0008] reading a maximum key value of all request timestamp corresponding key names in the query sub time period, and determining the maximum key value as the QPS value of the query sub time period;
[0009] calculating a mean value of the QPS values corresponding to the K query sub time periods, and determining the mean value as the QPS value of the query time period.
[0010] In a second aspect, an embodiment of the present application provides a QPS statistical device for a distributed system, the QPS statistical device comprising:
[0011] a time division module configured to determine a server interface to be counted in the distributed system as a target server interface, acquire a query timestamp of the target server interface, determine a query time period according to the query timestamp, and divide the query time period into K query sub time periods according to a preset sub time period length, K being an integer greater than zero;
[0012] a request mapping module configured to determine a timestamp corresponding to a request received by the target server interface as a request timestamp, map a key name according to the request timestamp by using a preset mapping rule, and determine a key value corresponding to the key name according to a receiving time order of the request in the query time period to which the request timestamp belongs;
[0013] a key value query module configured to read a maximum key value of all request timestamp corresponding key names in any query sub time period, and determine the maximum key value as the QPS value of the query sub time period;
[0014] a mean value calculation module configured to calculate a mean value of the QPS values corresponding to the K query sub time periods, and determine the mean value as the QPS value of the query time period.
[0015] In a third aspect, an embodiment of the present application provides a computer device, the computer device comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, the processor implementing the QPS statistical method of the first aspect when executing the computer program.
[0016] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, the computer readable storage medium storing a computer program, the computer program being executable by a processor to implement the QPS statistical method of the first aspect.
[0017] Compared with the prior art, the embodiment of the present application has the following beneficial effects:
[0018] The target server interface to be counted in the distributed system is determined, the query timestamp of the target server interface is obtained, the query time period is determined according to the query timestamp, the query time period is divided into K query sub-time periods in a preset sub-time period length, the timestamp corresponding to the request received by the target server interface is determined as a request timestamp, the key name is obtained by using a preset mapping rule according to the request timestamp, the key value corresponding to the key name is determined according to the receiving time order of the request in the query time period to which the request timestamp belongs, for any query sub-time period, the maximum key value of the key name corresponding to all request timestamps in the query sub-time period is read, and the maximum key value is determined as the QPS value of the query sub-time period, the mean value of the QPS values corresponding to the K query sub-time periods is calculated, and the mean value is determined as the QPS value of the query time period, the QPS value of the query sub-time period is directly obtained by reading the key name and the key value obtained by mapping in the request receiving process, without the need for query and calculation operations, in the high-concurrency distributed system, the QPS of multiple target server interfaces can be simultaneously counted, the statistical efficiency of the QPS in the system is greatly improved, and the QPS calculation is performed in the form of query time period segmentation, so that the problem that the QPS is difficult to effectively guarantee the interface load due to uneven distribution of request timestamps in the query time period is avoided, and the statistical accuracy of the QPS is improved. BRIEF DESCRIPTION OF DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without creative labor.
[0020] Figure 1 is an application environment schematic diagram of a QPS statistical method for a distributed system provided by an embodiment of the present application;
[0021] Figure 2 is a flowchart of a QPS statistical method for a distributed system provided by an embodiment of the present application;
[0022] Figure 3 is a flowchart of a QPS statistical method for a distributed system provided by an embodiment of the present application;
[0023] Figure 4 is a structural schematic diagram of a QPS statistical device for a distributed system provided by an embodiment of the present application;
[0024] Figure 5 is a structural schematic diagram of a computer device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0025] In the following description, for purposes of explanation and not limitation, specific details are set forth such as particular architectures, techniques, etc. in order to provide a thorough understanding of the embodiments of the present application. However, it will be apparent to those skilled in the art that the present application can be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known methods, devices, circuits, and
[0026] It will be understood that the terms "comprises" and / or "comprising," when used in this specification, include the presence of one or more features, integers, steps, operations, elements, and / or components described in the specification, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0027] It will be understood that the term "and / or," when used in the specification and in the following claims, is intended to mean one or more of the associated listed items can be present, and includes the possibilities of one or more of the associated listed items being present, and all possible combinations of the associated listed items.
[0028] As used in the description of the application and the following claims, the term "if" can be interpreted to mean "when" or "upon" or "in response to determining" or "in response to detecting" depending on the context. Similarly, the phrase "if it is determined" or "if [a described condition or event] is detected" can be interpreted to mean "upon determining" or "in response to determining" or "upon detecting [the described condition or event]" or "in response to detecting [the described condition or event]".
[0029] In addition, the description in the specification of the application and the appended claims, the terms "first," "second," "third," etc. are used merely as labels, and are not intended to signify relative importance or significance.
[0030] Reference in the specification to "one embodiment" or "an embodiment" or "some embodiments" means that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment of the application. The appearances of the phrase "in one embodiment" or "in some embodiments" in various places in the specification are not necessarily all referring to the same embodiment, although it can. The terms "including," "comprising," "having" and variations thereof are meant to encompass the items listed thereafter and equivalents thereof as well as additional items. The terms "coupled" and "connected," as well as variations thereof, are intended to encompass a connection between two or more entities that is resistant to a pulling force, except as can be explicitly described herein.
[0031] It should be understood that the size of the serial number of each step in the following embodiment does not mean the order of execution, and the execution order of each process should be determined by its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiment of the application.
[0032] In order to illustrate the technical solutions of the present application, the following will be illustrated by specific embodiments.
[0033] The QPS statistical method for a distributed system provided by the embodiment one of the present application can be applied in the application environment of Figure 1 , wherein the client communicates with the server. The client includes but is not limited to a palm computer, a desktop computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a cloud terminal device, a personal digital assistant (PDA) and the like. The server can be realized by a server cluster composed of multiple distributed servers in the distributed system.
[0034] Referring to Figure 2 , it is a flowchart of the QPS statistical method for a distributed system provided by the embodiment one of the present application. The QPS statistical method can be applied to the client in Figure 1 , and the computer device corresponding to the client is connected to each distributed server interface in the server to obtain the query timestamp of the distributed server interface and the request timestamp when the request is received. The server interface includes a key-value database, and the key-value database is used to store the key name and key value data generated by the server interface when the request is received, and the key name and key value data are used to determine the QPS value. As shown in Figure 2 , the QPS statistical method for a distributed system can include the following steps:
[0035] Step S201, determining the server interface to be counted in the distributed system as a target server interface, obtaining the query timestamp of the target server interface, determining the query time period according to the query timestamp, and dividing the query time period into K query sub-time periods with a preset sub-time period length.
[0036] The distributed system can be composed of multiple independent computers, and there is a unified communication mechanism between the multiple independent computers, and the multiple independent computers can process tasks in parallel. In the embodiment, the distributed system is composed of multiple distributed servers.
[0037] The server interface to be counted can refer to a server interface to be counted for QPS. QPS can refer to Queries Per Second, which is a measurement of request traffic of a target server interface within a specified time. QPS can be used as an index for performance evaluation of a server interface, and can be used to represent the load capacity of the server interface. The target server interface can refer to a server interface to be evaluated for performance. Due to the parallelism of the distributed system, QPS can be counted for multiple server interfaces at the same time, that is, multiple target server interfaces can exist at the same time. For ease of description, a single target server interface is taken as an example in this embodiment.
[0038] The query timestamp can refer to a time point for determining a query time period. The query time period can refer to a time interval for which QPS is to be calculated. The sub-time period length can refer to a unit length when the query time period is divided into sub-time periods. K is an integer greater than zero.
[0039] Specifically, the query timestamp can include a query start timestamp or a query end timestamp. When the query timestamp is the query start timestamp and the query end timestamp, the query start timestamp is taken as the starting time point of the query time period and the query end timestamp is taken as the ending time point of the query time period to obtain the query time period. When the query timestamp is the query start timestamp, the query start timestamp is taken as the starting time point of the query time period, and the ending time point is determined according to the starting time point and a preset time period length to obtain the query time period. When the query timestamp is the query end timestamp, the query start timestamp is taken as the ending time point of the query time period, and the starting time point is determined according to the ending time point and a preset time period length to obtain the query time period.
[0040] In this embodiment, the sub-time period length is set to 2s. The implementer can adjust the preset value of the sub-time period length according to the actual situation. For example, the query start timestamp is 12:12:12 and the query end timestamp is 12:12:18. The query time period is 12:12:12-12:12:18. Since the sub-time period length is set to 2s and the query time period length is 6s, the length of the divided query sub-time period is determined according to the ratio of the query time period length to the sub-time period length. Therefore, the value of K is 3.
[0041] It should be noted that when the ratio of the query time period length to the sub-time period length is not an integer, the remainder of the ratio is obtained by taking the remainder operation. The remainder result is divided into a query sub-time period. The ratio of the query time period length minus the remainder result to the sub-time period length is k. Therefore, K=k+1, and k is an integer greater than zero and less than K.
[0042] Optionally, before dividing the query time period into K query sub-time periods with a preset sub-time period length, the method further comprises:
[0043] determining a set of associated interfaces of the target server interface according to a known association relationship between interfaces in the distributed system, the set of associated interfaces comprising at least one associated interface;
[0044] determining the to-be-updated sub-time period length according to a length of an associated sub-time period corresponding to each associated interface in the set of associated interfaces;
[0045] updating the sub-time period length to the to-be-updated sub-time period length when the to-be-updated sub-time period length meets a preset condition.
[0046] The known association relationship can refer to a concurrency relationship between server interfaces in the distributed system, that is, when one server interface receives a request, another server interface also receives a request, and it is considered that the two server interfaces have a concurrency relationship. The concurrency relationship is known by default and can be determined by comparing request time stamps between server interfaces.
[0047] The set of associated interfaces can refer to a set of all server interfaces having an association relationship with the target server interface, and the elements in the set are the associated interfaces.
[0048] The length of the associated sub-time period can refer to the sub-time period length set by the associated interface, and the to-be-updated sub-time period length can refer to the sub-time period length to which the sub-time period length of the target server interface is to be updated. The preset condition can be used to measure whether the to-be-updated sub-time period can effectively improve the accuracy of QPS statistics.
[0049] The embodiment determines the to-be-updated sub-time period length according to the length of the associated sub-time period of the associated interface, and obtains a better sub-time period length through a consensus mechanism, which is conducive to improving the representation ability of the query sub-time period and thus improving the accuracy of QPS statistics.
[0050] Optionally, the to-be-updated weight corresponding to the to-be-updated sub-time period length is initialized to zero.
[0051] When the to-be-updated sub-time period length meets the preset condition, updating the sub-time period length to the to-be-updated sub-time period length comprises:
[0052] iterating the length of the associated sub-time period corresponding to each associated interface, comparing the to-be-updated sub-time period length with the length of the associated sub-time period, and if the comparison result is consistent, obtaining the associated interface weight of the corresponding associated interface and increasing the associated interface weight to the to-be-updated weight;
[0053] The detection is made on whether the to-be-updated weight is greater than a preset weight threshold. If the to-be-updated weight is greater than the weight threshold, it is determined that the to-be-updated sub time period length satisfies the preset condition, and the sub time period length is updated to the to-be-updated sub time period length.
[0054] The association interface weight can refer to the influence degree of the association interface on the to-be-updated sub time period length determination process, and the to-be-updated weight can refer to the weight of the to-be-updated sub time period length, which is used for comparison with the preset weight threshold to determine whether the to-be-updated sub time period length is reliable enough.
[0055] Specifically, after selecting any one of the associated sub time period lengths as the to-be-updated sub time period length, the to-be-updated sub time period length is compared with the associated sub time period lengths. If the final value of the to-be-updated weight does not satisfy the preset condition, the to-be-updated sub time period length is reselected until the to-be-updated weight satisfying the preset condition is obtained or all the associated sub time period lengths have been selected.
[0056] In this embodiment, the weight threshold is determined according to the number of association interfaces. That is, if the number of association interfaces is M, the weight threshold is determined as
[0057] In an embodiment, the implementer can manually preset the weight threshold, for example, set to 20.
[0058] In this embodiment, the corresponding association weight is determined for each association interface, so as to improve the influence degree of the associated sub time period length with a stronger association degree on the to-be-updated sub time period length, and avoid the to-be-updated sub time period length deviating from the optimal length due to the associated sub time period length with a weaker association degree, so as to further improve the accuracy of QPS statistics.
[0059] Optionally, after it is determined that the to-be-updated sub time period length satisfies the preset condition, the method further includes:
[0060] For any association interface, if the comparison result of the association interface corresponding associated sub time period length and the to-be-updated sub time period length is consistent, the influence times of the association interface are obtained, and the influence times are increased by one to obtain updated influence times.
[0061] The updated influence times are mapped to the updated weight through a normalization mapping function, and the association interface weight corresponding to the association interface is updated to the updated weight.
[0062] The influence times can refer to the number of times that the association interface effectively influences the determination of the to-be-updated sub time period length in the historical process, and the updated influence times can refer to the number of times that the association interface effectively influences the determination of the to-be-updated sub time period length.
[0063] Specifically, for any associated interface, if the ratio of the length of the associated sub-time period corresponding to the associated interface to the length of the to-be-updated sub-time period is inconsistent with the ratio of the length of the associated sub-time period corresponding to the associated interface to the length of the to-be-updated sub-time period, it is determined that the influence number corresponding to the associated interface is the update influence number.
[0064] The formula of the normalized mapping function is Wherein, m can refer to the associated interface identifier, m' can refer to the identifier of the associated interface corresponding to the to-be-mapped update influence number, M can refer to the number of associated interfaces, c m′ may refer to the update influence number of the m'th associated interface, c m may refer to the update influence number of the m'th associated interface.
[0065] The embodiment dynamically updates the weights of the associated interfaces, thereby improving the influence degree of each associated interface on the length of the to-be-updated sub-time period in real time, avoiding the possible change of the association degree between interfaces, and causing the determined length of the to-be-updated sub-time period to be inaccurate, thereby effectively improving the characterization ability of QPS to the load capacity, that is, improving the accuracy of QPS statistics.
[0066] Optionally, after determining the maximum key value as the QPS value of the query sub-time period, the method further comprises:
[0067] For any query sub-time period, the starting time point of the query sub-time period and the QPS value of the query sub-time period constitute a query element corresponding to the query sub-time period;
[0068] According to the time order of the starting time points of all query sub-time periods, all query elements corresponding to the query time periods are spliced, and the splicing result is determined as a query vector;
[0069] For any non-associated interface corresponding to a reference query vector that does not belong to the set of associated interfaces of the target server interface, the similarity between the query vector and the reference query vector is calculated, and if the similarity meets a preset condition, the non-associated interface is added to the set of associated interfaces.
[0070] Wherein, the starting time point can refer to the starting time of the query sub-time period, the query element can be a representation form of QPS information, and the query vector can be used to represent the QPS value change information of the query time period over time.
[0071] The reference query vector can be the QPS value change information of the non-associated interface over time, the similarity can be used to represent the similarity between the vectors, and the preset condition can be used to measure whether the reference query vector is similar enough to the query vector.
[0072] Specifically, in the embodiment, the similarity calculation method can adopt cosine similarity, and the cosine similarity calculation method is Wherein, β is the cosine similarity calculation result of the query vector and the reference query vector, v1 can refer to the query vector, v2 can refer to the reference query vector, |v1| can refer to the modulus of the query vector, and |v2| can refer to the modulus of the reference query vector.
[0073] The preset condition can be greater than the similarity threshold, that is, if the similarity is greater than the similarity threshold, the non-associated interface is added to the associated interface set, if the similarity is less than or equal to the similarity threshold, the non-associated interface is not added to the associated interface set, and the similarity threshold is set to 0.75 in this embodiment. The implementer can adjust the similarity threshold according to the actual situation.
[0074] This embodiment updates the associated interface set in real time, thereby effectively adapting to the task changes of the distributed server interface, and mining the potential association between the server interfaces, thereby effectively improving the representation ability of QPS to the load capacity, that is, improving the accuracy of QPS statistics.
[0075] The above steps of determining the server interface to be counted in the distributed system as the target server interface, obtaining the query timestamp of the target server interface, determining the query time period according to the query timestamp, and dividing the query time period into K query sub-time periods according to the preset sub-time period length, can flexibly query the target server interface, can adapt to the characteristics of high concurrency in the distributed system, reduce the resource consumption when multiple target server interfaces perform QPS statistics in parallel, and improve the efficiency of QPS statistics.
[0076] In step S202, the timestamp corresponding to the request received by the target server interface is determined as the request timestamp, the key name is mapped according to the preset mapping rule according to the request timestamp, and the key value corresponding to the key name is determined according to the receiving time order of the request in the query time period to which the request timestamp belongs.
[0077] Wherein, the request can include request specification information, request data processing on specified data, request to replace specified document content, request to delete specified information, etc., and the timestamp corresponding to the request can be the time point when the target server interface receives the request.
[0078] The preset mapping rule can be a mapping table, a mapping function and a neural network model, which is used to map the request timestamp into data in the same encoding format, so as to facilitate storage and search, the key name can be the mapping data of the request timestamp in the query sub-time period according to the preset mapping rule, and the key value can be the sorting sequence number of the request in the query sub-time period according to the time order.
[0079] Specifically, when receiving a request, the target server interface determines the time point of receiving the request as the request timestamp corresponding to the request, and detects whether the request timestamp and the last request timestamp are in the same query sub-time period. If the current request timestamp and the last request timestamp are in the same query sub-time period, the key name corresponding to the current request timestamp is the same as the key name corresponding to the last request timestamp, and the key value corresponding to the key name is increased by 1. For example, the key name corresponding to the last request timestamp is 1653192732, and the key value is 1. It is detected that the request timestamp and the last request timestamp are in the same query sub-time period, so the key name corresponding to the current request timestamp is also 1653192732, and the key value is 2.
[0080] If the current request timestamp and the last request timestamp are not in the same query sub-time period, the key name and the key value corresponding to the last request timestamp are added, the addition result is determined as the key name corresponding to the current request timestamp, and the key value of the key name corresponding to the current request timestamp is determined as 1. For example, the key name corresponding to the last request timestamp is 1653192732, and the key value is 2. It is detected that the current request timestamp and the last request timestamp are not in the same query sub-time period, so the key name corresponding to the current request timestamp is 1653192734, and the key value is 1.
[0081] In the embodiment, the key name can be obtained by mapping the mapping table. Since the above process can obtain the key name by calculation without mapping, only the key name corresponding to the first received request needs to be determined. The mapping method of the key name corresponding to the first received request is obtained according to the target server interface identifier and the request timestamp corresponding to the first received request. The target server interface identifier can be the machine code corresponding to the target server interface, the IP address corresponding to the target server interface, etc. The target server interface identifier is compared with the identifier in the mapping table, the mapping result corresponding to the identifier consistent with the comparison result is taken as the first mapping result corresponding to the target server interface identifier, and the request timestamp is compared with the timestamp in the mapping table in the same way. The mapping result corresponding to the timestamp consistent with the comparison result is taken as the second mapping result corresponding to the request timestamp. The first mapping result and the second mapping result are spliced to obtain the key name corresponding to the first received request.
[0082] From the above mapping rule, it can be seen that the key names corresponding to the requests in the same query sub-time period are consistent. It should be noted that in the embodiment, the key name and the key value can not be in a one-to-one correspondence, that is, the same key name can correspond to multiple key values. At this time, only the maximum key value of the key name corresponding to a query sub-time period needs to be read to obtain the number of received requests in the query sub-time period.
[0083] In an embodiment, the key name and the key value can be in one-to-one correspondence, that is, one key name corresponds to one key value, and after the key value is calculated, the calculation result is used to update the key value of the corresponding key name. At this time, only the key value of the key name corresponding to the query sub-time period needs to be read to obtain the number of requests received by the query sub-time period. This method is beneficial to reduce the storage pressure of the key value database and improve the utilization efficiency of the storage space of the key value database.
[0084] The request timestamp received by the target server interface is determined as the request timestamp, the key name is mapped by using a preset mapping rule according to the request timestamp, and the key value corresponding to the key name is determined according to the receiving time order of the requests in the query time period to which the request timestamp belongs. The request timestamp is mapped into the key name by using the preset mapping rule, and the corresponding key value is obtained. The receiving information of the requests is recorded synchronously by using the key value database, which is convenient for directly obtaining the QPS value in the subsequent process, and effectively improves the efficiency of the subsequent QPS statistics.
[0085] In step S203, for any query sub-time period, the maximum key value of the key name corresponding to all request timestamps in the query sub-time period is read, and the maximum key value is determined as the QPS value of the query sub-time period.
[0086] The key name corresponding to all request timestamps in the query sub-time period is the same key name, and the maximum key value can be the maximum value in the key value corresponding to the key name.
[0087] Specifically, in the key value database, data is stored in the form of a matrix of P*2, wherein the data stored in the first column is key name data, the data stored in the second column is key value data, and the key name data and the key value data in a row are used to represent the information of a request. For a single query sub-time period, the key name corresponding to all request timestamps in the query sub-time period is consistent, for example, the p1th row, the p2th row and the p3th row correspond to requests belonging to the same query sub-time period, then the first column elements of the p1th row, the p2th row and the p3th row are consistent, the second column element of the p1th row is 1, the second column element of the p2th row is 2, and the second column element of the p3th row is 3. Correspondingly, the maximum key value of the key name corresponding to all request timestamps in the query sub-time period is 3, and 3 is the QPS value of the query sub-time period.
[0088] The step of reading the maximum key value of the key name corresponding to all request timestamps in the query sub-time period for any query sub-time period, and determining the maximum key value as the QPS value of the query sub-time period, only needs to access the key value database to directly read the key value to calculate the QPS value, without the need to query and accumulate statistics for each received request, thereby effectively improving the efficiency of QPS statistics.
[0089] In step S204, the average of the QPS values corresponding to the K query sub-time periods is calculated, and the average is determined as the QPS value of the query time period.
[0090] Wherein, the calculation method of the mean value is Wherein, μ can refer to the mean value calculation result, Q k Can refer to the QPS value corresponding to the kth query sub-time period.
[0091] The above calculates the mean value of the QPS values corresponding to the K query sub-time periods, and determines the mean value as the QPS value of the query time period. The QPS value of the query time period is determined through the QPS values corresponding to the K query sub-time periods, which avoids the case that the direct statistics of the QPS value is affected by the length of the query time period, resulting in incomplete request information statistics, and further resulting in low accuracy of QPS statistics, thereby improving the accuracy of QPS statistics.
[0092] In this embodiment, the key name and key value obtained by mapping during the request receiving process are read to directly obtain the QPS value of the query sub-time period, without the need for query and calculation operations. In a high-concurrency distributed system, the QPS statistics can be supported simultaneously through multiple target server interfaces, greatly improving the statistical efficiency of QPS in the system. At the same time, the QPS is calculated in the form of query time period segmentation, avoiding the problem that the QPS is difficult to effectively guarantee the interface load due to the uneven distribution of request timestamps in the query time period, and improving the statistical accuracy of QPS.
[0093] Referring to Figure 3 It is a flowchart of a QPS statistical method for a distributed system provided by the second embodiment of the present application. In the QPS statistical method, the QPS value of the query time period can be obtained by calculating the mean value of the QPS values corresponding to the K query sub-time periods, or by calculating the weighted mean value of the QPS values corresponding to the K query sub-time periods.
[0094] When the QPS value of the query time period is calculated by calculating the mean value of the QPS values corresponding to the K query sub-time periods, the calculation process is described in Embodiment 1 and will not be repeated here.
[0095] When the QPS value of the query time period is calculated by calculating the weighted mean value of the QPS values corresponding to the K query sub-time periods, the calculation process includes:
[0096] Step S301, multiplying the QPS value corresponding to each query sub-time period by a preset interest weight to obtain a weighted QPS value;
[0097] Step S302, calculating the mean value of all weighted QPS values, and determining the mean value as the QPS value of the query time period.
[0098] Wherein, the interest weight can refer to the degree of attention to the query sub-time period, and the weighted QPS value can refer to the QPS value adjusted by the interest weight.
[0099] Specifically, the weighted mean is calculated in the following manner wherein μ can refer to the result of the weighted mean calculation, Q k may refer to the QPS value corresponding to the kth query sub-time period, w k may refer to the interest weight corresponding to the kth query sub-time period. The introduction of the interest weight is conducive to improving the representation ability of QPS and paying more attention to the QPS of the key time period. For example, there is an access peak period for the server interface, and the load capacity of the server interface needs to be accurately evaluated during the access peak period to allocate sufficient computing resources to each server interface. During the non-access peak period, the server computing resources are relatively sufficient, and the interest weight can be lower.
[0100] The embodiment adjusts the influence degree of the QPS value of different query sub-time periods on the QPS value of the query time period through the weighted manner, thereby improving the representation ability of the query time period QPS on the load performance.
[0101] Optionally, before multiplying the QPS value corresponding to each query sub-time period by the preset interest weight, the following is further included:
[0102] obtaining the historical QPS value of the target server interface, and obtaining the interest weight corresponding to each time point by using a preset mapping function according to the historical QPS value;
[0103] For any query sub-time period, the interest weight mean of the time points included in the query sub-time period is calculated, and the calculation result is determined as the preset interest weight of the query sub-time period.
[0104] wherein the historical QPS value can refer to the QPS value of the target server interface in the historical time period before the query time period, the preset mapping function can be used to map the QPS value to a normalized value to improve the calculation efficiency, and the time point can refer to a time point with a preset step length.
[0105] Specifically, the QPS value of each time point in the statistical time period corresponding to the historical QPS value is consistent with the QPS value of the statistical time period, the QPS mean value corresponding to each time point is calculated, and the QPS mean value is input as an input quantity into the preset mapping function. The preset mapping function can be wherein Q'g g is the QPS mean value of the gth time point, f(Q'g g ) is the mapping value of the QPS mean value of the gth time point, max(Q'1, …, Q'g G ) is the maximum value of the QPS mean values of all G time points.
[0106] The embodiment determines the interest weight according to the historical QPS value of the server interface, has strong generalization ability, does not need to manually set different interest weights for different task server interfaces, dynamically updates, guarantees the effectiveness of the interest weight, and is beneficial to improving the accuracy of QPS statistics.
[0107] The QPS statistical method for the distributed system according to the embodiment, Figure 4 A structural block diagram of the QPS statistical device for the distributed system provided by the third embodiment of the application is shown, the QPS statistical device is applied to a client, a computer device corresponding to the client is connected to each distributed server interface in a server to obtain a query timestamp of the distributed server interface and a request timestamp when a request is received, the server interface includes a key-value database, the key-value database is used to store a key name and key value data generated by the server interface when the request is received, the key name and the key value data are used to determine a QPS value, for the convenience of description, only parts related to the embodiments of the application are shown.
[0108] Referring to Figure 4 The QPS statistical device includes:
[0109] The time division module 41 is configured to determine a server interface to be counted in the distributed system as a target server interface, obtain a query timestamp of the target server interface, determine a query time period according to the query timestamp, and divide the query time period into K query sub-time periods according to a preset sub-time period length, K being an integer greater than zero;
[0110] The request mapping module 42 is configured to determine a timestamp corresponding to a request received by the target server interface as a request timestamp, map a key name according to a preset mapping rule according to the request timestamp, and determine a key value corresponding to the key name according to a receiving time sequence of the request in the query time period to which the request timestamp belongs;
[0111] The key value query module 43 is configured to read a maximum key value of the key name corresponding to all request timestamps in any query sub-time period, and determine the maximum key value as a QPS value of the query sub-time period;
[0112] The mean value calculation module 44 is configured to calculate a mean value of the QPS values corresponding to the K query sub-time periods, and determine the mean value as a QPS value of the query time period.
[0113] Optionally, the QPS statistical device further includes:
[0114] The interface association module is configured to determine an associated interface set of the target server interface according to a known association relationship between interfaces in the distributed system, the associated interface set including at least one associated interface;
[0115] The updating length determination module is configured to determine the to-be-updated sub-time period length according to the associated sub-time period length corresponding to each associated interface in the associated interface set;
[0116] The length updating module is configured to update the sub-time period length to the to-be-updated sub-time period length when the to-be-updated sub-time period length satisfies the preset condition.
[0117] Optionally, the to-be-updated weight corresponding to the to-be-updated sub-time period length is initialized to zero.
[0118] The length updating module includes:
[0119] The length comparison unit is configured to traverse the associated sub-time period length corresponding to each associated interface, compare the to-be-updated sub-time period length with the associated sub-time period length, and if the comparison result is consistent, obtain the associated interface weight of the corresponding associated interface and increase the associated interface weight to the to-be-updated weight.
[0120] The threshold comparison unit is configured to detect whether the to-be-updated weight is greater than a preset weight threshold, and if the to-be-updated weight is greater than the weight threshold, determine that the to-be-updated sub-time period length satisfies the preset condition and update the sub-time period length to the to-be-updated sub-time period length.
[0121] Optionally, the associated interface corresponds to an influence frequency.
[0122] The length updating module further includes:
[0123] The frequency counting unit is configured to, for any associated interface, if the comparison result of the associated sub-time period length corresponding to the associated interface and the to-be-updated sub-time period length is consistent, obtain the influence frequency of the associated interface and increase the influence frequency by one to obtain an updated influence frequency.
[0124] The weight updating unit is configured to map the updated influence frequency to an updated weight through a normalization mapping function and update the associated interface weight corresponding to the associated interface to the updated weight.
[0125] Optionally, the QPS counting device further includes:
[0126] The element construction module is configured to, for any query sub-time period, construct a query element corresponding to the query sub-time period with the start time point of the query sub-time period and the QPS value of the query sub-time period.
[0127] The element splicing module is configured to splice the query elements corresponding to all query sub-time periods according to the time sequence of the start time points of the query sub-time periods to determine a splicing result as a query vector.
[0128] The collection updating module is configured to calculate the similarity between the query vector and a reference query vector corresponding to any non-associated interface that does not belong to the associated interface set of the target server interface, and add the non-associated interface to the associated interface set if the similarity meets a preset condition.
[0129] Optionally, the mean value calculation module 44 includes:
[0130] The weighted calculation unit is configured to multiply the QPS value corresponding to each query sub-time period by a preset interested weight to obtain a weighted QPS value.
[0131] The weighted mean value calculation unit is configured to calculate the mean value of all weighted QPS values and determine the mean value as the QPS value of the query time period.
[0132] Optionally, the mean value calculation module 44 further includes:
[0133] The weight mapping unit is configured to obtain a historical QPS value of the target server interface, and obtain the interested weight corresponding to each time point by using a preset mapping function according to the historical QPS value.
[0134] The weight determination unit is configured to calculate the mean value of the interested weights corresponding to the time points included in any query sub-time period, and determine the calculation result as the preset interested weight of the query sub-time period.
[0135] It should be noted that the information interaction and execution process between the above modules and units are based on the same concept as the method embodiments of the present application, and the specific functions and technical effects brought by them can be referred to the method embodiments part, which will not be repeated here.
[0136] Figure 5 A structural schematic diagram of a computer device according to the fourth embodiment of the present application is shown in FIG. 4. Figure 5 As shown in the figure, the computer device of this embodiment includes at least one processor (only one is shown in the figure), a memory, and a computer program stored in the memory and executable on the at least one processor, and the processor executes the computer program to implement the steps in any of the above QPS statistical methods for distributed systems. Figure 5
[0137] The computer device can include, but is not limited to, a processor and a memory. Those skilled in the art can understand that the computer device is only an example of the computer device and does not constitute a limitation on the computer device, and the computer device can include more or fewer components than those shown in the figure, or combine certain components or different components, for example, it can also include a network interface, a display screen, and an input device, etc. Figure 5
[0138] The processor can be a CPU, and can also be other general-purpose processors, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor.
[0139] The memory includes a readable storage medium, an internal memory, etc., where the internal memory can be a memory of the computer device, and the internal memory provides an environment for running of the operating system and the computer-readable instructions in the readable storage medium. The readable storage medium can be a hard disk of the computer device, and in other embodiments, can also be an external storage device of the computer device, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc. Further, the memory can include both an internal storage unit of the computer device and an external storage device. The memory is used to store an operating system, an application program, a BootLoader, data, and other programs, such as program codes of computer programs, etc. The memory can also be used to temporarily store data that has been output or will be output.
[0140] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above-mentioned division of each functional unit and module is exemplified, and in actual application, the above-mentioned functions can be completed by different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of software functional unit. In addition, the specific names of each functional unit and module are only for easy distinction, and do not limit the protection scope of the present application. The specific working process of the unit and module in the above device can refer to the corresponding process in the foregoing method embodiment, which will not be repeated here. If the integrated unit is realized in the form of 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 present application realizes all or part of the processes in the above-mentioned embodiment methods, which can be realized by a computer program to instruct related hardware to complete, and the computer program can be stored in a computer readable storage medium. The computer program includes computer program code, which can be in the form of source code, object code, executable file or some intermediate form. The computer readable medium at least includes any entity or device capable of carrying computer program code, recording medium, computer memory, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), electrical carrier signal, telecommunication signal and software distribution medium. For example, U disk, mobile hard disk, magnetic disk or optical disk, etc. In some jurisdictions, according to legislation and patent practice, computer readable medium cannot be electrical carrier signal and telecommunication signal.
[0141] The present application realizes all or part of the processes in the above-mentioned embodiment methods, which can also be completed by a computer program product. When the computer program product runs on the computer equipment, it makes the computer equipment execute the steps in the above-mentioned embodiment methods.
[0142] In the above-mentioned embodiments, the description of each embodiment has its own emphasis, and the parts not described or recorded in detail in a certain embodiment can be referred to the related description of other embodiments.
[0143] Those skilled in the art can understand that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be realized in electronic hardware or a combination of computer software and electronic hardware. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0144] In the embodiments provided by the present application, it should be understood that the disclosed apparatus / computer device and method can be implemented in other manners. For example, the described apparatus / computer device embodiments are merely schematic. For example, the division of the modules or units can be different, and each can include a plurality of sub-units. Some or all of the modules or units can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections can be indirect couplings or communication connections through some interfaces, devices or units, and can be in electrical, mechanical or other forms.
[0145] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e. may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiments.
[0146] The above embodiments are only used to illustrate the technical solutions of the present application, but not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that the technical solutions recorded in the foregoing embodiments can be modified, or some technical features can be replaced by equivalents; and these modifications or replacements do not make the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.
Claims
1. A method for QPS statistics for distributed systems, characterized in that, The method comprises: determining a target server interface to be counted in a distributed system, obtaining a query timestamp of the target server interface, determining a query time period according to the query timestamp, and dividing the query time period into K query sub-time periods with a preset sub-time period length, K being an integer greater than zero; determining a timestamp corresponding to a request received by the target server interface as a request timestamp, mapping a key name according to the request timestamp using a preset mapping rule, and determining a key value corresponding to the key name according to the receiving time order of the request in the query time period to which the request timestamp belongs; for any query sub-time period, reading the maximum key value of the key name corresponding to all request timestamps in the query sub-time period, and determining the maximum key value as the QPS value of the query sub-time period; calculating the mean value of the QPS values corresponding to the K query sub-time periods, and determining the mean value as the QPS value of the query time period.
2. The QPS statistical method of claim 1, wherein, Before dividing the query time period into K query sub-time periods with a preset sub-time period length, the method further comprises: determining a set of associated interfaces of the target server interface according to the known association relationship between the interfaces in the distributed system, the set of associated interfaces comprising at least one associated interface; determining an updated sub-time period length according to the associated sub-time period length corresponding to each associated interface in the set of associated interfaces; updating the sub-time period length to the updated sub-time period length when the updated sub-time period length meets a preset condition.
3. The QPS statistical method of claim 2, wherein, initializing an updated weight corresponding to the updated sub-time period length to zero; the updating of the sub-time period length to the updated sub-time period length when the updated sub-time period length meets a preset condition comprises: iterating through the associated sub-time period length corresponding to each associated interface, comparing the updated sub-time period length with the associated sub-time period length, if the comparison result is consistent, obtaining the associated interface weight of the corresponding associated interface, and increasing the associated interface weight to the updated weight; detecting whether the updated weight is greater than a preset weight threshold, if the updated weight is greater than the weight threshold, determining that the updated sub-time period length meets a preset condition, and updating the sub-time period length to the updated sub-time period length.
4. The QPS statistical method of claim 3, wherein, After determining that the updated sub-time period length meets a preset condition, the method further comprises: for any associated interface, if the comparison result of the associated sub-time period length corresponding to the associated interface and the updated sub-time period length is consistent, obtaining the influence times of the associated interface, and increasing the influence times by one to obtain updated influence times; mapping the updated influence times to an updated weight through a normalization mapping function, and updating the associated interface weight corresponding to the associated interface to the updated weight.
5. The QPS statistical method of claim 2, wherein, After determining the maximum key value as the QPS value of the query sub-time period, the method further comprises: for any query sub-time period, constructing a query element corresponding to the query sub-time period with the starting time point of the query sub-time period and the QPS value of the query sub-time period. According to the time sequence of all query sub-time periods corresponding to the starting time point, all query elements corresponding to the query time period are spliced to determine that the splicing result is a query vector; For any non-associated interface corresponding to a reference query vector that does not belong to the associated interface set of the target server interface, the similarity between the query vector and the reference query vector is calculated, and if the similarity meets the preset condition, the non-associated interface is added to the associated interface set.
6. The QPS statistical method according to any one of claims 1 to 5, characterized in that, The average of the QPS values corresponding to the K query sub-time periods is calculated, and the average is determined as the QPS value of the query time period. The QPS value corresponding to each query sub-time period is multiplied by a preset interest weight to obtain a weighted QPS value. The average of all weighted QPS values is calculated, and the average is determined as the QPS value of the query time period.
7. The QPS statistical method of claim 6, wherein, Before the QPS value corresponding to each query sub-time period is multiplied by a preset interest weight, it further includes: Obtain the historical QPS value of the target server interface, and obtain the interest weight corresponding to each time point by using a preset mapping function according to the historical QPS value; For any query sub-time period, the average of the interest weights corresponding to the time points included in the query sub-time period is calculated, and the calculation result is determined as the preset interest weight of the query sub-time period.
8. A QPS (Queries Per Second) counting device for a distributed system, characterized in that, The QPS statistical device includes: A time division module for determining a server interface to be counted in a distributed system as a target server interface, obtaining a query timestamp of the target server interface, determining a query time period according to the query timestamp, and dividing the query time period into K query sub-time periods with a preset sub-time period length, K being an integer greater than zero; A request mapping module for determining that the timestamp corresponding to the request received by the target server interface is a request timestamp, mapping the key name by using a preset mapping rule according to the request timestamp, and determining the key value corresponding to the key name according to the receiving time sequence of the request within the query time period to which the request timestamp belongs; A key value query module for reading the maximum key value of the key name corresponding to all request timestamps within any query sub-time period, and determining the maximum key value as the QPS value of the query sub-time period; An average calculation module for calculating the average of the QPS values corresponding to the K query sub-time periods, and determining the average as the QPS value of the query time period.
9. A computer device, comprising: The computer device includes a processor, a memory, and a computer program stored in the memory and executable on the processor, and the processor executes the computer program to implement the QPS statistical method of any one of claims 1-7.
10. A computer-readable storage medium storing a computer program, the computer program comprising instructions that, when executed by a computer, cause the computer to perform the method of any one of claims 1 to 9. The computer program is executed by the processor to implement the QPS statistical method of any one of claims 1-7.
Citation Information
Patent Citations
Data splitting method and device for distributed storage system
CN107169009A
Method, device and equipment for obtaining instantaneous interface access statistics
CN108512711A