MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / simulate

Function simulate

example/cacheCluster/main.cpp:15–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13namespace CDNSimulator {
14
15void simulate(int argc, char *argv[]) {
16 const char *data_path = "../../../data/twitter_cluster52.csv";
17 if (argc > 1) {
18 data_path = argv[1];
19 } else {
20 printf("use default data at ../../../data/twitter_cluster52.csv\n");
21 }
22
23 if (access(data_path, F_OK) == -1) {
24 printf("Data file %s does not exist.\n", data_path);
25 exit(1);
26 }
27
28 /* setup a csv reader */
29 reader_init_param_t init_params = default_reader_init_params();
30 init_params.obj_id_field = 2;
31 init_params.obj_size_field = 3;
32 init_params.time_field = 1;
33 init_params.has_header_set = true;
34 init_params.has_header = true;
35 init_params.delimiter = ',';
36
37 /* we can also use open_trace with the same parameters */
38 reader_t *reader = open_trace(data_path, CSV_TRACE, &init_params);
39
40 const uint64_t n_server = 10;
41 const uint64_t server_dram_cache_size = 1 * MiB;
42 const uint64_t server_disk_cache_size = 10 * MiB;
43 const std::string algo = "lru";
44 // each cache holds 2 ** 20 objects, this is for performance optimization
45 // you can specify a smaller number to save memory
46 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());
52
53 CacheCluster cluster(0);
54
55 for (int i = 0; i < n_server; i++) {
56 CacheServer server(i);
57 server.add_cache(std::move(Cache(server_dram_cache_size, algo, hashpower)));
58 server.add_cache(std::move(Cache(server_disk_cache_size, algo, hashpower)));
59 cluster.add_server(std::move(server));
60 }
61
62 /* read the trace */
63 request_t *req = new_request();
64
65 uint64_t n_miss = 0, n_miss_byte = 0;
66 uint64_t n_req = 0, n_req_byte = 0;
67
68 while (read_trace(reader, req) == 0) {
69 bool hit = cluster.get(req);
70 if (!hit) {
71 n_miss += 1;
72 n_miss_byte += req->obj_size;

Callers 1

mainFunction · 0.70

Calls 9

open_traceFunction · 0.85
new_requestFunction · 0.85
read_traceFunction · 0.85
close_traceFunction · 0.85
add_cacheMethod · 0.80
add_serverMethod · 0.80
CacheClass · 0.50
getMethod · 0.45

Tested by

no test coverage detected