rocksdb/env
Changyu Bi 8515bd50c9 Support read rate-limiting in SequentialFileReader (#9973)
Summary:
Added rate limiter and read rate-limiting support to SequentialFileReader. I've updated call sites to SequentialFileReader::Read with appropriate IO priority (or left a TODO and specified IO_TOTAL for now).

The PR is separated into four commits: the first one added the rate-limiting support, but with some fixes in the unit test since the number of request bytes from rate limiter in SequentialFileReader are not accurate (there is overcharge at EOF). The second commit fixed this by allowing SequentialFileReader to check file size and determine how many bytes are left in the file to read. The third commit added benchmark related code. The fourth commit moved the logic of using file size to avoid overcharging the rate limiter into backup engine (the main user of SequentialFileReader).

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9973

Test Plan:
- `make check`, backup_engine_test covers usage of SequentialFileReader with rate limiter.
- Run db_bench to check if rate limiting is throttling as expected: Verified that reads and writes are together throttled at 2MB/s, and at 0.2MB chunks that are 100ms apart.
  - Set up: `./db_bench --benchmarks=fillrandom -db=/dev/shm/test_rocksdb`
  - Benchmark:
```
strace -ttfe read,write ./db_bench --benchmarks=backup -db=/dev/shm/test_rocksdb --backup_rate_limit=2097152 --use_existing_db
strace -ttfe read,write ./db_bench --benchmarks=restore -db=/dev/shm/test_rocksdb --restore_rate_limit=2097152 --use_existing_db
```
- db bench on backup and restore to ensure no performance regression.
  - backup (avg over 50 runs): pre-change: 1.90443e+06 micros/op; post-change: 1.8993e+06 micros/op (improve by 0.2%)
  - restore (avg over 50 runs): pre-change: 1.79105e+06 micros/op; post-change: 1.78192e+06 micros/op (improve by 0.5%)

```
# Set up
./db_bench --benchmarks=fillrandom -db=/tmp/test_rocksdb -num=10000000

# benchmark
TEST_TMPDIR=/tmp/test_rocksdb
NUM_RUN=50
for ((j=0;j<$NUM_RUN;j++))
do
   ./db_bench -db=$TEST_TMPDIR -num=10000000 -benchmarks=backup -use_existing_db | egrep 'backup'
  # Restore
  #./db_bench -db=$TEST_TMPDIR -num=10000000 -benchmarks=restore -use_existing_db
done > rate_limit.txt && awk -v NUM_RUN=$NUM_RUN '{sum+=$3;sum_sqrt+=$3^2}END{print sum/NUM_RUN, sqrt(sum_sqrt/NUM_RUN-(sum/NUM_RUN)^2)}' rate_limit.txt >> rate_limit_2.txt
```

Reviewed By: hx235

Differential Revision: D36327418

Pulled By: cbi42

fbshipit-source-id: e75d4307cff815945482df5ba630c1e88d064691
2022-05-24 10:28:57 -07:00
..
composite_env.cc Option type info functions (#9411) 2022-05-13 04:57:08 -07:00
composite_env_wrapper.h Make the Env class Customizable (#9293) 2022-01-04 16:45:49 -08:00
emulated_clock.h Make SystemClock into a Customizable Class (#8636) 2021-09-21 09:23:48 -07:00
env.cc Option type info functions (#9411) 2022-05-13 04:57:08 -07:00
env_basic_test.cc Make SystemClock into a Customizable Class (#8636) 2021-09-21 09:23:48 -07:00
env_chroot.cc Make FileSystem a Customizable Class (#8649) 2021-11-02 09:07:11 -07:00
env_chroot.h Make FileSystem a Customizable Class (#8649) 2021-11-02 09:07:11 -07:00
env_encryption.cc Added GetFactoryCount/Names/Types to ObjectRegistry (#9358) 2022-05-16 09:44:43 -07:00
env_encryption_ctr.h Added GetFactoryCount/Names/Types to ObjectRegistry (#9358) 2022-05-16 09:44:43 -07:00
env_posix.cc Use STATIC_AVOID_DESTRUCTION for static objects with non-trivial destructors (#9958) 2022-05-17 09:39:22 -07:00
env_test.cc Option type info functions (#9411) 2022-05-13 04:57:08 -07:00
file_system.cc Introduce a CountedFileSystem for counting file operations (#9283) 2022-02-03 15:01:23 -08:00
file_system_tracer.cc Make TraceRecord and Replayer public (#8611) 2021-08-11 19:32:46 -07:00
file_system_tracer.h Make FileSystem a Customizable Class (#8649) 2021-11-02 09:07:11 -07:00
fs_posix.cc Use STATIC_AVOID_DESTRUCTION for static objects with non-trivial destructors (#9958) 2022-05-17 09:39:22 -07:00
fs_readonly.h Make FileSystem a Customizable Class (#8649) 2021-11-02 09:07:11 -07:00
fs_remap.cc Test refactoring for Backups+Temperatures (#9655) 2022-03-04 12:32:30 -08:00
fs_remap.h Make FileSystem a Customizable Class (#8649) 2021-11-02 09:07:11 -07:00
io_posix.cc Remove own ToString() (#9955) 2022-05-06 13:03:58 -07:00
io_posix.h Support read rate-limiting in SequentialFileReader (#9973) 2022-05-24 10:28:57 -07:00
io_posix_test.cc Status check enforcement for io_posix_test and options_settable_test (#6857) 2020-05-19 19:22:28 -07:00
mock_env.cc Require C++17 (#9481) 2022-02-04 17:13:10 -08:00
mock_env.h Make the Env class Customizable (#9293) 2022-01-04 16:45:49 -08:00
mock_env_test.cc Make SystemClock into a Customizable Class (#8636) 2021-09-21 09:23:48 -07:00
unique_id_gen.cc New stable, fixed-length cache keys (#9126) 2021-12-16 17:15:13 -08:00
unique_id_gen.h New stable, fixed-length cache keys (#9126) 2021-12-16 17:15:13 -08:00