Skip to content

Commit

Permalink
update example (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
1a1a11a authored Jan 15, 2024
1 parent 61c77f7 commit 921c112
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 318 deletions.
24 changes: 12 additions & 12 deletions example/cacheCluster/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
cmake_minimum_required (VERSION 3.2)
project (cacheCluster)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 11)
# set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


# clear an error when using cmake in macOS
# if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# set(CMAKE_MACOSX_RPATH 1)
# # Fix linking on 10.14+. See https://stackoverflow.com/questions/54068035
# LINK_DIRECTORIES(/usr/local/lib)
# # a temporary fix for mac
# SET(CMAKE_C_FLAGS_DEBUG " -L/usr/local/lib -lglib-2.0 -lintl -Wno-unused-command-line-argument")
# endif()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../../cmake/Modules/")
find_package(GLib "2.40" REQUIRED)
include_directories(${GLib_INCLUDE_DIRS})
message(STATUS "glib found? " ${GLib_FOUND} ", GLIB = " ${GLib_LIBRARY} ", header = " ${GLib_INCLUDE_DIRS})


find_package(ZSTD)
# https://stackoverflow.com/questions/61377055/cannot-find-gflags-gflags-h-while-building-library-osx/61379123#61379123
include_directories(${ZSTD_INCLUDE_DIR})
if ("${ZSTD_LIBRARIES}" STREQUAL "")
message(FATAL_ERROR "zstd not found")
endif()


################ this mode compiles the external cache replacement algorithm together with the simulator ############
message(STATUS "project_source dir = " ${PROJECT_SOURCE_DIR})
file(GLOB ALL_CXX_SRC ${PROJECT_SOURCE_DIR}/*.cpp)
file(GLOB ALL_C_SRC ${PROJECT_SOURCE_DIR}/*.c)

add_executable(cacheCluster ${ALL_CXX_SRC} ${ALL_C_SRC})
target_link_libraries(cacheCluster libCacheSim m ${GLib_LIBRARY} pthread dl)
target_link_libraries(cacheCluster libCacheSim m ${GLib_LIBRARY} pthread dl ${ZSTD_LIBRARIES})

25 changes: 15 additions & 10 deletions example/cacheCluster/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
namespace CDNSimulator {

void simulate(int argc, char *argv[]) {
const char *data_path = "../../../data/trace.csv";
const char *data_path = "../../../data/twitter_cluster52.csv";
if (argc > 1) {
data_path = argv[1];
} else {
printf("use default data at ../../../data/twitter_cluster52.csv\n");
}

if (access(data_path, F_OK) == -1) {
Expand All @@ -25,9 +27,9 @@ void simulate(int argc, char *argv[]) {

/* setup a csv reader */
reader_init_param_t init_params = default_reader_init_params();
init_params.obj_id_field = 5;
init_params.obj_size_field = 4;
init_params.time_field = 2;
init_params.obj_id_field = 2;
init_params.obj_size_field = 3;
init_params.time_field = 1;
init_params.has_header_set = true;
init_params.has_header = true;
init_params.delimiter = ',';
Expand All @@ -36,12 +38,17 @@ void simulate(int argc, char *argv[]) {
reader_t *reader = open_trace(data_path, CSV_TRACE, &init_params);

const uint64_t n_server = 10;
const uint64_t server_dram_cache_size = 8 * GiB;
const uint64_t server_disk_cache_size = 100 * GiB;
const uint64_t server_dram_cache_size = 1 * MiB;
const uint64_t server_disk_cache_size = 10 * MiB;
const std::string algo = "lru";
// each cache holds 2 ** 20 objects, this is for performance optimization
// you can specify a smaller number to save memory
const uint32_t hashpower = 20;
printf(
"setting up a cluster of %lu servers, each server has %lu MB DRAM cache "
"and %lu MB disk cache, using %s as cache replacement algorithm\n",
(unsigned long)n_server, (unsigned long)(server_dram_cache_size / MiB),
(unsigned long)(server_disk_cache_size / MiB), algo.c_str());

CacheCluster cluster(0);

Expand All @@ -68,10 +75,8 @@ void simulate(int argc, char *argv[]) {
n_req_byte += req->obj_size;
}

std::cout << n_req << " requests, " << n_miss
<< " misses, miss ratio: " << (double)n_miss / n_req
<< ", byte miss ratio: " << (double)n_miss_byte / n_req_byte
<< std::endl;
std::cout << n_req << " requests, " << n_miss << " misses, miss ratio: " << (double)n_miss / n_req
<< ", byte miss ratio: " << (double)n_miss_byte / n_req_byte << std::endl;

close_trace(reader);
}
Expand Down
40 changes: 15 additions & 25 deletions example/cacheHierarchy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
cmake_minimum_required (VERSION 3.2)
project (layeredCache)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

message("****************** this example only works after libCacheSim has been installed ******************")


####
## export C_INCLUDE_PATH=/usr/local/include
## export CPLUS_INCLUDE_PATH=/usr/local/include

# clear an error when using cmake in macOS
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_MACOSX_RPATH 1)
# Fix linking on 10.14+. See https://stackoverflow.com/questions/54068035
LINK_DIRECTORIES(/usr/local/lib)
# a temporary fix for mac
SET(CMAKE_C_FLAGS_DEBUG " -L/usr/local/lib -lglib-2.0 -lintl -Wno-unused-command-line-argument")
endif()


set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
# find libglib2.0-dev
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../../cmake/Modules/")
find_package(GLib "2.40" REQUIRED)
include_directories(${GLib_INCLUDE_DIRS})
message(STATUS "glib found? " ${GLib_FOUND} ", GLIB = " ${GLib_LIBRARY} ", header = " ${GLib_INCLUDE_DIRS})

# set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/usr/local/share/cmake/yaml-cpp/")
find_package(ZSTD)
include_directories(${ZSTD_INCLUDE_DIR})
if ("${ZSTD_LIBRARIES}" STREQUAL "")
message(FATAL_ERROR "zstd not found")
endif()


# https://github.com/jbeder/yaml-cpp
# wget https://github.com/jbeder/yaml-cpp/archive/refs/tags/0.8.0.tar.gz
# tar -xzf 0.8.0.tar.gz; mkdir yaml-cpp-0.8.0/_build; cd yaml-cpp-0.8.0/_build;
# cmake -DBUILD_SHARED_LIBS=ON ..;
# make -j; sudo make install
find_package(YAML-CPP REQUIRED)
# set(YAML_CPP_INCLUDE_DIR /usr/local/include/)
# set(YAML_CPP_LIBRARIES /usr/local/lib/)
Expand All @@ -38,10 +33,5 @@ message(STATUS ${YAML_CPP_INCLUDE_DIR} ";" ${YAML_CPP_LIBRARIES})
file(GLOB ALL_SRC ${PROJECT_SOURCE_DIR}/*.cpp)
message(STATUS "all sources " ${ALL_SRC})
add_executable(layeredCache ${ALL_SRC})
target_link_libraries(layeredCache yaml-cpp libCacheSim m ${GLib_LIBRARY})





target_link_libraries(layeredCache yaml-cpp libCacheSim dl m ${GLib_LIBRARY} ${ZSTD_LIBRARIES} pthread)

83 changes: 0 additions & 83 deletions example/cacheHierarchy/cmake/Modules/FindGLib.cmake

This file was deleted.

22 changes: 9 additions & 13 deletions example/cacheSimulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,23 @@ project (cacheSimulator)

message("****************** this example only works after libCacheSim has been installed ******************")


# clear an error when using cmake in macOS
# if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# set(CMAKE_MACOSX_RPATH 1)
# # Fix linking on 10.14+. See https://stackoverflow.com/questions/54068035
# LINK_DIRECTORIES(/usr/local/lib)
# # a temporary fix for mac
# SET(CMAKE_C_FLAGS_DEBUG " -L/usr/local/lib -lglib-2.0 -lintl -Wno-unused-command-line-argument")
# endif()

find_library(libCacheSim libCacheSim)
find_path(libCacheSimInclude libCacheSim)
message(STATUS "libCacheSim found? ${libCacheSim} ${libCacheSimInclude}")
include_directories(${libCacheSimInclude})


set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../../cmake/Modules/")
find_package(GLib "2.40" REQUIRED)
include_directories(${GLib_INCLUDE_DIRS})
message(STATUS "glib found? ${GLib_FOUND}, lib = ${GLib_LIBRARY}, header = ${GLib_INCLUDE_DIRS}")

find_package(ZSTD)
# https://stackoverflow.com/questions/61377055/cannot-find-gflags-gflags-h-while-building-library-osx/61379123#61379123
include_directories(${ZSTD_INCLUDE_DIR})
if ("${ZSTD_LIBRARIES}" STREQUAL "")
message(FATAL_ERROR "zstd not found")
endif()


add_executable(cacheSimulator main.c)
target_link_libraries(cacheSimulator libCacheSim m ${GLib_LIBRARY})
target_link_libraries(cacheSimulator libCacheSim m ${GLib_LIBRARY} ${ZSTD_LIBRARIES})
83 changes: 0 additions & 83 deletions example/cacheSimulator/cmake/Modules/FindGLib.cmake

This file was deleted.

17 changes: 13 additions & 4 deletions example/cacheSimulatorConcurrent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
cmake_minimum_required (VERSION 2.8)
cmake_minimum_required (VERSION 3.2)
project (cacheSimulatorMultiSize)
# set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

find_library(libCacheSim libCacheSim)
find_path(libCacheSimInclude libCacheSim)
include_directories(${libCacheSimInclude})
message(STATUS "libCacheSim found? ${libCacheSim}, ${libCacheSimInclude}")


set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../../cmake/Modules/")
find_package(GLib "2.40" REQUIRED)
include_directories(${GLib_INCLUDE_DIRS})
message(STATUS "glib found? ${GLib_FOUND}, lib = ${GLib_LIBRARY}, header = ${GLib_INCLUDE_DIRS}")

find_package(ZSTD)
# https://stackoverflow.com/questions/61377055/cannot-find-gflags-gflags-h-while-building-library-osx/61379123#61379123
include_directories(${ZSTD_INCLUDE_DIR})
if ("${ZSTD_LIBRARIES}" STREQUAL "")
message(FATAL_ERROR "zstd not found")
endif()

add_executable(cacheSimulatorMultiSize main.cpp)
target_link_libraries(cacheSimulatorMultiSize libCacheSim)
target_link_libraries(cacheSimulatorMultiSize libCacheSim m ${GLib_LIBRARY} ${ZSTD_LIBRARIES})

Loading

0 comments on commit 921c112

Please sign in to comment.