Rate limiter for a message gateway
09742679 · 2017-08-22
Assignee
Inventors
Cpc classification
H04L49/9031
ELECTRICITY
International classification
Abstract
A hardware-implemented rate limiter is described. This implementation guarantees that messages containing a value v are not forwarded at a higher rate than a predefined threshold value r. More specifically, given a number of times x in a time interval y, which specifies a rate r defined by x/y, the rate limiter reports a violation by selectively setting an error value when v occurs more than x times during the time interval y. Moreover, the rate limiter may be able to keep track of multiple predefined threshold values for different rates. Furthermore, the rate limiter may keep track of 2.sup.b different values v, where b is the number of digits of the binary representation of v.
Claims
1. A rate limiter, comprising: an input node configured to receive input values; a history memory, coupled to the input node, configured to store the input values during a time window defined by a current time and a predefined time interval; a counter memory, coupled to the input node and the history memory, configured to aggregate counter values for different values of the input values during the time window; and control logic, coupled to the counter memory, configured to: compare a counter value to predefined threshold value; and selectively set an error value based on the comparison; wherein the history memory includes a ring buffer; wherein an in-pointer point to a storage element at a head of the ring buffer where a next-received input value is stored with an associated timestamp; and wherein an out-pointer point to another storage element at a tail of the ring buffer where another input value and another associated timestamp are stored and are removed when the other timestamp moves out of the time window.
2. The rate limiter of claim 1, wherein the counter memory includes array elements associated with the different values; and wherein an array element for a given value is incremented when the next received input value having the given value is stored in the history memory, and is decremented when the other input value having the given value is removed from the history memory.
3. The rate limiter of claim 1, wherein, when the other timestamp moves out of the time window, the other input value and the other timestamp are removed from the history memory by incrementing the out-pointer.
4. The rate limiter of claim 1, wherein the error value is provided when the counter value exceeds the predefined threshold value.
5. The rate limiter of claim 1, wherein, when the error value is set, a most-recent instance of a value of the input value corresponding to the counter value is excluded from the history memory.
6. The rate limiter of claim 1, wherein, when the error value is set, a most-recent instance of a value of the input value corresponding to the counter value is stored in the history memory.
7. The rate limiter of claim 1, wherein the control logic is further configured to: compare a second counter value to a second predefined threshold value; and selectively set a second error value based on the comparison of the second counter value and the second predefined threshold value.
8. The rate limiter of claim 7, wherein the second counter value is aggregated during a second time window defined by the current time and a second predefined time interval.
9. The rate limiter of claim 1, wherein the history memory includes a ring buffer; wherein an in-pointer point to a storage element at a head of the ring buffer where a next-received input value is stored with an associated timestamp; wherein an out-pointer point to a second storage element in the ring buffer where another input value and another associated timestamp are stored and are removed when the other timestamp moves out of the time window; and wherein a second out-pointer point to a third storage element in the ring buffer where the other input value and the other associated timestamp are stored and are removed when the other timestamp moves out of a second time window, which is defined by the current time and a second predefined time interval.
10. The rate limiter of claim 9, wherein the counter memory includes array elements associated with the different values; and wherein an array element for a given value is incremented when the next received input value having the given value is stored in the history memory and is decremented when the other input value having the given value is removed from the history memory.
11. The rate limiter of claim 9, wherein, when the other timestamp moves out of the time window, the other input value and the other timestamp are removed from the history memory by incrementing the out-pointer; and wherein, when the other timestamp moves out of the other time window, the other input value and the other timestamp are removed from the history memory by incrementing the second out-pointer.
12. The rate limiter of claim 1, wherein the control logic is coupled to the history memory; wherein the control logic is configured to apply a predefined hash function to the input values prior to storing hashed input values in the history memory; and wherein the counter memory aggregates the hashed input values in the counter values.
13. The rate limiter of claim 12, wherein the control logic is further configured to apply a mapping function to the input values prior to storing mapping input values in the history memory; and wherein the counter memory aggregates the combination of the hashed input values and the mapping input values in the counter values.
14. A system, comprising: a processor; and a rate limiter coupled to the processor, wherein the rate limiter includes: an input node configured to receive input values; a history memory, coupled to the input node, configured to store the input values during a time window defined by a current time and a predefined time interval; a counter memory, coupled to the input node and the history memory, configured to aggregate counter values for different values of the input values during the time window; and control logic, coupled to the counter memory, configured to: compare a counter value to a predefined threshold value; and selectively set an error value based on the comparison; wherein the history memory includes a ring buffer; wherein an in-pointer point to a storage element at a head of the ring buffer where a next-received input value is stored with an associated timestamp; and wherein an out-pointer point to another storage element at a tail of the ring buffer where another input value and another associated timestamp are stored and are removed when the other timestamp moves out of the time window.
15. The system of claim 14, wherein the counter memory includes array elements associated with the different values; and wherein an array element for a given value is incremented when the next received input value having the given value is stored in the history memory, and is decremented when the other input value is removed from the history memory.
16. The system of claim 14, wherein, when the other timestamp moves out of the time window, the other input value and the other timestamp are removed from the history memory by incrementing the out-pointer.
17. The system of claim 14, wherein the control logic is further configured to: compare a second counter value to a second predefined threshold value; and selectively set a second error value based on the comparison of the second counter value and the second predefined threshold value; and wherein the second counter value is aggregated during a second time window defined by the current time and a second predefined time interval.
18. A rate-limiter-implemented method for selectively setting an error value, wherein the method comprises: receiving input values at an input node; using a history memory in the rate limiter, storing the input values during a time window defined by a current time and a predefined time interval; using a counter memory in the rate limiter, aggregating counter values for different values of the input values during the time window; using control logic in the rate limiter, comparing a counter value to a predefined threshold value; and using the control logic in the rate limiter, selectively setting the error value based on the comparison; wherein the history memory includes a ring buffer; wherein an in-pointer point to a storage element at a head of the ring buffer where a next-received input value is stored with an associated timestamp; and wherein an out-pointer point to another storage element at a tail of the ring buffer where another input value and another associated timestamp are stored and are removed when the other timestamp moves out of the time window.
Description
BRIEF DESCRIPTION OF THE FIGURES
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10) Table 1 provides counter values aggregated during operation of the rate limiter of
(11) Table 2 provides pseudocode for a single-rate rate limiter in accordance with an embodiment of the present disclosure.
(12) Table 3 provides pseudocode for a multiple-rate rate limiter in accordance with an embodiment of the present disclosure.
(13) Note that like reference numerals refer to corresponding parts throughout the drawings. Moreover, multiple instances of the same part are designated by a common prefix separated from an instance number by a dash.
DETAILED DESCRIPTION
(14) Embodiments of a rate limiter, a system that includes the rate limiter (such as a message gateway), and a method for selectively setting an error value are described. A hardware implementation of the rate limiter guarantees that messages containing a value v are not forwarded at a higher rate than a predefined threshold value r. More specifically, given a number of times x in a time interval y, which specifies a rate r defined by x/y, the rate limiter reports a violation by selectively setting an error value when v occurs more than x times during the time interval y. Moreover, the rate limiter may be able to keep track of multiple predefined threshold values for different rates. For example, the rate limiter may keep track of 2.sup.b different values v, where b is the number of digits of the binary representation of v.
(15) The rate limiter may allow a message gateway to constrain or bound the number of instances of the values in different messages in the same or different time intervals with low latency (such as latencies on the order of a microsecond). This may allow the rate limiter to ensure regulatory compliance in latency-sensitive applications, such as stock trading.
(16) We now describe embodiments of the rate limiter.
(17) This is illustrated in
(18) TABLE-US-00001 TABLE 1 Value to Value Cycle Insert cnt.sub.a,0 cnt.sub.b,0 cnt.sub.a,0 cnt.sub.b,1 vio.sub.0 vio.sub.1 Dropped 1 a 1 0 1 0 0 0 No 2 a 2 0 2 0 0 0 No 3 a 2 0 2 0 1 0 Yes 4 b 1 1 2 1 0 0 No 5 b 0 2 2 2 0 0 No 6 a 1 2 3 2 0 0 No 7 b 1 2 3 3 0 0 No 8 b 1 2 2 4 0 0 No 9 a 1 2 2 4 0 0 No 10 b 1 1 2 4 0 1 Yes
(19) Referring back to
(20) When the error value is set, note that a most-recent instance of a value of the input value corresponding to the counter value may be excluded from history memory 112. Alternatively, when the error value is set, a most-recent instance of a value of the input value corresponding to the counter value may be stored in history memory 112.
(21) Operation of history memory 112 and counter memory 114 is illustrated in
(22) Counter memory 114 may store a counter cnt for each value v. For example, counter memory 114 may be organized as array elements that uses value v as the array index. (Thus, there may be different array elements in counter memory 114 for different values v.) The counter value cnt may be incremented when value v is inserted into history memory 112 and it may be decremented when value v is removed from history memory 112. The number of entries in history memory 112 may be determined as follows. The maximum number of storage elements n in history memory 112 may be given by the time interval y divided by the minimum inter-arrival time d of the values v. For example, if y equals 100 ms and d equals 100 ns, then n equals 10.sup.6 entries have to be provided. This assumes that values v are inserted at a sustained rate 1/d. (Alternatively, the maximum history size may be derived from the rate and the number of different values. In particular, in this example, if there are 1000 distinct values and the rate is x/y or 100/100 ms, then the maximum number of valid messages may be 1000.Math.100.) If the average rate over time interval y is less than 1/d, the number n can be reduced accordingly. Note that the number of entries in counter memory 114 may be 2.sup.b, where b is the number of bits needed to represent the binary value v=0 . . . 2.sup.b−1, and the size of an entry cnt in counter memory 114 may be n.
(23) Furthermore, note that the precision of the timestamp ts may not have to be better than d. It is assumed that the rate at which values v are inserted and removed from history memory 112 is greater than or equal to the arrival rate 1/d. The precision of the ts can be worse than d if the precision with which the rate is enforced can be relaxed.
(24) Table 2 provides pseudocode for operation of a single-rate rate limiter (RL). Function Init-RL initializes x and y with the maximum number of occurrences X and the time interval Y, respectively. Function Check-RL first checks that the rate in the counter memory (CM) is not exceeded. If the rate is not exceeded, vio is set to FALSE, and v together with the current time T is inserted into the history memory HM and the incremented counter value is stored in CM. If the rate is exceeded, vio is set to TRUE. Different strategies can be applied to how v contributes to the counter values when vio is set. For example, either v is dropped, i.e., no modifications to the HM or to the CM are made. Alternatively, v is not dropped and the HM and the CM are modified as described before when the rate is not exceeded.
(25) TABLE-US-00002 TABLE 2 function Init_RL (X, Y); begin x = X; y = Y; end function Check_RL (v, vio); begin vio = (CM[v].cnt + 1) > x; if not vio then begin HM[in] = {v,T}; in = in + 1; CM[v].cnt = CM[v].cnt + 1; end end loop begin if HM[out].ts < T−y then begin CM[HM[out].v].cnt = CM[HM[out].v].cnt − 1; out = out + 1; end end
(26) An infinite loop may periodically check whether the last storage element of history memory 112 has expired, i.e., whether its timestamp has moved outside the time window, in which case the storage element has to be removed. Removing the storage element may be accomplished by simply incrementing the out-pointer. Simultaneously, the corresponding counter in counter memory 114 may be decremented. The loop may be executed with a time period equal to or less than the minimum time between value arrivals. Alternatively, the loop may be executed with a time period equal to or less than the inverse of the maximum value arrival rate.
(27) In some embodiments, the rate limiter supports multiple rates. This is shown in
(28) TABLE-US-00003 TABLE 3 function Init_RL (X, Y); begin for i = 0 to R − 1 begin x[i] = X[i]; y[i] = Y[i]; end end function Check_RL (v, vio); begin novio = TRUE; for i = 0 to R − 1 begin vio[i] = (CM[v].cnt[i] + 1) > x[i]; novio = novio and not vio[i]; end if novio then begin for i = 0 to R − 1 begin CM[v].cnt[i] = CM[v].cnt[i] + 1; end HM[in] = {v,T}; in = in + 1; end end loop begin for i = 0 to R − 1 do begin if HM[out[i ]].ts < T−y[i] then begin idx = HM[out [i]].v CM[idx].cnt[i] = CM[idx].cnt[i] − 1; out[i] = out[i] + 1; end end end
(29) In embodiments where the rate limiter supports multiple rates, one or more constraints may be enforced. In particular, because the rate limiter limits the rate of outgoing messages, then, with a rate r, if values are received at a rate greater than r, some of the incoming messages may be dropped so that the rate of the outgoing messages equals r. In order to support multiple rates (such as r.sub.0=x.sub.0/t.sub.0 and r.sub.1=x.sub.1/t.sub.1), this implies: t.sub.0≦t.sub.1, x.sub.0≦x.sub.1 and x.sub.0/t.sub.0≧x.sub.1/t.sub.1. The first constraint can be ensured, without loss of generality, by sorting the rates. Moreover, for the second constraint, note that, if x.sub.0 was greater than x.sub.1, then an incoming value would always trigger r.sub.1 and never r.sub.0. This is because, with t.sub.0≦t.sub.1 and x.sub.0>x.sub.1, r.sub.1 allows for fewer elements in more time and, therefore, r.sub.0 does not make sense. Similarly, for the third constraint, note that, if x.sub.0/t.sub.0 was less than x.sub.1/t.sub.1 and t.sub.0≦t.sub.1, then r.sub.1 could never be exceeded because r.sub.0 already enforces a lower average message rate on shorter time intervals. Thus, r.sub.1 would not be needed.
(30) In some embodiments, if the values v are sparse, the input values are hashed using a hash function prior to further processing by the rate limiter. This is shown in
(31) In some implementations, more than one mapping function is used to obtain the input value for the rate limiter. This is shown in
(32) In some embodiments, control logic 116 in rate limiter 500 (
(33) Referring back to
(34) We now describe embodiments of the method.
(35) In some embodiments of method 700, there are additional or fewer operations. Moreover, the order of the operations may be changed and/or two or more operations may be combined into a single operation.
(36) We now describe embodiments of the system.
(37) More generally, embodiments of the rate limiter may be used in a variety of applications, including communications, high-performance computing, etc. As a consequence, the system may include: VLSI circuits, communication systems, storage area networks, data centers, networks (such as local area networks), and/or computer systems (such as multiple-core processor computer systems). Note that system 800 may include, but is not limited to: a server (such as a multi-socket, multi-rack server), a message gateway, a laptop computer, a communication device or system, a tablet computer, a personal computer, a work station, a mainframe computer, a blade, an enterprise computer, a data center, a portable-computing device, a supercomputer, a data center, a network-attached-storage (NAS) system, a storage-area-network (SAN) system, and/or another electronic computing device. Moreover, note that a given computer system may be at one location or may be distributed over multiple, geographically dispersed locations.
(38) In an exemplary embodiment, the rate limiter is used in a message gateway. This is shown in
(39) As shown in
(40) Processor 916 uses rate limiter 910 as a co-processor. A hash function may be performed on the stock symbol (which may be represented as an 8-byte character string) extracted from the ‘enter order’ message. The resulting hash value together with the order type (which may be represented as two bits) may be used as the value v that is passed on to rate limiter 910. Moreover, the hash function may be selected such that it is guaranteed to calculate a unique value for each stock symbol. Note that rate limiter 910 returns vio to indicate whether a rate was exceeded or not. Furthermore, note that the rate parameters x and y may be provided by control registers that are initialized when message gateway 900 is reset.
(41) The preceding embodiments may include fewer components or additional components. Although these embodiments are illustrated as having a number of discrete items, these circuits and devices are intended to be functional descriptions of the various features that may be present rather than structural schematics of the embodiments described herein. Consequently, in these embodiments two or more components may be combined into a single component, and/or a position of one or more components may be changed.
(42) Furthermore, functionality in these circuits, components and devices is implemented in hardware and/or in software as is known in the art. For example, some or all of the functionality of these embodiments may be implemented in one or more: application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), and/or one or more digital signal processors (DSPs). In particular, a hardware implementation of the rate limiter may allow the rate limiter to scale to thousands or millions of input values with latency on the order of microseconds. Additionally, note that circuits in these embodiments may be implemented using PMOS and/or NMOS, and signals may include digital signals that have approximately discrete values and/or analog signals that have continuous values. Note that components and circuits may be single-ended or differential, and power supplies may be unipolar or bipolar.
(43) In the preceding embodiments, some components are shown directly connected to one another, while others are shown connected via intermediate components. In each instance the method of interconnection, or ‘coupling,’ establishes some desired electrical communication between two or more circuit nodes, or terminals. Such coupling may often be accomplished using a number of circuit configurations, as will be understood by those of skill in the art (for example, AC coupling and/or DC coupling may be used).
(44) An output of a process for designing an integrated circuit, or a portion of an integrated circuit, comprising one or more of the circuits described herein may be a computer-readable medium such as, for example, a magnetic tape or an optical or magnetic disk. The computer-readable medium may be encoded with data structures or other information describing circuitry that may be physically instantiated as an integrated circuit or portion of an integrated circuit. Although various formats may be used for such encoding, these data structures are commonly written in: Caltech Intermediate Format (CIF), Calma GDSII Stream Format (GDSII) or Electronic Design Interchange Format (EDIF). Those of skill in the art of integrated circuit design can develop such data structures from schematics of the type detailed above and the corresponding descriptions and encode the data structures on a computer-readable medium. Those of skill in the art of integrated circuit fabrication can use such encoded data to fabricate integrated circuits comprising one or more of the circuits described herein.
(45) While the preceding embodiments illustrated the use of the rate limiter in a message gateway for messages associated with stock transactions, in other embodiments the rate limiter may be used in other applications. For example, the rate limiter may be used to limit the rate of network traffic from a site, a port or a website. Alternatively, the rate limiter may be used in a data center or for event-driven processing.
(46) In the preceding description, we refer to ‘some embodiments.’ Note that ‘some embodiments’ describes a subset of all of the possible embodiments, but does not always specify the same subset of embodiments.
(47) The foregoing description is intended to enable any person skilled in the art to make and use the disclosure, and is provided in the context of a particular application and its requirements. Moreover, the foregoing descriptions of embodiments of the present disclosure have been presented for purposes of illustration and description only. They are not intended to be exhaustive or to limit the present disclosure to the forms disclosed. Accordingly, many modifications and variations will be apparent to practitioners skilled in the art, and the general principles defined herein may be applied to other embodiments and applications without departing from the spirit and scope of the present disclosure. Additionally, the discussion of the preceding embodiments is not intended to limit the present disclosure. Thus, the present disclosure is not intended to be limited to the embodiments shown, but is to be accorded the widest scope consistent with the principles and features disclosed herein.