Skip to content

Commit 921c112

Browse files
authored
update example (#53)
1 parent 61c77f7 commit 921c112

File tree

10 files changed

+67
-318
lines changed

10 files changed

+67
-318
lines changed

example/cacheCluster/CMakeLists.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
cmake_minimum_required (VERSION 3.2)
22
project (cacheCluster)
3-
set(CMAKE_BUILD_TYPE Debug)
4-
set(CMAKE_CXX_STANDARD 11)
3+
# set(CMAKE_BUILD_TYPE Debug)
4+
set(CMAKE_CXX_STANDARD 17)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
66

77

8-
# clear an error when using cmake in macOS
9-
# if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
10-
# set(CMAKE_MACOSX_RPATH 1)
11-
# # Fix linking on 10.14+. See https://stackoverflow.com/questions/54068035
12-
# LINK_DIRECTORIES(/usr/local/lib)
13-
# # a temporary fix for mac
14-
# SET(CMAKE_C_FLAGS_DEBUG " -L/usr/local/lib -lglib-2.0 -lintl -Wno-unused-command-line-argument")
15-
# endif()
16-
178
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../../cmake/Modules/")
189
find_package(GLib "2.40" REQUIRED)
1910
include_directories(${GLib_INCLUDE_DIRS})
2011
message(STATUS "glib found? " ${GLib_FOUND} ", GLIB = " ${GLib_LIBRARY} ", header = " ${GLib_INCLUDE_DIRS})
2112

13+
14+
find_package(ZSTD)
15+
# https://stackoverflow.com/questions/61377055/cannot-find-gflags-gflags-h-while-building-library-osx/61379123#61379123
16+
include_directories(${ZSTD_INCLUDE_DIR})
17+
if ("${ZSTD_LIBRARIES}" STREQUAL "")
18+
message(FATAL_ERROR "zstd not found")
19+
endif()
20+
21+
2222
################ this mode compiles the external cache replacement algorithm together with the simulator ############
2323
message(STATUS "project_source dir = " ${PROJECT_SOURCE_DIR})
2424
file(GLOB ALL_CXX_SRC ${PROJECT_SOURCE_DIR}/*.cpp)
2525
file(GLOB ALL_C_SRC ${PROJECT_SOURCE_DIR}/*.c)
2626

2727
add_executable(cacheCluster ${ALL_CXX_SRC} ${ALL_C_SRC})
28-
target_link_libraries(cacheCluster libCacheSim m ${GLib_LIBRARY} pthread dl)
28+
target_link_libraries(cacheCluster libCacheSim m ${GLib_LIBRARY} pthread dl ${ZSTD_LIBRARIES})
2929

example/cacheCluster/main.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
namespace CDNSimulator {
1414

1515
void simulate(int argc, char *argv[]) {
16-
const char *data_path = "../../../data/trace.csv";
16+
const char *data_path = "../../../data/twitter_cluster52.csv";
1717
if (argc > 1) {
1818
data_path = argv[1];
19+
} else {
20+
printf("use default data at ../../../data/twitter_cluster52.csv\n");
1921
}
2022

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

2628
/* setup a csv reader */
2729
reader_init_param_t init_params = default_reader_init_params();
28-
init_params.obj_id_field = 5;
29-
init_params.obj_size_field = 4;
30-
init_params.time_field = 2;
30+
init_params.obj_id_field = 2;
31+
init_params.obj_size_field = 3;
32+
init_params.time_field = 1;
3133
init_params.has_header_set = true;
3234
init_params.has_header = true;
3335
init_params.delimiter = ',';
@@ -36,12 +38,17 @@ void simulate(int argc, char *argv[]) {
3638
reader_t *reader = open_trace(data_path, CSV_TRACE, &init_params);
3739

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

4653
CacheCluster cluster(0);
4754

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

71-
std::cout << n_req << " requests, " << n_miss
72-
<< " misses, miss ratio: " << (double)n_miss / n_req
73-
<< ", byte miss ratio: " << (double)n_miss_byte / n_req_byte
74-
<< std::endl;
78+
std::cout << n_req << " requests, " << n_miss << " misses, miss ratio: " << (double)n_miss / n_req
79+
<< ", byte miss ratio: " << (double)n_miss_byte / n_req_byte << std::endl;
7580

7681
close_trace(reader);
7782
}

example/cacheHierarchy/CMakeLists.txt

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
11
cmake_minimum_required (VERSION 3.2)
22
project (layeredCache)
3-
4-
set(CMAKE_CXX_STANDARD 11)
3+
set(CMAKE_CXX_STANDARD 17)
54
set(CMAKE_CXX_STANDARD_REQUIRED ON)
65

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

98

10-
####
11-
## export C_INCLUDE_PATH=/usr/local/include
12-
## export CPLUS_INCLUDE_PATH=/usr/local/include
13-
14-
# clear an error when using cmake in macOS
15-
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
16-
set(CMAKE_MACOSX_RPATH 1)
17-
# Fix linking on 10.14+. See https://stackoverflow.com/questions/54068035
18-
LINK_DIRECTORIES(/usr/local/lib)
19-
# a temporary fix for mac
20-
SET(CMAKE_C_FLAGS_DEBUG " -L/usr/local/lib -lglib-2.0 -lintl -Wno-unused-command-line-argument")
21-
endif()
22-
23-
24-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
25-
# find libglib2.0-dev
9+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../../cmake/Modules/")
2610
find_package(GLib "2.40" REQUIRED)
2711
include_directories(${GLib_INCLUDE_DIRS})
2812
message(STATUS "glib found? " ${GLib_FOUND} ", GLIB = " ${GLib_LIBRARY} ", header = " ${GLib_INCLUDE_DIRS})
2913

30-
# set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/usr/local/share/cmake/yaml-cpp/")
14+
find_package(ZSTD)
15+
include_directories(${ZSTD_INCLUDE_DIR})
16+
if ("${ZSTD_LIBRARIES}" STREQUAL "")
17+
message(FATAL_ERROR "zstd not found")
18+
endif()
19+
20+
21+
# https://github.com/jbeder/yaml-cpp
22+
# wget https://github.com/jbeder/yaml-cpp/archive/refs/tags/0.8.0.tar.gz
23+
# tar -xzf 0.8.0.tar.gz; mkdir yaml-cpp-0.8.0/_build; cd yaml-cpp-0.8.0/_build;
24+
# cmake -DBUILD_SHARED_LIBS=ON ..;
25+
# make -j; sudo make install
3126
find_package(YAML-CPP REQUIRED)
3227
# set(YAML_CPP_INCLUDE_DIR /usr/local/include/)
3328
# set(YAML_CPP_LIBRARIES /usr/local/lib/)
@@ -38,10 +33,5 @@ message(STATUS ${YAML_CPP_INCLUDE_DIR} ";" ${YAML_CPP_LIBRARIES})
3833
file(GLOB ALL_SRC ${PROJECT_SOURCE_DIR}/*.cpp)
3934
message(STATUS "all sources " ${ALL_SRC})
4035
add_executable(layeredCache ${ALL_SRC})
41-
target_link_libraries(layeredCache yaml-cpp libCacheSim m ${GLib_LIBRARY})
42-
43-
44-
45-
46-
36+
target_link_libraries(layeredCache yaml-cpp libCacheSim dl m ${GLib_LIBRARY} ${ZSTD_LIBRARIES} pthread)
4737

example/cacheHierarchy/cmake/Modules/FindGLib.cmake

Lines changed: 0 additions & 83 deletions
This file was deleted.

example/cacheSimulator/CMakeLists.txt

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,23 @@ project (cacheSimulator)
44

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

7-
8-
# clear an error when using cmake in macOS
9-
# if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
10-
# set(CMAKE_MACOSX_RPATH 1)
11-
# # Fix linking on 10.14+. See https://stackoverflow.com/questions/54068035
12-
# LINK_DIRECTORIES(/usr/local/lib)
13-
# # a temporary fix for mac
14-
# SET(CMAKE_C_FLAGS_DEBUG " -L/usr/local/lib -lglib-2.0 -lintl -Wno-unused-command-line-argument")
15-
# endif()
16-
177
find_library(libCacheSim libCacheSim)
188
find_path(libCacheSimInclude libCacheSim)
199
message(STATUS "libCacheSim found? ${libCacheSim} ${libCacheSimInclude}")
2010
include_directories(${libCacheSimInclude})
2111

22-
23-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
12+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../../cmake/Modules/")
2413
find_package(GLib "2.40" REQUIRED)
2514
include_directories(${GLib_INCLUDE_DIRS})
2615
message(STATUS "glib found? ${GLib_FOUND}, lib = ${GLib_LIBRARY}, header = ${GLib_INCLUDE_DIRS}")
2716

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

2925
add_executable(cacheSimulator main.c)
30-
target_link_libraries(cacheSimulator libCacheSim m ${GLib_LIBRARY})
26+
target_link_libraries(cacheSimulator libCacheSim m ${GLib_LIBRARY} ${ZSTD_LIBRARIES})

example/cacheSimulator/cmake/Modules/FindGLib.cmake

Lines changed: 0 additions & 83 deletions
This file was deleted.
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1-
cmake_minimum_required (VERSION 2.8)
1+
cmake_minimum_required (VERSION 3.2)
22
project (cacheSimulatorMultiSize)
3-
# set(CMAKE_BUILD_TYPE Debug)
3+
set(CMAKE_CXX_STANDARD 17)
4+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
45

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

77
find_library(libCacheSim libCacheSim)
88
find_path(libCacheSimInclude libCacheSim)
99
include_directories(${libCacheSimInclude})
1010
message(STATUS "libCacheSim found? ${libCacheSim}, ${libCacheSimInclude}")
1111

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

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

1725
add_executable(cacheSimulatorMultiSize main.cpp)
18-
target_link_libraries(cacheSimulatorMultiSize libCacheSim)
26+
target_link_libraries(cacheSimulatorMultiSize libCacheSim m ${GLib_LIBRARY} ${ZSTD_LIBRARIES})
27+

0 commit comments

Comments
 (0)