rocksdb/table
Nathan Bronson 7d87f02799 support for concurrent adds to memtable
Summary:
This diff adds support for concurrent adds to the skiplist memtable
implementations.  Memory allocation is made thread-safe by the addition of
a spinlock, with small per-core buffers to avoid contention.  Concurrent
memtable writes are made via an additional method and don't impose a
performance overhead on the non-concurrent case, so parallelism can be
selected on a per-batch basis.

Write thread synchronization is an increasing bottleneck for higher levels
of concurrency, so this diff adds --enable_write_thread_adaptive_yield
(default off).  This feature causes threads joining a write batch
group to spin for a short time (default 100 usec) using sched_yield,
rather than going to sleep on a mutex.  If the timing of the yield calls
indicates that another thread has actually run during the yield then
spinning is avoided.  This option improves performance for concurrent
situations even without parallel adds, although it has the potential to
increase CPU usage (and the heuristic adaptation is not yet mature).

Parallel writes are not currently compatible with
inplace updates, update callbacks, or delete filtering.
Enable it with --allow_concurrent_memtable_write (and
--enable_write_thread_adaptive_yield).  Parallel memtable writes
are performance neutral when there is no actual parallelism, and in
my experiments (SSD server-class Linux and varying contention and key
sizes for fillrandom) they are always a performance win when there is
more than one thread.

Statistics are updated earlier in the write path, dropping the number
of DB mutex acquisitions from 2 to 1 for almost all cases.

This diff was motivated and inspired by Yahoo's cLSM work.  It is more
conservative than cLSM: RocksDB's write batch group leader role is
preserved (along with all of the existing flush and write throttling
logic) and concurrent writers are blocked until all memtable insertions
have completed and the sequence number has been advanced, to preserve
linearizability.

My test config is "db_bench -benchmarks=fillrandom -threads=$T
-batch_size=1 -memtablerep=skip_list -value_size=100 --num=1000000/$T
-level0_slowdown_writes_trigger=9999 -level0_stop_writes_trigger=9999
-disable_auto_compactions --max_write_buffer_number=8
-max_background_flushes=8 --disable_wal --write_buffer_size=160000000
--block_size=16384 --allow_concurrent_memtable_write" on a two-socket
Xeon E5-2660 @ 2.2Ghz with lots of memory and an SSD hard drive.  With 1
thread I get ~440Kops/sec.  Peak performance for 1 socket (numactl
-N1) is slightly more than 1Mops/sec, at 16 threads.  Peak performance
across both sockets happens at 30 threads, and is ~900Kops/sec, although
with fewer threads there is less performance loss when the system has
background work.

Test Plan:
1. concurrent stress tests for InlineSkipList and DynamicBloom
2. make clean; make check
3. make clean; DISABLE_JEMALLOC=1 make valgrind_check; valgrind db_bench
4. make clean; COMPILE_WITH_TSAN=1 make all check; db_bench
5. make clean; COMPILE_WITH_ASAN=1 make all check; db_bench
6. make clean; OPT=-DROCKSDB_LITE make check
7. verify no perf regressions when disabled

Reviewers: igor, sdong

Reviewed By: sdong

Subscribers: MarkCallaghan, IslamAbdelRahman, anthony, yhchiang, rven, sdong, guyg8, kradhakrishnan, dhruba

Differential Revision: https://reviews.facebook.net/D50589
2015-12-25 11:03:40 -08:00
..
adaptive_table_factory.cc Pass column family ID to table property collector 2015-10-09 14:36:51 -07:00
adaptive_table_factory.h Pass column family ID to table property collector 2015-10-09 14:36:51 -07:00
block_based_filter_block_test.cc rocksdb: switch to gtest 2015-03-17 14:08:00 -07:00
block_based_filter_block.cc bloom hit/miss stats for SST and memtable 2015-10-07 11:23:20 -07:00
block_based_filter_block.h Remember whole key/prefix filtering on/off in SST file 2015-02-11 11:20:04 -08:00
block_based_table_builder.cc Introduce ReadOptions::pin_data (support zero copy for keys) 2015-12-16 12:08:30 -08:00
block_based_table_builder.h Move skip_table_builder_flush to BlockBasedTableOption 2015-10-30 18:33:01 -07:00
block_based_table_factory.cc Skip bottom-level filter block caching when hit-optimized 2015-12-23 10:15:07 -08:00
block_based_table_factory.h Merge pull request #805 from SherlockNoMad/OptionHelperFix 2015-11-17 16:24:52 -08:00
block_based_table_reader.cc Skip bottom-level filter block caching when hit-optimized 2015-12-23 10:15:07 -08:00
block_based_table_reader.h Skip bottom-level filter block caching when hit-optimized 2015-12-23 10:15:07 -08:00
block_builder.cc Introduce ReadOptions::pin_data (support zero copy for keys) 2015-12-16 12:08:30 -08:00
block_builder.h Introduce ReadOptions::pin_data (support zero copy for keys) 2015-12-16 12:08:30 -08:00
block_hash_index_test.cc Seperate InternalIterator from Iterator 2015-10-13 15:32:13 -07:00
block_hash_index.cc Seperate InternalIterator from Iterator 2015-10-13 15:32:13 -07:00
block_hash_index.h Seperate InternalIterator from Iterator 2015-10-13 15:32:13 -07:00
block_prefix_index.cc Turn on -Wshorten-64-to-32 and fix all the errors 2014-11-11 16:47:22 -05:00
block_prefix_index.h Windows Port from Microsoft 2015-07-01 16:13:56 -07:00
block_test.cc Seperate InternalIterator from Iterator 2015-10-13 15:32:13 -07:00
block.cc Introduce ReadOptions::pin_data (support zero copy for keys) 2015-12-16 12:08:30 -08:00
block.h Introduce ReadOptions::pin_data (support zero copy for keys) 2015-12-16 12:08:30 -08:00
bloom_block.cc table/bloom_block.*: pass func parameter by reference 2014-09-30 23:30:31 +02:00
bloom_block.h Enforce write buffer memory limit across column families 2014-12-02 12:09:20 -08:00
cuckoo_table_builder_test.cc Enable MS compiler warning c4244. 2015-12-11 16:47:34 -08:00
cuckoo_table_builder.cc Merge pull request #846 from yuslepukhin/enble_c4244_lossofdata 2015-12-23 22:59:42 -08:00
cuckoo_table_builder.h Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env 2015-07-17 16:58:18 -07:00
cuckoo_table_factory.cc Pass column family ID to table property collector 2015-10-09 14:36:51 -07:00
cuckoo_table_factory.h Add OptionsUtil::LoadOptionsFromFile() API 2015-11-12 06:52:43 -08:00
cuckoo_table_reader_test.cc Enable MS compiler warning c4244. 2015-12-11 16:47:34 -08:00
cuckoo_table_reader.cc Skip bottom-level filter block caching when hit-optimized 2015-12-23 10:15:07 -08:00
cuckoo_table_reader.h Skip bottom-level filter block caching when hit-optimized 2015-12-23 10:15:07 -08:00
filter_block.h Dump routine to BlockBasedTableReader 2014-12-23 13:24:07 -08:00
flush_block_policy.cc move block based table related options BlockBasedTableOptions 2014-08-25 14:22:05 -07:00
format.cc Add ZSTD (not final format) compression type 2015-08-28 11:01:13 -07:00
format.h Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env 2015-07-17 16:58:18 -07:00
full_filter_block_test.cc rocksdb: switch to gtest 2015-03-17 14:08:00 -07:00
full_filter_block.cc bloom hit/miss stats for SST and memtable 2015-10-07 11:23:20 -07:00
full_filter_block.h Remember whole key/prefix filtering on/off in SST file 2015-02-11 11:20:04 -08:00
get_context.cc Use SST files for Transaction conflict detection 2015-12-11 12:34:11 -08:00
get_context.h Use SST files for Transaction conflict detection 2015-12-11 12:34:11 -08:00
internal_iterator.h Introduce ReadOptions::pin_data (support zero copy for keys) 2015-12-16 12:08:30 -08:00
iter_heap.h Replace std::priority_queue in MergingIterator with custom heap, take 2 2015-07-15 03:34:40 -07:00
iterator_wrapper.h Introduce ReadOptions::pin_data (support zero copy for keys) 2015-12-16 12:08:30 -08:00
iterator.cc Seperate InternalIterator from Iterator 2015-10-13 15:32:13 -07:00
merger_test.cc Seperate InternalIterator from Iterator 2015-10-13 15:32:13 -07:00
merger.cc Introduce ReadOptions::pin_data (support zero copy for keys) 2015-12-16 12:08:30 -08:00
merger.h Seperate InternalIterator from Iterator 2015-10-13 15:32:13 -07:00
meta_blocks.cc Revert "Adding new table properties" 2015-11-06 16:49:38 -08:00
meta_blocks.h Moving memtable related files from util to a new directory memtable 2015-10-16 14:10:33 -07:00
mock_table.cc Skip bottom-level filter block caching when hit-optimized 2015-12-23 10:15:07 -08:00
mock_table.h Skip bottom-level filter block caching when hit-optimized 2015-12-23 10:15:07 -08:00
plain_table_builder.cc Pass column family ID to table property collector 2015-10-09 14:36:51 -07:00
plain_table_builder.h Pass column family ID to table property collector 2015-10-09 14:36:51 -07:00
plain_table_factory.cc Merge pull request #805 from SherlockNoMad/OptionHelperFix 2015-11-17 16:24:52 -08:00
plain_table_factory.h Fix build broken by previous commit of "option helper refactor" 2015-11-17 16:52:54 -08:00
plain_table_index.cc Enable MS compiler warning c4244. 2015-12-11 16:47:34 -08:00
plain_table_index.h Block plain_table_index.cc in ROCKSDB_LITE 2014-11-24 20:47:27 -08:00
plain_table_key_coding.cc Fix the bug of using freed memory introduced by recent plain table reader patch 2015-09-23 16:16:26 -07:00
plain_table_key_coding.h PlainTableReader to support non-mmap mode 2015-09-23 11:41:07 -07:00
plain_table_reader.cc Skip bottom-level filter block caching when hit-optimized 2015-12-23 10:15:07 -08:00
plain_table_reader.h Skip bottom-level filter block caching when hit-optimized 2015-12-23 10:15:07 -08:00
scoped_arena_iterator.h Seperate InternalIterator from Iterator 2015-10-13 15:32:13 -07:00
sst_file_writer.cc Move skip_table_builder_flush to BlockBasedTableOption 2015-10-30 18:33:01 -07:00
table_builder.h Skip bottom-level filter block caching when hit-optimized 2015-12-23 10:15:07 -08:00
table_properties_internal.h Seperate InternalIterator from Iterator 2015-10-13 15:32:13 -07:00
table_properties.cc Revert "Adding new table properties" 2015-11-06 16:49:38 -08:00
table_reader_bench.cc plain table reader: avoid re-read the same position for index and data in non-mmap mode 2015-11-18 16:49:08 -08:00
table_reader.h Skip bottom-level filter block caching when hit-optimized 2015-12-23 10:15:07 -08:00
table_test.cc support for concurrent adds to memtable 2015-12-25 11:03:40 -08:00
two_level_iterator.cc Introduce ReadOptions::pin_data (support zero copy for keys) 2015-12-16 12:08:30 -08:00
two_level_iterator.h Seperate InternalIterator from Iterator 2015-10-13 15:32:13 -07:00