Skip to content

Commit

Permalink
Avoid slow CI tests on MACOS_X using build flag
Browse files Browse the repository at this point in the history
Build with MACOS_IGNORE_FULLFSYNC=1 to build a version of Roc ksDB which does not HAVE_FULLFSYNC and is therefore much faster at some intensive open/close operations, such as are often found in testing.

DO NOT use this in production, or in performance testing.

e.g
$ make clean jclean
$ MACOS_IGNORE_FULLFSYNC=1 make -j12 rocksdbjava

This turns off the default -DHAVE_FULLFSYNC (on Mac only) on platform detection, which has a huge cost on open/close testing due to very conservative flush safety - using `fcntl(fd_, F_FULLFSYNC)`

Same option is also added to cmake build to turn off FULLFSYNC on MacOS build
  • Loading branch information
alanpaxton committed Jan 6, 2025
1 parent 09d7f6a commit 95d059c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,10 @@ endif()
if(CMAKE_SYSTEM_NAME MATCHES "Cygwin")
add_definitions(-fno-builtin-memcmp -DCYGWIN)
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(OS_MACOSX ON)
add_definitions(-DOS_MACOSX)
elseif(CMAKE_SYSTEM_NAME MATCHES "iOS")
set(OS_MACOSX ON)
add_definitions(-DOS_MACOSX -DIOS_CROSS_COMPILE)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_definitions(-DOS_LINUX)
Expand Down Expand Up @@ -574,7 +576,7 @@ if(HAVE_AUXV_GETAUXVAL)
endif()

check_cxx_symbol_exists(F_FULLFSYNC "fcntl.h" HAVE_FULLFSYNC)
if(HAVE_FULLFSYNC)
if(HAVE_FULLFSYNC AND (NOT OS_MACOSX OR NOT MACOS_IGNORE_FULLFSYNC))
add_definitions(-DHAVE_FULLFSYNC)
endif()

Expand Down
7 changes: 5 additions & 2 deletions build_tools/build_detect_platform
Original file line number Diff line number Diff line change
Expand Up @@ -732,15 +732,18 @@ EOF
fi

# check for F_FULLFSYNC
$CXX $PLATFORM_CXXFALGS -x c++ - -o test.o 2>/dev/null <<EOF
$CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o 2>/dev/null <<EOF
#include <fcntl.h>
int main() {
fcntl(0, F_FULLFSYNC);
return 0;
}
EOF
if [ "$?" = 0 ]; then
COMMON_FLAGS="$COMMON_FLAGS -DHAVE_FULLFSYNC"
if [ ! "$MACOS_IGNORE_FULLFSYNC" ] || [ ! "$PLATFORM" = OS_MACOSX ]; then
echo "Full fsync"
COMMON_FLAGS="$COMMON_FLAGS -DHAVE_FULLFSYNC"
fi
fi

rm -f test.o test_dl.o
Expand Down
2 changes: 1 addition & 1 deletion env/io_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ IOStatus PosixMmapFile::Fsync(const IOOptions& /*opts*/,
IODebugContext* /*dbg*/) {
#ifdef HAVE_FULLFSYNC
if (::fcntl(fd_, F_FULLFSYNC) < 0) {
return IOError("While fcntl(F_FULLSYNC) on mmaped file", filename_, errno);
return IOError("While fcntl(F_FULLSYNC) on mmapped file", filename_, errno);
}
#else // HAVE_FULLFSYNC
if (fsync(fd_) < 0) {
Expand Down
43 changes: 43 additions & 0 deletions java/src/test/java/org/rocksdb/OpenFSyncPerformanceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.rocksdb;

import org.junit.Test;

import java.util.ArrayList;

/**
* This test is intended to be run on MacOS
* It is used to compare/validate versions of RocksDB built using
* `make clean jclean; make -j12 rocksdbjava`
* versus versions built using
* `make clean jclean; MACOS_IGNORE_FULLFSYNC=1 make -j12 rocksdbjava`
* The latter run this test about 10x faster on MacOS.
* @link <a href="https://github.com/facebook/rocksdb/issues/13147">...</a>
* `MACOS_IGNORE_FULLFSYNC` can be used to build fast test-only versions of RocksDB for efficient CI usage
*/
public class OpenFSyncPerformanceTest {

@Test
public void testOpen() throws RocksDBException {
int count = 100;
ArrayList<Long> deltas = new ArrayList<>(count);
long sum = 0;
for (int i = 0; i < count; i++) {
long start = System.currentTimeMillis();
try(RocksDB db = RocksDB.open("test-open-" + i)) {
long delta = System.currentTimeMillis() - start;
//System.out.println("RocksDB.open() cost:" + (delta));
sum += delta;
deltas.add(delta);
} finally {
RocksDB.destroyDB("test-open-" +i, new Options());
}
}
long mean = sum / count;
long variance = 0;
for (long d : deltas) {
variance += (d - mean) * (d - mean);
}
double sd = Math.sqrt((double) (variance/count));
System.out.println("RocksDB.open() mean cost:" + (sum/count) + ", SD: " + sd + ", count: " + count);
}
}

0 comments on commit 95d059c

Please sign in to comment.