Marc2001
Marc2001

Reputation: 311

What does event throttling mean?

I read a whole bunch of articles about Rx throttling this morning and I was a little bit confused about throttling. In this article, it says "Throttling enforces a maximum number of times a function can be called over time (As in execute this function at most once every 100 milliseconds)" But, reading this article, it says "throttling implements debounce in Rx."

My question is what's the real definition of throttling (Code samples of using them would help alot)?

Upvotes: 0

Views: 2683

Answers (1)

John Wu
John Wu

Reputation: 52270

Throttling sets a ceiling on the number of events. If you set the ceiling to 10 and receive 2 events (well below the ceiling), both are processed as soon as possible.

Debouncing enforces a delay between events. If you set the delay to 1/10th of a second, and you receive 2 events, there will be a 1/10th sec delay between them. The delay is the same no matter how many events are received.

If events are handled very quickly, a throttle set to 10 and a debounce set to 1/10th will have more or less the same effect while under heavy traffic. If the events take too long to process, debouncing degrades the bandwidth because it is adding additional delay. Under low load, throttling is more efficient, because no delay is added. And throttling has all of the benefits of debouncing at high traffic levels.

In other words, throttling addresses the problem more appropriately, but debouncing is easier to implement. The author is pointing out that the Throttle() method actually debounces. So whoever wrote that code "cheated," in other words.

Upvotes: 4

Related Questions