Method and system for detecting overspeed items in extensible stream based on SpeedSketch
The SpeedSketch data structure solves the problem of high memory consumption and insufficient accuracy of speeding item detection in data streams through technologies such as hash function and global clock, and achieves fast, accurate and memory-saving speeding item detection, and is suitable for multiple platforms and Data flow at scale.
Patent Information
- Application Number
- CN202410498999.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-24
- Publication Date
- 2024-08-27
AI Technical Summary
When the existing technology detects overspeed items in data streams, there are problems such as high memory consumption and insufficient detection accuracy, especially periodic network traffic fluctuations and potential problems caused by approximation algorithms.
Use the SpeedSketch data structure to map data items to buckets through hash functions, update the bucket usage value and obtain the minimum usage value MinUsage to determine overspeed items, combine the global clock and conservative update technology to reduce memory overhead and estimation errors, and use sampling and counters Flip technology improves detection accuracy.
It achieves fast, memory-saving and high-accuracy overspeed detection, reduces memory complexity and error rate, and can process 4.8 billion pieces of data per second on programmable switches with an average error rate of less than 0.1%.
Smart Images

Figure CN118555221A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of overspeed item detection in a flow system, and specifically to a method and system for overspeed item detection in a data stream using SpeedSketch. The method has strong scalability and can be applied to data streams of multiple platforms and various scales. Background Art
[0002] In data flow, monitoring high-speed users (such as users who occupy a large amount of network bandwidth or users who quickly send too many business requests and exceed the processing capacity) is crucial to preventing system overload and maintaining system fairness. In this case, it is very important to detect excessive requests from users and mark them as "overspeed items". Overspeed items occur when the speed at which a user's items (such as data packets or message requests) arrive exceeds the processing speed. The definition of overspeed items is as follows:
[0003] Speeding Items: Under the average speed limit parameter V and burst capacity parameter B, each user is assigned a separate buffer that can hold B data items and processes them at speed V. After a data item arrives, it is directed to the buffer of the user that owns it. If the buffer is full, the item is defined as a speeding item; otherwise it is added to the buffer and is not considered speeding.
[0004] Existing methods include exact algorithms and approximate algorithms: the exact algorithm sets a buffer counter for each user to ensure zero errors, and performs a simulation each time a data item arrives to check whether the data item can be inserted into the buffer. The memory required by this method grows linearly with the number of users; the approximate algorithm uses a sketch to check for overspeed items, such as the stingy sketch. Although the approximate method can detect quickly, the detected overspeed items will be concentrated at the end of a time window, resulting in harmful periodic network traffic fluctuations and other potential problems. The above two methods are limited by memory limitations and overspeed item detection accuracy, respectively. Summary of the invention
[0005] In order to meet the requirements of fast, memory-saving and high-accuracy detection of speeding items in data stream scenarios, the present invention provides a sketches-based data structure, called SpeedSketch. The data structure can quickly detect speeding items in data streams while theoretically ensuring high accuracy and greatly saving memory. The present invention includes a basic version, an advanced version and two extensions of SpeedSketch.
[0006] The technical solution adopted by the present invention is as follows:
[0007] A scalable method for detecting speeding items in a flow based on SpeedSketch, comprising the following steps:
[0008] When a data item arrives in the data stream, the SpeedSketch insertion process is performed, the usage value of the bucket in SpeedSketch is updated, and the minimum usage value MinUsage is obtained;
[0009] Determine whether the current data item is an overspeed item based on the minimum usage value MinUsage.
[0010] Furthermore, the SpeedSketch contains k arrays, each array contains n buckets, and the jth bucket of the i-th array is recorded as There are n×k buckets in total; each bucket has a counter To record usage and have a timestamp To record the latest update time of the bucket, there are k independent hash functions: h1(.),…,h k (.), when user e has data arriving, the i-th hash function maps the user's data to the i-th array. In a bucket.
[0011] Furthermore, the SpeedSketch insertion process includes:
[0012] Use k hash functions to find the k mapping buckets corresponding to user e. For these k mapping buckets, update the first Buckets: The current timestamp is T, and the amount of data processed from the last update of the bucket to now is Where V represents the average speed limit parameter, and the usage value C of the bucket is updated as The timestamp t of the bucket is updated to T;
[0013] After k buckets are updated, find the minimum usage value
[0014] Furthermore, judging whether the current data item is an overspeed item based on the minimum usage value MinUsage includes: if MinUsage+1≤B, the current data item is not an overspeed item, and the usage value C of the corresponding k buckets is increased by one; if MinUsage+1>B, the current data item is an overspeed item, where B represents the burst capacity parameter.
[0015] Furthermore, the timestamps in all the buckets of SpeedSketch described in the above method are replaced by a global clock G, thereby reducing the memory overhead of each bucket; only one counter is recorded in each bucket, and its value is Change to When a data item arrives, To calculate the usage value C of each bucket, and then use the usage value C to calculate MinUsage to determine whether it is an overspeeding item; and, use conservative update technology to reduce the estimation error without changing the data structure, which means that when inserting an item, C is not increased when C>MinUsage.
[0016] Furthermore, the above method also includes: using sampling technology to achieve weighting so that each data item has a different weight.
[0017] Furthermore, the method further includes: using a counter rollover technique to resolve overflow errors and reduce the memory usage of the bucket; the counter rollover technique includes: limiting the global clock G to grow cyclically within the interval [0, MaxG), where MaxG represents the upper limit of the clock count, and using a global flag Flag to perform parity check, each time G exceeds MaxG, Flag is reset to 0, Flag is flipped, that is, Flag = 1-Flag; recording a 1-bit flag in each bucket To record the value of Flag when the bucket was last accessed; when a data item arrives and the bucket it is mapped to is accessed, first check whether the global flag Flag is the same as the local flag If yes, insert the item, otherwise Reduce MaxG, and then insert terms so that G and Always smaller than MaxG+B to reduce memory usage while preventing overflow.
[0018] A scalable flow overspeed detection system based on SpeedSketch, comprising:
[0019] The minimum usage value acquisition module is used to perform the SpeedSketch insertion process when a data item arrives in the data stream, update the usage value of the bucket in SpeedSketch, and obtain the minimum usage value MinUsage;
[0020] The overspeed item judgment module is used to judge whether the current data item is an overspeed item according to the minimum usage value MinUsage.
[0021] The beneficial effects of the present invention are as follows:
[0022] The present invention finds that it is obviously inefficient to allocate memory for all possible users when only a small number of users have speeding items. Through experiments, it is found that active users who use the traffic speeding item detection service at the same time are often less than 1% of the total number of potential users, and among these active users, less than 5% of users will speed at a certain moment. Therefore, the linear algorithm can be greatly optimized by only paying attention to speeding users and allocating resources to those speeding users. Based on this discovery, the present invention proposes SpeedSketch, which has three major characteristics:
[0023] 1) Fast: A programmable switch can process 4.8 billion pieces per second.
[0024] 2) Less memory usage: The space complexity is reduced from the original O(N) to O(N′ O ), where N represents all users, N′ O Represents the maximum possible number of concurrent speeding users.
[0025] 3) High accuracy: SpeedSketch, as an approximate algorithm, can easily achieve an average error rate of less than 0.1%. In addition, the present invention also proposes an advanced version of SpeedSketch and two extensions to improve the scalability of SpeedSketch. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 It is a flow chart of the main steps of the method of the present invention.
[0027] Figure 2 This is an example that inserts packet information into SpeedSketch and determines whether it is an overspeed item. DETAILED DESCRIPTION
[0028] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the examples in the accompanying drawings. It should be understood that the specific examples described herein are only used to explain the present invention and are not used to limit the present invention.
[0029] The invention provides a scalable method for detecting overspeed items in a flow based on SpeedSketch, such as Figure 1 As shown, the main steps include: when a data item in the data stream arrives, the SpeedSketch insertion process is performed, the usage value of the bucket in the SpeedSketch is updated, and the minimum usage value MinUsage is obtained; according to the minimum usage value MinUsage, whether the current data item is an overspeeding item is determined. The present invention includes a basic version of SpeedSketch, an advanced version, and two extensions.
[0030] 1. Basic version of the present invention:
[0031] Considering the performance bottleneck in the linear solution is: a bucket can only serve one user at any time. The method of the present invention is: allow multiple users to share a bucket at the same time, when all users sharing a bucket are slow, they can use a bucket perfectly at the same time; otherwise, the composition of shared users can be repeatedly changed until the error is small and controllable.
[0032] The data structure of SpeedSketch of the present invention is as follows Figure 2 As shown, the basic version of SpeedSketch consists of k arrays, each of which contains n buckets. The jth bucket of the i-th array is recorded as There are n×k buckets in total. Each bucket has a counter To record usage and have a timestamp To record the latest update time of the bucket. In addition, there are k independent hash functions: h1(.),…,h k (.). When user e has data arriving, the i-th hash function will map the user's data to the i-th array. In a bucket.
[0033] When a data item arrives in the data stream of user e, the insertion process of SpeedSketch is as follows:
[0034] First, use all k hash functions to calculate and find the k mapping buckets corresponding to user e. For these k mapping buckets, use the following method to update the first Buckets: The current timestamp is T, and the amount of data processed from the last update of the bucket to now is Where V represents the processing speed, which is the average speed limit parameter in the definition of the speeding item, so the usage value C of this bucket is updated to The timestamp t of the bucket is updated to T. After all k buckets are updated, the minimum usage value is found. MinUsage is the value in these buckets that is closest to the actual usage of user e, which will be explained in the following paragraphs.
[0035] Next, MinUsage is used to determine whether the current data item is an overspeed item. If MinUsage+1≤B, where B represents capacity, i.e., the burst capacity parameter in the definition of an overspeed item, then the current data item is not an overspeed item, and the usage value C of the corresponding k buckets is increased by one; conversely, if MinUsage+1>B, then the current data item is an overspeed item. The whole process is as follows: Figure 2 shown.
[0036] Based on the above, we can see that the usage recorded in a bucket is the total usage of all users hashed to it. As more and more other users share the same bucket with user e, the usage of these buckets will increase over time, so the usage of user e in any of the k mapping buckets is not less than the actual usage of user e (that is, the usage of user e in the linear method). Therefore, it can be concluded that MinUsage is the most accurate description of the actual usage of user e, and it can be used to detect speeding items. Based on the above analysis, SpeedSketch has the following three characteristics: 1) Inactive users with no projects will not incur overhead. 2) Slow users can share a bucket without generating errors. 3) SpeedSketch has a unilateral error, but will never miss any speeding items.
[0037] 2. Advanced version of the present invention:
[0038] High-order SpeedSketch is an optimized version of basic SpeedSketch with two technologies: global clock and Thrift (conservative update technology). These two technologies do not introduce any losses. The global clock technology reduces the memory overhead of each bucket, while the conservative update technology reduces the estimation error without changing the data structure.
[0039] 2.1) Global clock technology: The basic version of SpeedSketch has a counter and a timestamp. In fact, the timestamps in all buckets can be replaced by a global clock, thereby reducing the memory overhead of each bucket. The advanced SpeedSketch of the present invention adds a global clock G, which increases by V after each unit time and has no upper limit. Only one counter is recorded in each bucket, but its value changes from Change to Here G is the global clock for updating the bucket. Therefore, when an item arrives, To calculate the usage C of each bucket, and then use the usage C to calculate MinUsage according to the basic version of SpeedSketch algorithm to determine whether it is an overspeed item. Here C is a temporary variable. After the judgment is completed, To save it.
[0040] 2.2) Conservative update technique: When inserting an item, do not increase C when C>MinUsage. The following is an explanation of this optimization technique: Define u to represent the actual usage of user e before inserting the item, that is, u = A e .C, where A e .C is the counter corresponding to user e in the linear solution. In order to achieve accurate estimation, C should be as small as possible while satisfying u≤C, so there is ,u≤C i , where C i is C in the i-th mapping bucket. Therefore u≤MinUsage. After another data packet from user e arrives, the actual usage is u'=u+1. If C>MinUsage, u'=u+1≤MinUsage+1≤C+1. Since u and C are both integers, u'≤C. Therefore, when C>MinUsage, not increasing C is to ensure that C is not less than the actual usage and to make C as small as possible, thereby reducing the estimation error.
[0041] 3. Two extended versions of the present invention:
[0042] 3.1) Weighted Technique: In some cases, each data item may have a different weight (for example, the size of a data packet in the network is between 64 bytes and 1500 bytes). Assuming that the maximum weight of all possible data items arriving is W, the extended version of the present invention uses sampling techniques to achieve weighting. For example, assume that each increase in counter C represents a weight W. For each data item arriving at counter C, if its weight is w, then The probability of increasing the value of counter C by one, otherwise it remains unchanged.
[0043] 3.2) Counter Rollover Technique: If SpeedSketch runs for a long time, G and It may grow to integer overflow. The counter rollover technology is to solve the potential overflow error and further reduce the memory usage of the bucket. The present invention limits the global clock G to grow cyclically in the interval [0, MaxG) (MaxG represents the upper limit of the clock count, for example, MaxG = 2 16 =65536), and use a global bit Flag for parity check. Specifically, every time G exceeds MaxG, Flag is reset to 0 and Flag is flipped (Flag = 1-Flag). A 1-bit flag is recorded in each bucket. To record the value of Flag when the bucket was last accessed. When a data item arrives and the bucket it is mapped to is accessed, the global flag Flag is first checked to see if it is the same as the local flag Flag. Same: If yes, insert the term as before; otherwise, assume that after the extra cycles, the global clock G becomes smaller, and In this case, the local flag needs to be updated to the global flag, that is, Reduce MaxG, and then insert entries as before. There is only a small probability that a bucket is accessed twice and the difference between the time nodes is close to 2×MaxG, which will cause a memory overflow, but even then, the overflow error will not be greater than B. This technique can make G and Always smaller than MaxG+B, preventing overflow and reducing memory usage.
[0044] Specific embodiments of the present invention:
[0045] Figure 2 This is an example of the working process of SpeedSketch. In this example, k=3, there are 5 buckets in each array, with capacity B=5 and processing speed V=2.
[0046] Assume that the current global clock G = 10, a new data item e arrives, first calculate h1(e), h2(e), h2(e) according to the three hash functions, then find the corresponding three buckets according to these three hash values: according to The actual usage values of the corresponding three buckets are calculated to be [5, 2, 0], from which MinUsage = min(5, 2, 0) = 0 can be obtained. By comparison, 0+1≤B is obtained, so the data item this time is not an overspeed item.
[0047] After the judgment is completed, the data in SpeedSketch needs to be updated. According to Thrift, when C>MinUsage, C is not increased, so C becomes [5,3,1]. C is just a temporary variable. C+G, that is, [15,13,11], is updated to SpeedSketch, and the data item is processed.
[0048] Another embodiment of the present invention provides a scalable flow overspeed item detection system based on SpeedSketch, which includes:
[0049] The minimum usage value acquisition module is used to perform the SpeedSketch insertion process when a data item arrives in the data stream, update the usage value of the bucket in SpeedSketch, and obtain the minimum usage value MinUsage;
[0050] The overspeed item judgment module is used to judge whether the current data item is an overspeed item according to the minimum usage value MinUsage.
[0051] The specific implementation process of each module refers to the above description of the method of the present invention.
[0052] Another embodiment of the present invention provides a computer device (computer, server, smart phone, etc.), which includes a memory and a processor, the memory stores a computer program, the computer program is configured to be executed by the processor, and the computer program includes instructions for executing each step in the method of the present invention.
[0053] Another embodiment of the present invention provides a computer-readable storage medium (such as ROM / RAM, magnetic disk, optical disk), wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a computer, the steps of the method of the present invention are implemented.
[0054] The specific embodiments of the present invention disclosed above are intended to help understand the content of the present invention and implement it accordingly. It can be understood by those skilled in the art that various replacements, changes and modifications are possible without departing from the spirit and scope of the present invention. The present invention should not be limited to the contents disclosed in the embodiments of this specification, and the scope of protection of the present invention shall be subject to the scope defined in the claims.
Claims
1. A scalable method for detecting overspeed items in a flow based on SpeedSketch, characterized in that: The following steps are involved: When a data item arrives in the data stream, the SpeedSketch insertion process is performed, the usage value of the bucket in SpeedSketch is updated, and the minimum usage value MinUsage is obtained; Determine whether the current data item is an overspeed item based on the minimum usage value MinUsage.
2. The method according to claim 1, characterized in that The SpeedSketch contains k arrays, each array contains n buckets, and the jth bucket of the i-th array is recorded as There are n×k buckets in total; each bucket has a counter To record usage and have a timestamp To record the latest update time of the bucket, there are k independent hash functions: h1(.),…,h k (.), when user e has data arriving, the i-th hash function maps the user's data to the i-th array. In a bucket.
3. The method according to claim 2, characterized in that The SpeedSketch insertion process includes: Use k hash functions to find the k mapping buckets corresponding to user e. For these k mapping buckets, update the first Buckets: The current timestamp is T, and the amount of data processed from the last update of the bucket to now is Where V represents the average speed limit parameter, and the usage value C of the bucket is updated as The timestamp t of the bucket is updated to T; After k buckets are updated, find the minimum usage value 4. The method according to claim 1, characterized in that: The determining whether the current data item is an overspeed item according to the minimum usage value MinUsage includes: If MinUsage+1≤B, the current data item is not an overspeed item, and the usage value C of the corresponding k buckets is increased by one; if MinUsage+1>B, the current data item is an overspeed item, where B represents the burst capacity parameter.
5. The method according to claim 1, characterized in that The timestamps in all the buckets of the SpeedSketch are replaced by a global clock G, thereby reducing the memory overhead of each bucket; each bucket only records one counter, whose value is from Change to When a data item arrives, To calculate the usage value C of each bucket, and then use the usage value C to calculate MinUsage to determine whether it is an overspeeding item; and, use conservative update technology to reduce the estimation error without changing the data structure, which means that when inserting an item, C is not increased when C>MinUsage.
6. The method according to claim 1, characterized in that Sampling techniques are used to implement weighting so that each data item has a different weight.
7. The method according to claim 1, characterized in that Counter rollover technology is used to solve overflow errors and reduce the memory usage of the bucket; the counter rollover technology includes: Limit the global clock G to grow cyclically in the interval [0, MaxG), where MaxG represents the upper limit of the clock count, and use a global flag Flag to perform parity check. Each time G exceeds MaxG, Flag is reset to 0 and flipped, that is, Flag = 1-Flag; record a 1-bit flag in each bucket To record the value of Flag when the bucket was last accessed; When a data item arrives and the bucket it is mapped to is accessed, the global flag Flag is first checked to see if it matches the local flag Flag. If yes, insert the item, otherwise Reduce MaxG, and then insert terms so that G and Always smaller than MaxG+B to reduce memory usage while preventing overflow.
8. A scalable flow overspeed detection system based on SpeedSketch, characterized in that: include: The minimum usage value acquisition module is used to perform the SpeedSketch insertion process when a data item arrives in the data stream, update the usage value of the bucket in SpeedSketch, and obtain the minimum usage value MinUsage; The overspeed item judgment module is used to judge whether the current data item is an overspeed item according to the minimum usage value MinUsage.
9. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, the computer program is configured to be executed by the processor, and the computer program comprises instructions for executing the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a computer, the method according to any one of claims 1 to 7 is implemented.
