From 45828c721536e2145be6f825e563955d39948f02 Mon Sep 17 00:00:00 2001 From: "Peter (Stig) Edwards" Date: Thu, 11 Jan 2018 18:49:48 -0800 Subject: [PATCH] Consider an increase to buffer size when reading option file, from 4K to 8K. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Hello and thank you for RocksDB, While looking into the buffered io used when an `OPTIONS` file is read I noticed the `OPTIONS` files produced by RocksDB 5.8.8 (and head of master) were just over 4096 bytes in size, resulting in the version of glibc I am using (glibc-2.17-196.el7) (on the filesystem used) being passed a 4K buffer for the `fread_unlocked` call and 2 system call reads using a 4096 buffer being used to read the contents of the `OPTIONS` file. If the buffer size is increased to 8192 then 1 system call read is used to read the contents. As I think the buffer size is just used for reading `OPTIONS` files, and I thought it likely that `OPTIONS` files have increased in size (as more options are added), I thought I would suggest an increase. [ If the comments from the top of the `OPTIONS` file are removed, and white space from the start of lines is removed then the size can be reduced to be under 4K, but as more options are added the size seems likely to grow again. ] Create a new database: ``` > ./ldb --create_if_missing --db=/tmp/rdb_tmp put 1 1 OK ``` The OPTIONS file is 4252 bytes: ``` > stat /tmp/rdb_tmp/OPTIONS* | head -n 2 File: ‘/tmp/rdb_tmp/OPTIONS-000005’ Size: 4252 Blocks: 16 IO Block: 4096 regular file ``` Before, the 4096 byte buffer is used from 2 system read calls: ``` > strace -f ./ldb --try_load_options --db=/tmp/rdb_tmp get DOES_NOT_EXIST 2>&1 | grep -A 1 'RocksDB option file' read(3, "# This is a RocksDB option file."..., 4096) = 4096 read(3, "e\n metadata_block_size=4096\n c"..., 4096) = 156 ``` ltrace shows 4096 passed to fread_unlocked ``` > ltrace -S -f ./ldb --try_load_options --db=/tmp/rdb_tmp get DOES_NOT_EXIST 2>&1 | grep -C 3 'RocksDB option file' [pid 51013] fread_unlocked(0x7ffd5fbf2d50, 1, 4096, 0x7fd2e084e780 [pid 51013] fstat@SYS(3, 0x7ffd5fbf28f0) = 0 [pid 51013] mmap@SYS(nil, 4096, 3, 34, -1, 0) = 0x7fd2e318c000 [pid 51013] read@SYS(3, "# This is a RocksDB option file."..., 4096) = 4096 [pid 51013] <... fread_unlocked resumed> ) = 4096 ... ``` After, the 8192 byte buffer is used from 1 system read call: ``` > strace -f ./ldb --try_load_options --db=/tmp/rdb_tmp get DOES_NOT_EXIST 2>&1 | grep -A 1 'RocksDB option file' read(3, "# This is a RocksDB option file."..., 8192) = 4252 read(3, "", 4096) = 0 ``` ltrace shows 8192 passed to fread_unlocked ``` > ltrace -S -f ./ldb --try_load_options --db=/tmp/rdb_tmp get DOES_NOT_EXIST 2>&1 | grep -C 3 'RocksDB option file' [pid 146611] fread_unlocked(0x7ffcfba382f0, 1, 8192, 0x7fc4e844e780 [pid 146611] fstat@SYS(3, 0x7ffcfba380f0) = 0 [pid 146611] mmap@SYS(nil, 4096, 3, 34, -1, 0) = 0x7fc4eaee0000 [pid 146611] read@SYS(3, "# This is a RocksDB option file."..., 8192) = 4252 [pid 146611] read@SYS(3, "", 4096) = 0 [pid 146611] <... fread_unlocked resumed> ) = 4252 [pid 146611] feof(0x7fc4e844e780) = 1 ``` Closes https://github.com/facebook/rocksdb/pull/3294 Differential Revision: D6653684 Pulled By: ajkr fbshipit-source-id: 222f25f5442fefe1dcec18c700bd9e235bb63491 --- options/options_parser.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/options_parser.cc b/options/options_parser.cc index e68295981..040e51c92 100644 --- a/options/options_parser.cc +++ b/options/options_parser.cc @@ -199,7 +199,7 @@ Status RocksDBOptionsParser::ParseStatement(std::string* name, namespace { bool ReadOneLine(std::istringstream* iss, SequentialFile* seq_file, std::string* output, bool* has_data, Status* result) { - const int kBufferSize = 4096; + const int kBufferSize = 8192; char buffer[kBufferSize + 1]; Slice input_slice;