1--- 2title: Higher write throughput with `unordered_write` feature 3layout: post 4author: maysamyabandeh 5category: blog 6--- 7 8Since RocksDB 6.3, The `unordered_write=`true option together with WritePrepared transactions offers 34-42% higher write throughput compared to vanilla RocksDB. If the application can handle more relaxed ordering guarantees, the gain in throughput would increase to 63-131%. 9 10### Background 11 12Currently RocksDB API delivers the following powerful guarantees: 13- Atomic reads: Either all of a write batch is visible to reads or none of it. 14- Read-your-own writes: When a write thread returns to the user, a subsequent read by the same thread will be able to see its own writes. 15- Immutable Snapshots: The reads visible to the snapshot are immutable in the sense that it will not be affected by any in-flight or future writes. 16 17### `unordered_write` 18 19The `unordered_write` feature, when turned on, relaxes the default guarantees of RocksDB. While it still gives read-your-own-write property, neither atomic reads nor the immutable snapshot properties are provided any longer. However, RocksDB users could still get read-your-own-write and immutable snapshots when using this feature in conjunction with TransactionDB configured with WritePrepared transactions and `two_write_queues`. You can read [here](https://github.com/facebook/rocksdb/wiki/unordered_write) to learn about the design of `unordered_write` and [here](https://github.com/facebook/rocksdb/wiki/WritePrepared-Transactions) to learn more about WritePrepared transactions. 20 21### How to use it? 22 23To get the same guarantees as vanilla RocksdB: 24 25 DBOptions db_options; 26 db_options.unordered_write = true; 27 db_options.two_write_queues = true; 28 DB* db; 29 { 30 TransactionDBOptions txn_db_options; 31 txn_db_options.write_policy = TxnDBWritePolicy::WRITE_PREPARED; 32 txn_db_options.skip_concurrency_control = true; 33 TransactionDB* txn_db; 34 TransactionDB::Open(options, txn_db_options, kDBPath, &txn_db); 35 db = txn_db; 36 } 37 db->Write(...); 38 39To get relaxed guarantees: 40 41 DBOptions db_options; 42 db_options.unordered_write = true; 43 DB* db; 44 DB::Open(db_options, kDBPath, &db); 45 db->Write(...); 46 47# Benchmarks 48 49 TEST_TMPDIR=/dev/shm/ ~/db_bench --benchmarks=fillrandom --threads=32 --num=10000000 -max_write_buffer_number=16 --max_background_jobs=64 --batch_size=8 --writes=3000000 -level0_file_num_compaction_trigger=99999 --level0_slowdown_writes_trigger=99999 --level0_stop_writes_trigger=99999 -enable_pipelined_write=false -disable_auto_compactions --transaction_db=true --unordered_write=1 --disable_wal=0 50 51Throughput with `unordered_write`=true and using WritePrepared transaction: 52- WAL: +42% 53- No-WAL: +34% 54Throughput with `unordered_write`=true 55- WAL: +63% 56- NoWAL: +131% 57