7242dae7fe
Summary: This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy. **NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into. Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`). In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`. In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`. --- [JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java. With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425). These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical. --- These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x. ``` ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s ``` Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252 Differential Revision: D19331064 Pulled By: pdillinger fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738 |
||
---|---|---|
.. | ||
backupablejni.cc | ||
backupenginejni.cc | ||
cassandra_compactionfilterjni.cc | ||
cassandra_value_operator.cc | ||
checkpoint.cc | ||
clock_cache.cc | ||
columnfamilyhandle.cc | ||
compact_range_options.cc | ||
compaction_filter_factory_jnicallback.cc | ||
compaction_filter_factory_jnicallback.h | ||
compaction_filter_factory.cc | ||
compaction_filter.cc | ||
compaction_job_info.cc | ||
compaction_job_stats.cc | ||
compaction_options_fifo.cc | ||
compaction_options_universal.cc | ||
compaction_options.cc | ||
comparator.cc | ||
comparatorjnicallback.cc | ||
comparatorjnicallback.h | ||
compression_options.cc | ||
env_options.cc | ||
env.cc | ||
filter.cc | ||
ingest_external_file_options.cc | ||
iterator.cc | ||
jnicallback.cc | ||
jnicallback.h | ||
loggerjnicallback.cc | ||
loggerjnicallback.h | ||
lru_cache.cc | ||
memory_util.cc | ||
memtablejni.cc | ||
merge_operator.cc | ||
native_comparator_wrapper_test.cc | ||
optimistic_transaction_db.cc | ||
optimistic_transaction_options.cc | ||
options_util.cc | ||
options.cc | ||
persistent_cache.cc | ||
portal.h | ||
ratelimiterjni.cc | ||
remove_emptyvalue_compactionfilterjni.cc | ||
restorejni.cc | ||
rocks_callback_object.cc | ||
rocksdb_exception_test.cc | ||
rocksjni.cc | ||
slice.cc | ||
snapshot.cc | ||
sst_file_manager.cc | ||
sst_file_reader_iterator.cc | ||
sst_file_readerjni.cc | ||
sst_file_writerjni.cc | ||
statistics.cc | ||
statisticsjni.cc | ||
statisticsjni.h | ||
table_filter_jnicallback.cc | ||
table_filter_jnicallback.h | ||
table_filter.cc | ||
table.cc | ||
thread_status.cc | ||
trace_writer_jnicallback.cc | ||
trace_writer_jnicallback.h | ||
trace_writer.cc | ||
transaction_db_options.cc | ||
transaction_db.cc | ||
transaction_log.cc | ||
transaction_notifier_jnicallback.cc | ||
transaction_notifier_jnicallback.h | ||
transaction_notifier.cc | ||
transaction_options.cc | ||
transaction.cc | ||
ttl.cc | ||
wal_filter_jnicallback.cc | ||
wal_filter_jnicallback.h | ||
wal_filter.cc | ||
write_batch_test.cc | ||
write_batch_with_index.cc | ||
write_batch.cc | ||
write_buffer_manager.cc | ||
writebatchhandlerjnicallback.cc | ||
writebatchhandlerjnicallback.h |