Skip to content

Commit

Permalink
feat: support win64(vcpkg+CMake)
Browse files Browse the repository at this point in the history
YCSB-cpp can now be built on windows, using vcpkg and CMake.
See README.md for usage.
  • Loading branch information
kabu1204 committed Feb 24, 2023
1 parent 0e04c43 commit 45acea1
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 38 deletions.
66 changes: 66 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
cmake_minimum_required(VERSION 3.10)
project(ycsb-cpp LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 17)

set(CMAKE_BUILD_TYPE Release)

option(BIND_ROCKSDB "build with rocksdb" OFF)
option(BIND_WIREDTIGER "build with wiredtiger" OFF)
option(WITH_ZLIB "linking YCSB with zlib; needed by HdrHISTOGRAM, DO NOT TURN OFF" ON)
option(WITH_LZ4 "linking YCSB with lz4" OFF)
option(WITH_SNAPPY "linking YCSB with snappy" OFF)
option(WITH_ZSTD "linking YCSB with zstd" OFF)

file(GLOB_RECURSE YCSB_CORE_SRC "core/*.cc")

add_executable(ycsb ${YCSB_CORE_SRC})
target_include_directories(ycsb PRIVATE ${PROJECT_SOURCE_DIR})

if (BIND_ROCKSDB)
message(STATUS "BIND_ROCKSDB - ON")
# rocksdb need zlib
set(WITH_ZLIB ON)
file(GLOB_RECURSE YCSB_ROCKSDB_SRC "rocksdb/*.cc")
target_sources(ycsb PRIVATE ${YCSB_ROCKSDB_SRC})
find_package(RocksDB CONFIG REQUIRED)
target_link_libraries(ycsb PRIVATE RocksDB::rocksdb rpcrt4.lib)
else()
message(STATUS "BIND_ROCKSDB - OFF")
endif()

if(WITH_ZLIB)
message(STATUS "WITH_ZLIB - ON")
find_package(ZLIB REQUIRED)
target_link_libraries(ycsb PRIVATE ZLIB::ZLIB)
else()
message(STATUS "WITH_ZLIB - OFF")
endif()

if(WITH_SNAPPY)
message(STATUS "WITH_SNAPPY - ON")
find_package(Snappy CONFIG REQUIRED)
target_link_libraries(ycsb PRIVATE Snappy::snappy)
else()
message(STATUS "WITH_SNAPPY - OFF")
endif()

if(WITH_LZ4)
message(STATUS "WITH_LZ4 - ON")
find_package(lz4 CONFIG REQUIRED)
target_link_libraries(main PRIVATE lz4::lz4)
else()
message(STATUS "WITH_LZ4 - OFF")
endif()

if(WITH_ZSTD)
message(STATUS "WITH_ZSTD - ON")
find_package(zstd CONFIG REQUIRED)
target_link_libraries(main PRIVATE $<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>)
else()
message(STATUS "WITH_ZSTD - OFF")
endif()

add_subdirectory(HdrHistogram_c)
include_directories(HdrHistogram_c/include)
add_compile_definitions(-DHDRMEASUREMENT)
add_dependencies(ycsb hdr_histogram)
79 changes: 62 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,30 @@ This is a fork of [YCSB-C](https://github.com/basicthinker/YCSB-C) with some add

This repo is forked from [ls4154/YCSB-cpp](https://github.com/ls4154/YCSB-cpp) to support WiredTiger.

## Building
# Build WiredTiger

Clone the source:
```
git clone git://github.com/wiredtiger/wiredtiger.git
mkdir -p wiredtiger/build
cd wiredtiger/build
```

Enable built-in compressors and build
```
cmake -DHAVE_BUILTIN_EXTENSION_LZ4=1 -DHAVE_BUILTIN_EXTENSION_SNAPPY=1 -DHAVE_BUILTIN_EXTENSION_ZLIB=1 -DHAVE_BUILTIN_EXTENSION_ZSTD=1 -DENABLE_STATIC=1 ../.
make -j$(nproc)
sudo make install
```

## Build YCSB-cpp

## Build with Makefile on GNU

Simply use `make` to build.

```
git clone https://github.com/ls4154/YCSB-cpp.git
git clone https://github.com/kabu1204/YCSB-cpp
cd YCSB-cpp
git submodule update --init
make
Expand Down Expand Up @@ -45,21 +63,48 @@ EXTRA_LDFLAGS ?= -L/example/rocksdb -ldl -lz -lsnappy -lzstd -lbz2 -llz4
BIND_ROCKSDB ?= 1
```

## Build WiredTiger

Clone the source:
```
git clone git://github.com/wiredtiger/wiredtiger.git
mkdir -p wiredtiger/build
cd wiredtiger/build
```

Enable built-in compressors and build
```
cmake -DHAVE_BUILTIN_EXTENSION_LZ4=1 -DHAVE_BUILTIN_EXTENSION_SNAPPY=1 -DHAVE_BUILTIN_EXTENSION_ZLIB=1 -DHAVE_BUILTIN_EXTENSION_ZSTD=1 -DENABLE_STATIC=1 ../.
make -j$(nproc)
sudo make install
```
## Build with CMake+vcpkg on Windows
### Prerequisite

1. You need to install Visual Studio Community first, for example VS2019.
2. [vcpkg](https://github.com/microsoft/vcpkg)
3. [CMake](https://cmake.org/download/)

### Building

The following steps are done in *Developer Powershell for VS 2019*(StartMenu - Visual Studio 2019 - Developer Powershell for VS 2019)

1. Install RocksDB
```powershell
cd <vcpkg_root>
.\vcpkg.exe install rocksdb[*]:x64-windows
```
This will automatically install dependent compression libraries(lz4, snappy, zstd, zlib), and build rocksdb with these libraries enabled.

`<vcpkg_root>` is the path where you've installed the vcpkg, `C:/src/vcpkg` for example.

2. Clone YCSB-cpp
```powershell
cd <somewhere>
git clone https://github.com/kabu1204/YCSB-cpp
cd YCSB-cpp
git submodule update --init
```
3. Build YCSB-cpp
```powershell
mkdir build
cd build
cmake -DBIND_ROCKSDB=1 -DWITH_SNAPPY=1 -DCMAKE_TOOLCHAIN_FILE=<vcpkg_root>/scripts/buildsystems/vcpkg.cmake ..
msbuild ycsb-cpp.sln /p:Configuration=Release
```
`-DCMAKE_TOOLCHAIN_FILE=<vcpkg_root>/scripts/buildsystems/vcpkg.cmake` enables CMake `find_packege()` to find libraries
installed by vcpkg. You do not need to use backslash '\' in your path here.

`-DBIND_ROCKSDB=1` binds rocksdb.

`-DWITH_SNAPPY=1` tells CMake to link snappy with YCSB, same for `WITH_LZ4`, `WITH_ZLIB` and `WITH_ZSTD`.

The executable `ycsb.exe` can be found in `build/Release`.

## Running

Expand Down
43 changes: 24 additions & 19 deletions core/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,31 @@ namespace ycsbc {

inline int ClientThread(ycsbc::DB *db, ycsbc::CoreWorkload *wl, const int num_ops, bool is_loading,
bool init_db, bool cleanup_db, CountDownLatch *latch) {
if (init_db) {
db->Init();
}

int ops = 0;
for (int i = 0; i < num_ops; ++i) {
if (is_loading) {
wl->DoInsert(*db);
} else {
wl->DoTransaction(*db);
try {
if (init_db) {
db->Init();
}

int ops = 0;
for (int i = 0; i < num_ops; ++i) {
if (is_loading) {
wl->DoInsert(*db);
} else {
wl->DoTransaction(*db);
}
ops++;
}

if (cleanup_db) {
db->Cleanup();
}

latch->CountDown();
return ops;
} catch(const utils::Exception& e) {
std::cerr<<"Caught exception: "<<e.what()<<std::endl;
return -1;
}
ops++;
}

if (cleanup_db) {
db->Cleanup();
}

latch->CountDown();
return ops;
}

} // ycsbc
Expand Down
2 changes: 2 additions & 0 deletions core/measurements.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <hdr/hdr_histogram.h>
#endif

typedef unsigned int uint;

namespace ycsbc {

class Measurements {
Expand Down
1 change: 1 addition & 0 deletions core/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <cstdint>
#include <exception>
#include <random>
#include <locale>

namespace ycsbc {

Expand Down
2 changes: 1 addition & 1 deletion rocksdb/rocksdb.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rocksdb.dbname=/tmp/ycsb-rocskdb
rocksdb.dbname=ycsb-rocksdb
rocksdb.format=single
rocksdb.destroy=false

Expand Down
12 changes: 11 additions & 1 deletion rocksdb/rocksdb_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
#include <rocksdb/utilities/options_util.h>
#include <rocksdb/write_batch.h>

#if defined(_MSC_VER)
#if _MSC_VER >= 1911
#define MAYBE_UNUSED [[maybe_unused]]
#else
#define MAYBE_UNUSED
#endif
#elif defined(__GNUC__)
#define MAYBE_UNUSED __attribute__ ((unused))
#endif

namespace {
const std::string PROP_NAME = "rocksdb.dbname";
const std::string PROP_NAME_DEFAULT = "";
Expand Down Expand Up @@ -466,7 +476,7 @@ DB::Status RocksdbDB::UpdateSingle(const std::string &table, const std::string &
DeserializeRow(current_values, data);
assert(current_values.size() == static_cast<size_t>(fieldcount_));
for (Field &new_field : values) {
bool found __attribute__((unused)) = false;
bool found MAYBE_UNUSED = false;
for (Field &cur_field : current_values) {
if (cur_field.name == new_field.name) {
found = true;
Expand Down

0 comments on commit 45acea1

Please sign in to comment.