10c754147SBo Chen# I/O Throttling 20c754147SBo Chen 332ad4982SBo ChenCloud Hypervisor now supports I/O throttling on virtio-block and virtio-net 4*af74de27SRuoqing Hedevices. This support is based on the [`rate-limiter` module](https://github.com/firecracker-microvm/firecracker/tree/7a1231b141e958d15d5b2c079dd5e0880528b4b0/src/rate_limiter) 50c754147SBo Chenfrom Firecracker. This document explains the user interface of this 60c754147SBo Chenfeature, and highlights some internal implementations that can help users 70c754147SBo Chenbetter understand the expected behavior of I/O throttling in practice. 80c754147SBo Chen 90c754147SBo ChenCloud Hypervisor allows to limit both the I/O bandwidth (e.g. bytes/s) 1032ad4982SBo Chenand I/O operations (ops/s) independently. For virtio-net devices, while 1132ad4982SBo Chensharing the same "rate limit" from user inputs (on both bandwidth and 1232ad4982SBo Chenoperations), the RX and TX queues are throttled independently. 1332ad4982SBo ChenTo limit the I/O bandwidth, Cloud Hypervisor 140c754147SBo Chenprovides three user options, i.e., `bw_size` (bytes), `bw_one_time_burst` 150c754147SBo Chen(bytes), and `bw_refill_time` (ms). Both `bw_size` and `bw_refill_time` 160c754147SBo Chenare required, while `bw_one_time_burst` is optional. 170c754147SBo ChenInternally, these options define a TokenBucket with a maximum capacity 180c754147SBo Chen(`bw_size` bytes), an initial burst size (`bw_one_time_burst`) and an 190c754147SBo Cheninterval for refilling purposes (`bw_refill_time`). The "refill-rate" is 200c754147SBo Chen`bw_size` bytes per `bw_refill_time` ms, and it is the constant rate at 210c754147SBo Chenwhich the tokens replenish. The refill process only starts happening 220c754147SBo Chenafter the initial burst budget is consumed. Consumption from the token 230c754147SBo Chenbucket is unbounded in speed which allows for bursts bound in size by 240c754147SBo Chenthe amount of tokens available. Once the token bucket is empty, 250c754147SBo Chenconsumption speed is bound by the "refill-rate". Similarly, Cloud 260c754147SBo ChenHypervisor provides another three options for limiting I/O operations, 27a87d1bbaSFabiano Fidêncioi.e., `ops_size` (I/O operations), `ops_one_time_burst` (I/O operations), 28a87d1bbaSFabiano Fidêncioand `ops_refill_time` (ms). 290c754147SBo Chen 300c754147SBo ChenOne caveat in the I/O throttling is that every-time the bucket gets 310c754147SBo Chenempty, it will stop I/O operations for a fixed amount of time 320c754147SBo Chen(`cool_down_time`). The `cool_down_time` now is fixed at `100 ms`, it 330c754147SBo Chencan have big implications to the actual rate limit (which can be a lot 340c754147SBo Chendifferent the expected "refill-rate" derived from user inputs). For 3532ad4982SBo Chenexample, to have a 1000 IOPS limit on a virtio-blk device, users should 3632ad4982SBo Chenbe able to provide either of the following two options: 370c754147SBo Chen`ops_size=1000,ops_refill_time=1000` or 380c754147SBo Chen`ops_size=10,ops_refill_time=10`. However, the actual IOPS limits are 390c754147SBo Chenlikely to be ~1000 IOPS and ~100 IOPS respectively. The reason is the 400c754147SBo Chenactual rate limit users get can be as low as 410c754147SBo Chen`ops_size/(ops_refill_time+cool_down_time)`. As a result, it is 420c754147SBo Chengenerally advisable to keep `bw/ops_refill_time` larger than `100 ms` 430c754147SBo Chen(`cool_down_time`) to make sure the actual rate limit is close to users' 440c754147SBo Chenexpectation ("refill-rate"). 45c297d8d7SThomas Barrett 46c297d8d7SThomas Barrett## Rate Limit Groups 47*af74de27SRuoqing He 48c297d8d7SThomas BarrettIt is possible to throttle the aggregate bandwidth or operations 49c297d8d7SThomas Barrettof multiple virtio-blk devices using a `rate_limit_group`. virtio-blk devices may be 50c297d8d7SThomas Barrettdynamically added and removed from a `rate_limit_group`. The following example 51c297d8d7SThomas Barrettdemonstrates how to throttle the aggregate bandwidth of two disks to 10 MiB/s. 52*af74de27SRuoqing He 53c297d8d7SThomas Barrett``` 54c297d8d7SThomas Barrett--disk path=disk0.raw,rate_limit_group=group0 \ 55c297d8d7SThomas Barrett path=disk1.raw,rate_limit_group=group0 \ 56c297d8d7SThomas Barrett--rate-limit-group bw_size=1048576,bw_refill_time,bw_refill_time=100 57c297d8d7SThomas Barrett``` 58