From eda0dcdd97fc675b4ac0424492d3f9228e5913dd Mon Sep 17 00:00:00 2001 From: Adam Retter Date: Fri, 5 Dec 2014 13:41:39 +0000 Subject: [PATCH] Exposed IncreasedParallelism option to Java API as setIncreasedParallelism --- java/org/rocksdb/DBOptions.java | 8 ++++++++ java/org/rocksdb/DBOptionsInterface.java | 15 +++++++++++++++ java/org/rocksdb/Options.java | 8 ++++++++ java/rocksjni/options.cc | 23 +++++++++++++++++++++++ 4 files changed, 54 insertions(+) diff --git a/java/org/rocksdb/DBOptions.java b/java/org/rocksdb/DBOptions.java index 600369dec8..e3614f463b 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 19ffe375d2..39ba13d25f 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 7781b80a6d..ac4037508e 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/rocksjni/options.cc b/java/rocksjni/options.cc index d139b1a57b..667d74508c 100644 --- a/java/rocksjni/options.cc +++ b/java/rocksjni/options.cc @@ -68,6 +68,17 @@ void Java_org_rocksdb_Options_disposeInternal( delete reinterpret_cast(handle); } +/* + * Class: org_rocksdb_Options + * Method: setIncreaseParallelism + * Signature: (JI)V + */ +void Java_org_rocksdb_Options_setIncreaseParallelism( + JNIEnv * evnv, jobject jobj, jlong jhandle, jint totalThreads) { + reinterpret_cast + (jhandle)->IncreaseParallelism(static_cast(totalThreads)); +} + /* * Class: org_rocksdb_Options * Method: setCreateIfMissing @@ -2816,6 +2827,18 @@ void Java_org_rocksdb_DBOptions_disposeInternal( delete reinterpret_cast(handle); } +/* + * Class: org_rocksdb_DBOptions + * Method: setIncreaseParallelism + * Signature: (JI)V + */ +void Java_org_rocksdb_DBOptions_setIncreaseParallelism( + JNIEnv * env, jobject jobj, jlong jhandle, jint totalThreads) { + reinterpret_cast + (jhandle)->IncreaseParallelism(static_cast(totalThreads)); +} + + /* * Class: org_rocksdb_DBOptions * Method: setCreateIfMissing