Skip to content

Commit

Permalink
Issue 3645: Allow direct reads in RocksDB to be configurable. (praveg…
Browse files Browse the repository at this point in the history
…a#3647)

Allow RocksDB direct reads to be configurable.

Signed-off-by: Raúl Gracia <[email protected]>
  • Loading branch information
RaulGracia authored and andreipaduroiu committed Apr 17, 2019
1 parent b30f2bd commit a0ed24e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions config/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,12 @@ extendeds3.url=localhost:9020
# will decrease, so the index size will also reduce linearly (but increasing read amplification).
#rocksdb.cacheBlockSizeKB=32

# According to RocksDB documentation, enabling direct reads may be beneficial for performance due to: i) it avoids extra
# copies of data on OS page cache, ii) it exploits better knowledge of the behavior of data to apply policies (e.g.,
# replacement). However, as not all OS/environments support direct IO, we keep it disabled by default for safety. For
# more information, please check: https://github.com/facebook/rocksdb/wiki/Direct-IO.
#rocksdb.directReads=false

##endregion

##region DurableLog Settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class RocksDBCache implements Cache {
private final int writeBufferSizeMB;
private final int readCacheSizeMB;
private final int cacheBlockSizeKB;
private final boolean directReads;

//endregion

Expand All @@ -95,6 +96,7 @@ class RocksDBCache implements Cache {
this.writeBufferSizeMB = config.getWriteBufferSizeMB() / MAX_WRITE_BUFFER_NUMBER;
this.readCacheSizeMB = config.getReadCacheSizeMB();
this.cacheBlockSizeKB = config.getCacheBlockSizeKB();
this.directReads = config.isDirectReads();
try {
this.databaseOptions = createDatabaseOptions();
this.writeOptions = createWriteOptions();
Expand Down Expand Up @@ -254,7 +256,7 @@ private Options createDatabaseOptions() {
.setMinWriteBufferNumberToMerge(MIN_WRITE_BUFFER_NUMBER_TO_MERGE)
.setTableFormatConfig(tableFormatConfig)
.setOptimizeFiltersForHits(true)
.setUseDirectReads(true);
.setUseDirectReads(this.directReads);
}

private void clear(boolean recreateDirectory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class RocksDBConfig {
public static final Property<Integer> WRITE_BUFFER_SIZE_MB = Property.named("writeBufferSizeMB", 64);
public static final Property<Integer> READ_CACHE_SIZE_MB = Property.named("readCacheSizeMB", 8);
public static final Property<Integer> CACHE_BLOCK_SIZE_KB = Property.named("cacheBlockSizeKB", 32);
public static final Property<Boolean> DIRECT_READS = Property.named("directReads", false);
private static final String COMPONENT_CODE = "rocksdb";

//endregion
Expand Down Expand Up @@ -60,6 +61,14 @@ public class RocksDBConfig {
@Getter
private final int cacheBlockSizeKB;

/**
* Enabling direct reads may be beneficial for performance due to: i) it avoids extra copies of data on OS page
* cache, ii) it exploits better knowledge of the behavior of data to apply policies (e.g., replacement). However,
* as not all OS/environments support direct IO, we keep it disabled by default for safety.
*/
@Getter
private final boolean directReads;

//endregion

//region Constructor
Expand All @@ -74,6 +83,7 @@ private RocksDBConfig(TypedProperties properties) throws ConfigurationException
this.writeBufferSizeMB = properties.getInt(WRITE_BUFFER_SIZE_MB);
this.readCacheSizeMB = properties.getInt(READ_CACHE_SIZE_MB);
this.cacheBlockSizeKB = properties.getInt(CACHE_BLOCK_SIZE_KB);
this.directReads = properties.getBoolean(DIRECT_READS);
}

/**
Expand Down

0 comments on commit a0ed24e

Please sign in to comment.