Throttling and Buffering

Learn how throttling and buffering can solve the problem of a fast producer but a slow consumer.

In addition to backpressure, several useful operators can solve the problem of a fast producer but a slow consumer. These operators allow us to either throttle or buffer items so that a consumer can keep up. Oftentimes, these operators are preferred over backpressure because they are much simpler to work with.

Throttling

Let’s recall the DeviceSensorManager example that we have discussed previously. We saw that the rate at which accelerometer events are emitted is defined by SensorManager.SENSOR_DELAY_NORMAL (that is, about 20 milliseconds).

Say we wanted to consume events at a much slower rate. How might we do that? We can attach a separate listener with the desired rate, but what if we want to use the same Observable? There are a couple of options to achieve this, one of which is to use the filtering operator .sample().

Get hands-on with 1200+ tech skills courses.