diff --git a/java/org/rocksdb/DBOptions.java b/java/org/rocksdb/DBOptions.java index 600369dec..e3614f463 100644 --- a/java/org/rocksdb/DBOptions.java +++ b/java/org/rocksdb/DBOptions.java @@ -72,6 +72,13 @@ public class DBOptions extends RocksObject implements DBOptionsInterface { return dbOptions; } + @Override + public DBOptions setIncreaseParallelism(int totalThreads) { + assert (isInitialized()); + setIncreaseParallelism(nativeHandle_, totalThreads); + return this; + } + @Override public DBOptions setCreateIfMissing(boolean flag) { assert(isInitialized()); @@ -547,6 +554,7 @@ public class DBOptions extends RocksObject implements DBOptionsInterface { private native void newDBOptions(); private native void disposeInternal(long handle); + private native void setIncreaseParallelism(long handle, int totalThreads); private native void setCreateIfMissing(long handle, boolean flag); private native boolean createIfMissing(long handle); private native void setCreateMissingColumnFamilies( diff --git a/java/org/rocksdb/DBOptionsInterface.java b/java/org/rocksdb/DBOptionsInterface.java index 19ffe375d..39ba13d25 100644 --- a/java/org/rocksdb/DBOptionsInterface.java +++ b/java/org/rocksdb/DBOptionsInterface.java @@ -7,6 +7,21 @@ package org.rocksdb; public interface DBOptionsInterface { + /** + *
By default, RocksDB uses only one background thread for flush and + * compaction. Calling this function will set it up such that total of + * `total_threads` is used.
+ * + *You almost definitely want to call this function if your system is + * bottlenecked by RocksDB.
+ * + * @param The total number of threads to be used by RocksDB. A good value + * is the number of cores. + * + * @return the instance of the current Options + */ + Object setIncreaseParallelism(int totalThreads); + /** * If this value is set to true, then the database will be created * if it is missing during {@code RocksDB.open()}. diff --git a/java/org/rocksdb/Options.java b/java/org/rocksdb/Options.java index 7781b80a6..ac4037508 100644 --- a/java/org/rocksdb/Options.java +++ b/java/org/rocksdb/Options.java @@ -43,6 +43,13 @@ public class Options extends RocksObject env_ = RocksEnv.getDefault(); } + @Override + public Options setIncreaseParallelism(int totalThreads) { + assert(isInitialized()); + setIncreaseParallelism(nativeHandle_, totalThreads); + return this; + } + @Override public Options setCreateIfMissing(boolean flag) { assert(isInitialized()); @@ -1032,6 +1039,7 @@ public class Options extends RocksObject private native void prepareForBulkLoad(long handle); // DB native handles + private native void setIncreaseParallelism(long handle, int totalThreads); private native void setCreateIfMissing(long handle, boolean flag); private native boolean createIfMissing(long handle); private native void setCreateMissingColumnFamilies( diff --git a/java/org/rocksdb/test/DBOptionsTest.java b/java/org/rocksdb/test/DBOptionsTest.java index 6064dd694..858379768 100644 --- a/java/org/rocksdb/test/DBOptionsTest.java +++ b/java/org/rocksdb/test/DBOptionsTest.java @@ -73,6 +73,20 @@ public class DBOptionsTest { new Properties()); } + @Test + public void setIncreaseParallelism() { + DBOptions opt = null; + try { + opt = new DBOptions(); + final int threads = Runtime.getRuntime().availableProcessors() * 2; + opt.setIncreaseParallelism(threads); + } finally { + if (opt != null) { + opt.dispose(); + } + } + } + @Test public void createIfMissing() { DBOptions opt = null; diff --git a/java/org/rocksdb/test/OptionsTest.java b/java/org/rocksdb/test/OptionsTest.java index 3425502d8..0e699c406 100644 --- a/java/org/rocksdb/test/OptionsTest.java +++ b/java/org/rocksdb/test/OptionsTest.java @@ -22,6 +22,20 @@ public class OptionsTest { public static final Random rand = PlatformRandomHelper. getPlatformSpecificRandomFactory(); + @Test + public void setIncreaseParallelism() { + Options opt = null; + try { + opt = new Options(); + final int threads = Runtime.getRuntime().availableProcessors() * 2; + opt.setIncreaseParallelism(threads); + } finally { + if (opt != null) { + opt.dispose(); + } + } + } + @Test public void writeBufferSize() throws RocksDBException { Options opt = null; diff --git a/java/rocksjni/options.cc b/java/rocksjni/options.cc index d139b1a57..667d74508 100644 --- a/java/rocksjni/options.cc +++ b/java/rocksjni/options.cc @@ -68,6 +68,17 @@ void Java_org_rocksdb_Options_disposeInternal( delete reinterpret_cast