#include <stdio.h> #include <stdlib.h> #include <time.h> #include “csim.h” #define…
- User
#include <stdio.h> #include <stdlib.h> #include <time.h> #include “csim.h”
#define NUM_CLIENTS 5 #define DB_SIZE 500 #define DATA_ITEM_SIZE 1024 #define BANDWIDTH 10000 #define CACHE_SIZE 100 #define NUM_HOT_ITEMS 50
double t_query_arr[] = {5, 10, 25, 50, 100}; double t_update_arr[] = {5, 10, 20, 100, 200}; float hot_access_prob = 0.8; float hot_update_prob = 0.33;
typedef struct { int id; double q_gen_time; double u_arr_time; } node;
FACILITY server; TABLE query_delay, cache_hit_ratio; node *nodes; float total_queries = 0; float cache_hits = 0;
void client(); void generate_query(node *n); void query_result(node *n); void handle_csim_error_message(long err);
int main() { long err; create(“simple_pull_based_cache”); nodes = (node *)malloc(NUM_CLIENTS * sizeof(node)); err = facility(“Server”, &server); handle_csim_error_message(err); table_init(“Query Delay”, &query_delay); table_init(“Cache Hit Ratio”, &cache_hit_ratio);
code// Simulating for (size_t q = 0; q < sizeof(t_query_arr) / sizeof(t_query_arr[0]); q++) { for (size_t u = 0; u < sizeof(t_update_arr) / sizeof(t_update_arr[0]); u++) { reset(); total_queries = 0; cache_hits = 0; for (int i = 0; i < NUM_CLIENTS; i++) { nodes[i].id = i; nodes[i].q_gen_time = t_query_arr[q]; nodes[i].u_arr_time = t_update_arr[u]; node_activity(client); } schedule(START, 0.0); schedule(END, 10e4); simulate(); printf(“Cache hit ratio: %.2f\n”, cache_hits / total_queries); printf(“Query delay: %.2f\n”, tbl_mean(query_delay)); printf(“\n”); } } // Clean up table_rm(query_delay); table_rm(cache_hit_ratio); err = facility_rm(server); handle_csim_error_message(err); cleanup(); free(nodes); return 0;}
void client() { node *n = nodes[node_id()]; while (clock < 10e4) { hold(exponential(n->q_gen_time));
code - Assistant